From 9c8c98af7f3a023958e6aae671d55b7d684bc28a Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Fri, 19 Dec 2014 18:31:43 +0100 Subject: [PATCH] Removed unittesting of removed models since we do not depend on this code anymore --- .../models/account/test_account.py | 268 ------------------ .../models/account/test_communities.py | 11 - .../models/account/test_wallets.py | 71 ----- src/_cutecoin_test/models/test_coin.py | 31 -- src/_cutecoin_test/models/test_community.py | 170 ----------- src/_cutecoin_test/models/test_node.py | 83 ------ src/_cutecoin_test/models/test_person.py | 64 ----- src/_cutecoin_test/models/test_transaction.py | 139 --------- src/_cutecoin_test/models/test_wallet.py | 79 ------ 9 files changed, 916 deletions(-) delete mode 100644 src/_cutecoin_test/models/account/test_account.py delete mode 100644 src/_cutecoin_test/models/account/test_communities.py delete mode 100644 src/_cutecoin_test/models/account/test_wallets.py delete mode 100644 src/_cutecoin_test/models/test_coin.py delete mode 100644 src/_cutecoin_test/models/test_community.py delete mode 100644 src/_cutecoin_test/models/test_node.py delete mode 100644 src/_cutecoin_test/models/test_person.py delete mode 100644 src/_cutecoin_test/models/test_transaction.py delete mode 100644 src/_cutecoin_test/models/test_wallet.py diff --git a/src/_cutecoin_test/models/account/test_account.py b/src/_cutecoin_test/models/account/test_account.py deleted file mode 100644 index 1c11562f..00000000 --- a/src/_cutecoin_test/models/account/test_account.py +++ /dev/null @@ -1,268 +0,0 @@ -import pytest -import ucoin -import gnupg -from mock import Mock -from cutecoin.models.account import Account -from cutecoin.models.account.communities import Communities -from cutecoin.models.community import Community, CommunityNetwork - - -user_keys = { - "0x31A6302161AC8F5938969E85399EB3415C237F93" : { - "keys": [ - { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "key": - { - "email":"mistertest@testmail.com", - "comment":"", - "name":"Mister test", - "fingerprint":"31A6302161AC8F5938969E85399EB3415C237F93", - "raw":"-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----\r\n" - } - } - ] - }, - "0x2E69197FAB029D8669EF85E82457A1587CA0ED9C" : { - "keys": [ - { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "key": - { - "email":"mistertest2@testmail.com", - "comment":"", - "name":"Mister test2", - "fingerprint":"2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "raw":"-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----\r\n" - } - } - ] - } -} - -def patch_transactions_recipient_get(*arg, **kwargs): - return iter([{ - "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "value": { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "transaction": - { - "version": 1, - "currency": "beta_brousouf", - "sender": "31A6302161AC8F5938969E85399EB3415C237F93", - "number": 15, - "previousHash": "BE522363749E62BA1034C7B1358B01C75289DA48", - "recipient": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "type": "TRANSFER", - "coins": [ - { - "id": "31A6302161AC8F5938969E85399EB3415C237F93-10-1-2-F-14", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-2-4-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-3-6-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - } - ], - "comment": "Too much coins ! Making big one." - } - } - }]) - - -def patch_transactions_sent_get(*arg, **kwargs): - return iter([{ - "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "value": { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "transaction": - { - "version": 1, - "currency": "beta_brousouf", - "sender": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "number": 15, - "previousHash": "BE522363749E62BA1034C7B1358B01C75289DA48", - "recipient": "31A6302161AC8F5938969E85399EB3415C237F93", - "type": "TRANSFER", - "coins": [ - { - "id": "31A6302161AC8F5938969E85399EB3415C237F93-10-1-2-F-14", - "transaction_id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-2-4-1-A-1", - "transaction_id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-3-6-1-A-1", - "transaction_id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-1" - } - ], - "comment": "Too much coins ! Making big one." - } - } - }]) - - -def patch_transactions_view_get(*arg, **kwargs): - return { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "transaction": - { - "version": 1, - "currency": "beta_brousouf", - "sender": "31A6302161AC8F5938969E85399EB3415C237F93", - "number": 15, - "previousHash": "BE522363749E62BA1034C7B1358B01C75289DA48", - "recipient": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "type": "TRANSFER", - "coins": [ - { - "id": "31A6302161AC8F5938969E85399EB3415C237F93-10-1-2-F-14", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-2-4-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-3-6-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - } - ], - "comment": "Too much coins ! Making big one." - } - } - -def patch_transactions_issuances_get(*arg, **kwargs): - return iter([{ - "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "value": { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "transaction": - { - "version": 1, - "currency": "beta_brousouf", - "sender": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "number": 1, - "previousHash": "BE522363749E62BA1034C7B1358B01C75289DA48", - "recipient": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "type": "ISSUANCE", - "coins": [ - { - "id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-2-4-1-A-1", - "transaction_id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-1" - },{ - "id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-3-6-1-A-1", - "transaction_id": "2E69197FAB029D8669EF85E82457A1587CA0ED9C-1" - } - ], - "comment": "Too much coins ! Making big one." - } - } - } - ]) - -def mock_gpg(): - def gpg_list_keys(): - return [{ - 'keyid': u'25500A07', - 'fingerprint': '2E69197FAB029D8669EF85E82457A1587CA0ED9C', - 'uids': [u'Mister Test <mister_test@testmail.com>'], - 'expires': u'', - 'length': u'1024', - 'algo': u'17', - 'date': u'1221156445', - 'type': u'pub' - }] - - mock = Mock(spec=gnupg.GPG) - instance = mock.return_value - instance.list_keys = gpg_list_keys - return instance - - -@pytest.fixture -def mock_community(): - def community_request(request, get_args={}): - if type(request) is ucoin.hdc.transactions.Recipient: - return patch_transactions_recipient_get() - elif type(request) is ucoin.hdc.transactions.sender.Last: - return patch_transactions_sent_get() - elif type(request) is ucoin.hdc.coins.List: - return { - "owner": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "coins": [{ - "issuer": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "ids": ["1-5-2-A-1", "2-4-1-A-1"] - }, - { - "issuer": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "ids": ["10-1-2-F-14"] - }] - } - elif type(request) == ucoin.pks.Lookup: - return user_keys[ get_args['search'] ] - else: - assert 0 - - mock_network = Mock(spec=CommunityNetwork, request=community_request) - mock = Mock(spec=Community, network=mock_network, currency="test_currency") - return mock - - -@pytest.fixture -def mock_communities(): - mock = Mock(spec=Communities, communities_list=[]) - return mock - - -class Test_Account: - def test_account_create1(self, mock_communities): - account = Account.create("25500A07", "TestUser", mock_communities) - assert account is not None - - def test_account_create2(self, monkeypatch, mock_communities, mock_community): - monkeypatch.setattr(gnupg, 'GPG', mock_gpg) - mock_communities.communities_list=[mock_community] - account = Account.create("25500A07", "TestUser", mock_communities) - assert account is not None - - def test_account_load(self): - pass - - def test_account_add_contact(self): - pass - - def test_account_fingerprint(self, monkeypatch, mock_communities): - monkeypatch.setattr(gnupg, 'GPG', mock_gpg) - account = Account.create("25500A07", "TestUser", mock_communities) - assert account.fingerprint() == "2E69197FAB029D8669EF85E82457A1587CA0ED9C" - - def test_account_transactions_received(self, monkeypatch, mock_community, mock_communities): - monkeypatch.setattr(gnupg, 'GPG', mock_gpg) - mock_communities.communities_list=[mock_community] - account = Account.create("25500A07", "TestUser", mock_communities) - assert len(account.transactions_received()) == 1 - assert sum( trx.value() for trx in account.transactions_received()) == 200 - - def test_account_transactions_sent(self, monkeypatch, mock_community, mock_communities): - monkeypatch.setattr(gnupg, 'GPG', mock_gpg) - mock_communities.communities_list=[mock_community] - account = Account.create("25500A07", "TestUser", mock_communities) - assert len(account.transactions_sent()) == 1 - assert sum( trx.value() for trx in account.transactions_sent()) == 200 - - def test_account_issued_last_dividend(self): - pass - - def test_account_issue_dividend(self): - pass - - def test_account_transfer_coins(self): - pass - - def test_account_push_tht(self): - pass - - def test_account_pull_tht(self): - pass - diff --git a/src/_cutecoin_test/models/account/test_communities.py b/src/_cutecoin_test/models/account/test_communities.py deleted file mode 100644 index d446a8ed..00000000 --- a/src/_cutecoin_test/models/account/test_communities.py +++ /dev/null @@ -1,11 +0,0 @@ -import pytest -import ucoin -from cutecoin.models.account.communities import Communities - - -#TODO: Test communities -class Test_Communities: - def test_communities_jsonify(self): - pass - - diff --git a/src/_cutecoin_test/models/account/test_wallets.py b/src/_cutecoin_test/models/account/test_wallets.py deleted file mode 100644 index af74ff05..00000000 --- a/src/_cutecoin_test/models/account/test_wallets.py +++ /dev/null @@ -1,71 +0,0 @@ -import pytest -import ucoin -from mock import Mock, MagicMock -from cutecoin.models.wallet import Wallet -from cutecoin.models.account.wallets import Wallets -from cutecoin.models.community import Community, CommunityNetwork - - -def mock_community(): - def community_request(request): - if type(request) is ucoin.hdc.coins.List: - return { - "owner": "86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8", - "coins": [{ - "issuer": "86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8", - "ids": ["1-5-2-A-1", "2-4-1-A-1"] - }, - { - "issuer": "31A6302161AC8F5938969E85399EB3415C237F93", - "ids": ["10-1-2-F-14"] - }] - } - else: - assert 0 - - mock_network = Mock(spec=CommunityNetwork, request=community_request) - community = MagicMock(spec=Community, network=mock_network) - - return community - - -def mock_wallet(): - def wallet_eq(mock1, mock2): - return mock1.community == mock2.community - mock_wallet = MagicMock(spec=Wallet, __eq__=wallet_eq) - - -class Test_Wallets: - def test_wallets_add_wallet(self): - wallets = Wallets() - wallet = wallets.add_wallet(mock_community()) - assert wallet is not None - - def test_wallets_get_wallet(self): - mock1 = mock_community() - mock2 = mock_community() - mock3 = mock_community() - mock_wallet1 = Mock(spec=Wallet, community=mock1) - mock_wallet2 = Mock(spec=Wallet, community=mock2) - mock_wallet3 = Mock(spec=Wallet, community=mock3) - wallets = Wallets() - wallets._wallets_list.append(mock_wallet1) - wallets._wallets_list.append(mock_wallet2) - - assert wallets.get_wallet(mock_wallet1) is not None - assert wallets.get_wallet(mock_wallet2) is not None - assert wallets.get_wallet(mock_wallet3) is None - - def test_wallets_remove_all_wallets_of(self): - mock1 = mock_community() - mock2 = mock_community() - mock_wallet1 = Mock(spec=Wallet, community=mock1) - mock_wallet2 = Mock(spec=Wallet, community=mock2) - wallets = Wallets() - wallets._wallets_list.append(mock_wallet1) - wallets._wallets_list.append(mock_wallet2) - - wallets.remove_all_wallets_of(mock1) - assert wallets.get_wallet(mock_wallet1) is None - assert wallets.get_wallet(mock_wallet2) is not None - diff --git a/src/_cutecoin_test/models/test_coin.py b/src/_cutecoin_test/models/test_coin.py deleted file mode 100644 index eef1acd4..00000000 --- a/src/_cutecoin_test/models/test_coin.py +++ /dev/null @@ -1,31 +0,0 @@ -import pytest -import re -from cutecoin.models.coin import Coin - - -issuer = "2E69197FAB029D8669EF85E82457A1587CA0ED9C" -number = 0 -base = 3 -power = 2 -origin = "A-2" - - -@pytest.fixture -def coin_id_regex(): - return re.compile("^([A-Z\d]{40})-(\d+)-(\d)-(\d+)-((A|F|D)-\d+)$") - - -class Test_Coin: - def test_coin_init(self, coin_id_regex): - coin = Coin(issuer, number, base, power, origin) - assert coin_id_regex.match(coin.get_id()) is not None - - def test_coin_from_id(self, coin_id_regex): - coin_id = issuer + "-" + str(number) + "-" + str(base) + "-" + str(power) + "-" + origin - coin = Coin.from_id(coin_id) - assert coin is not None - assert coin_id_regex.match(coin.get_id()) is not None - - def test_coin_value(self): - coin = Coin(issuer, number, base, power, origin) - assert coin.value() == 300 diff --git a/src/_cutecoin_test/models/test_community.py b/src/_cutecoin_test/models/test_community.py deleted file mode 100644 index bacc9808..00000000 --- a/src/_cutecoin_test/models/test_community.py +++ /dev/null @@ -1,170 +0,0 @@ -import pytest -from mock import Mock -import ucoin -from cutecoin.models.community import Community -from cutecoin.models.community import Node -from cutecoin.models.account.wallets import Wallets -from cutecoin.models.account import Account -from cutecoin.models.node import Node - - - -amendment_hash = "3682F828EFB1A1AFF45ACC6DDBB2BAD100DCD605" - -def patch_amendment_Promoted_get(*args, **kwargs): - return { - "version": "1", - "currency": "beta_brousouf", - "number": "2", - "previousHash": "0F45DFDA214005250D4D2CBE4C7B91E60227B0E5", - "dividend": "100", - "coinMinimalPower": "0", - "votersRoot": "DC7A9229DFDABFB9769789B7BFAE08048BCB856F", - "votersCount": "2", - "votersChanges": [ - "-C73882B64B7E72237A2F460CE9CAB76D19A8651E" - ], - "membersRoot": "F92B6F81C85200250EE51783F5F9F6ACA57A9AFF", - "membersCount": "4", - "membersChanges": [ - "+31A6302161AC8F5938969E85399EB3415C237F93" - ], - "raw": """Version: 1 -Currency: beta_brousouf -Number: 2 -Dividend: 100 -CoinMinimalPower: 0 -PreviousHash: 0F45DFDA214005250D4D2CBE4C7B91E60227B0E5 -MembersRoot: F92B6F81C85200250EE51783F5F9F6ACA57A9AFF -MembersCount: 4 -MembersChanges: -+31A6302161AC8F5938969E85399EB3415C237F93 -VotersRoot: DC7A9229DFDABFB9769789B7BFAE08048BCB856F -VotersCount: 2 -VotersChanges: --C73882B64B7E72237A2F460CE9CAB76D19A8651E -""" - } - - -def patch_amendments_members_get(*args, **kwargs): - return iter([{ - "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "value": "2E69197FAB029D8669EF85E82457A1587CA0ED9C" - }, - { - "hash": "3F870197FAB029D8669EF85E82457A1587CA0ED9C", - "value": "3F870197FAB029D8669EF85E82457A1587CA0ED9C" - }, - { - "hash": "3F69197FAB029D8669EF85E82457A1587CA0ED9C", - "value": "3F69197FAB029D8669EF85E82457A1587CA0ED9C" - }]) - - -def patch_amendments_voters_get(*args, **kwargs): - return iter([{ - "hash": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "value": "2E69197FAB029D8669EF85E82457A1587CA0ED9C" - }, - { - "hash": "3F870197FAB029D8669EF85E82457A1587CA0ED9C", - "value": "3F870197FAB029D8669EF85E82457A1587CA0ED9C" - }]) - - -@pytest.fixture -def mock_node(): - def node_use(request): - return request - - mock = Mock(spec=Node, trust=True, hoster=True, - server="192.168.100.10", port=3800) - mock.get_text.return_value = "Mock node" - mock.use = node_use - return mock - - -class Test_Community(): - def test_community_create(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - community = Community.create(mock_node) - assert community is not None - - def test_community_dividend(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - community = Community.create(mock_node) - assert community.dividend() == 100 - - def test_community_coin_minimal_power(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - community = Community.create(mock_node) - assert community.coin_minimal_power() == 0 - - def test_community_amendment_id(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - community = Community.create(mock_node) - assert community.amendment_id() == "2-"+amendment_hash.upper() - - def test_community_amendment_number(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - community = Community.create(mock_node) - assert community.amendment_number() == 2 - - def test_community_person_quality(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - monkeypatch.setattr(ucoin.registry.community.Members, - '__get__', patch_amendments_members_get) - monkeypatch.setattr(ucoin.registry.community.Voters, - '__get__', patch_amendments_voters_get) - community = Community.create(mock_node) - assert community.person_quality("2E69197FAB029D8669EF85E82457A1587CA0ED9C") == "voter" - assert community.person_quality("3F69197FAB029D8669EF85E82457A1587CA0ED9C") == "member" - assert community.person_quality("3F870197FAB029D8669EF85E82457A1587CA0ED9C") == "voter" - assert community.person_quality("3F871197FAB029D8669EF85E82457A1587CA0ED9C") == "nothing" - - def test_community_members_fingerprint(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - monkeypatch.setattr(ucoin.registry.community.Members, - '__get__', patch_amendments_members_get) - monkeypatch.setattr(ucoin.registry.community.Voters, - '__get__', patch_amendments_voters_get) - community = Community.create(mock_node) - - assert "2E69197FAB029D8669EF85E82457A1587CA0ED9C" in community.members_fingerprints() - assert "3F69197FAB029D8669EF85E82457A1587CA0ED9C" in community.members_fingerprints() - assert "3F870197FAB029D8669EF85E82457A1587CA0ED9C" in community.members_fingerprints() - assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.members_fingerprints() - - def test_community_voters_fingerprint(self, monkeypatch, mock_node): - monkeypatch.setattr(ucoin.registry.community.Members, - '__get__', patch_amendment_Promoted_get) - monkeypatch.setattr(ucoin.registry.community.Members, - '__get__', patch_amendments_members_get) - monkeypatch.setattr(ucoin.registry.community.Voters, - '__get__', patch_amendments_voters_get) - community = Community.create(mock_node) - - assert "2E69197FAB029D8669EF85E82457A1587CA0ED9C" in community.voters_fingerprints() - assert "3F870197FAB029D8669EF85E82457A1587CA0ED9C" in community.voters_fingerprints() - assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints() - - def test_community_jsonify(self, monkeypatch): - monkeypatch.setattr(ucoin.hdc.amendments.Promoted, - '__get__', patch_amendment_Promoted_get) - main_node = Node.create(trust=True, hoster=True, - server="192.168.100.10", port=3800) - community = Community.create(main_node) - wallets = Wallets() - json = community.jsonify(wallets) - account = Mock(spec=Account) - community2 = Community.load(json, account) - - assert community2.network.nodes[0].server == community.network.nodes[0].server diff --git a/src/_cutecoin_test/models/test_node.py b/src/_cutecoin_test/models/test_node.py deleted file mode 100644 index 2fc097ae..00000000 --- a/src/_cutecoin_test/models/test_node.py +++ /dev/null @@ -1,83 +0,0 @@ -import pytest -import ucoinpy as ucoin -from mock import Mock -from cutecoin.models.node import Node - - -def patch_peers_get(*args, **kwargs): - return iter([{ - "version": "1", - "currency": "beta_brousouf", - "fingerprint": "A70B8E8E16F91909B6A06DFB7EEF1651D9CCF468", - "dns": "DNS_VALUE", - "ipv4": "192.168.100.10", - "ipv6": "", - "port": "3800", - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----" - }, - { - "version": "1", - "currency": "beta_brousouf", - "fingerprint": "A70B8E8E16F91909B6A06DFB7EEF1651D9CCF469", - "dns": "DNS_VALUE", - "ipv4": "192.168.100.11", - "ipv6": "", - "port": "3801", - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----" - }]) - - -def patch_peer_get(*args, **kwargs): - return { - "version": "1", - "currency": "beta_brousouf", - "fingerprint": "A70B8E8E16F91909B6A06DFB7EEF1651D9CCF468", - "dns": "DNS_VALUE", - "ipv4": "192.168.100.10", - "ipv6": "", - "port": "3800", - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----" - } - -def patch_downstream_get(*args, **kwargs): - return { - "peers": [ - {"key": "SOME_KEY_FINGERPRINT", "dns": "name.example1.com", "ipv4": "11.11.11.11", "ipv6": "1A01:E35:2421:4BE0:CDBC:C04E:A7AB:ECF1", "port": 8881}, - {"key": "SOME_KEY_FINGERPRINT", "dns": "name.example2.com", "ipv4": "11.11.11.12", "ipv6": "1A01:E35:2421:4BE0:CDBC:C04E:A7AB:ECF2", "port": 8882} - ] - } - - -class Test_Node.create(): - def test_peers(self, monkeypatch): - - monkeypatch.setattr(ucoin.ucg.peering.Peers, - '__get__', patch_peers_get) - node = Node.create("192.168.100.12", 3800) - assert (peer for peer in node.peers() if peer["ipv4"] == "192.168.100.10") - assert (peer for peer in node.peers() if peer["ipv4"] == "192.168.100.11") - - def test_peering(self, monkeypatch): - monkeypatch.setattr(ucoin.ucg.peering.Peer, '__get__', patch_peer_get) - - node = Node.create("192.168.100.12", 3800) - peering = node.peering() - assert peering["ipv4"] == "192.168.100.10" - assert peering["port"] == str(3800) - - def test_eq(self, monkeypatch): - node1 = Node.create("192.168.100.12", 3800) - node2 = Node.create("192.168.100.13", 3800) - node3 = Node.create("192.168.100.12", 3801) - node4 = Node.create("192.168.100.12", 3800) - - assert node1 != node2 - assert node1 != node3 - assert node1 == node4 - - def test_downstream(self, monkeypatch): - monkeypatch.setattr(ucoin.ucg.peering.peers.DownStream, '__get__', patch_downstream_get) - node = Node.create("192.168.100.12", 3800) - downstream = node.downstream_peers() - assert downstream[0].server == "11.11.11.11" and downstream[0].port == 8881 - assert downstream[1].server == "11.11.11.12" and downstream[1].port == 8882 diff --git a/src/_cutecoin_test/models/test_person.py b/src/_cutecoin_test/models/test_person.py deleted file mode 100644 index 8a866430..00000000 --- a/src/_cutecoin_test/models/test_person.py +++ /dev/null @@ -1,64 +0,0 @@ -import pytest -import ucoinpy as ucoin -from mock import Mock, MagicMock -from cutecoin.models.person import Person -from cutecoin.models.community import Community, CommunityNetwork - - -user_keys = { - "0x31A6302161AC8F5938969E85399EB3415C237F93" : { - "keys": [ - { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "key": - { - "email":"mistertest@testmail.com", - "comment":"", - "name":"Mister test", - "fingerprint":"31A6302161AC8F5938969E85399EB3415C237F93", - "raw":"-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----\r\n" - } - } - ] - }, - "0x2E69197FAB029D8669EF85E82457A1587CA0ED9C" : { - "keys": [ - { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "key": - { - "email":"mistertest2@testmail.com", - "comment":"", - "name":"Mister test2", - "fingerprint":"2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "raw":"-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----\r\n" - } - } - ] - } -} - -@pytest.fixture -def mock_community(): - def community_request(request, get_args={}): - return user_keys[ get_args['search'] ] - mock_network = Mock(spec=CommunityNetwork, request=community_request) - community = MagicMock(spec=Community, network=mock_network) - - return community - -#TODO: Lookup for person after community was tested -class Test_Person(): - def test_person_lookup(self, monkeypatch, mock_community): - person = Person.lookup("2E69197FAB029D8669EF85E82457A1587CA0ED9C", mock_community) - assert person.name == "Mister test2" - assert person.fingerprint == "2E69197FAB029D8669EF85E82457A1587CA0ED9C" - assert person.email == "mistertest2@testmail.com" - - def test_person_jsonify(self, monkeypatch, mock_community): - person = Person.lookup("2E69197FAB029D8669EF85E82457A1587CA0ED9C", mock_community) - json = person.jsonify() - person2 = Person.from_json(json) - assert person2.name == person.name - assert person2.fingerprint == person.fingerprint - assert person2.email == person.email diff --git a/src/_cutecoin_test/models/test_transaction.py b/src/_cutecoin_test/models/test_transaction.py deleted file mode 100644 index bdb83aee..00000000 --- a/src/_cutecoin_test/models/test_transaction.py +++ /dev/null @@ -1,139 +0,0 @@ -import pytest -import re -import ucoinpy as ucoin -from mock import Mock, MagicMock -from cutecoin.models.transaction import Transaction, Transfer, Issuance -from cutecoin.models.transaction import factory -from cutecoin.models.community import Community, CommunityNetwork - - - -user_keys = { - "0x31A6302161AC8F5938969E85399EB3415C237F93" : { - "keys": [ - { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "key": - { - "email":"mistertest@testmail.com", - "comment":"", - "name":"Mister test", - "fingerprint":"31A6302161AC8F5938969E85399EB3415C237F93", - "raw":"-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----\r\n" - } - } - ] - }, - "0x2E69197FAB029D8669EF85E82457A1587CA0ED9C" : { - "keys": [ - { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "key": - { - "email":"mistertest2@testmail.com", - "comment":"", - "name":"Mister test2", - "fingerprint":"2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "raw":"-----BEGIN PGP PUBLIC KEY BLOCK----- ... -----END PGP PUBLIC KEY BLOCK-----\r\n" - } - } - ] - } -} - -def community_request_issuance(request, get_args={}): - if type(request) == ucoin.hdc.transactions.View: - return { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "raw": "Version: 1\r\n...\r\n", - "transaction": - { - "version": 1, - "currency": "beta_brousouf", - "sender": "31A6302161AC8F5938969E85399EB3415C237F93", - "number": 1, - "previousHash": "BE522363749E62BA1034C7B1358B01C75289DA48", - "recipient": "31A6302161AC8F5938969E85399EB3415C237F93", - "type": "ISSUANCE", - "coins": [ - { - "id": "31A6302161AC8F5938969E85399EB3415C237F93-2-4-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-3-6-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - } - ], - "comment": "Too much coins ! Making big one." - } - } - elif type(request) == ucoin.pks.Lookup: - return user_keys[ get_args['search'] ] - else: - assert 0 - - -def community_request_transfer(request, get_args={}): - if type(request) == ucoin.hdc.transactions.View: - return { - "signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----", - "raw": "Version: 1\r\n...\r\n", - "transaction": - { - "version": 1, - "currency": "beta_brousouf", - "sender": "31A6302161AC8F5938969E85399EB3415C237F93", - "number": 15, - "previousHash": "BE522363749E62BA1034C7B1358B01C75289DA48", - "recipient": "2E69197FAB029D8669EF85E82457A1587CA0ED9C", - "type": "TRANSFER", - "coins": [ - { - "id": "31A6302161AC8F5938969E85399EB3415C237F93-10-1-2-F-14", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-2-4-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - },{ - "id": "31A6302161AC8F5938969E85399EB3415C237F93-3-6-1-A-1", - "transaction_id": "31A6302161AC8F5938969E85399EB3415C237F93-1" - } - ], - "comment": "Too much coins ! Making big one." - } - } - elif type(request) == ucoin.pks.Lookup: - return user_keys[ get_args['search'] ] - else: - assert 0 - - -def mock_community(community_request): - mock_network = Mock(spec=CommunityNetwork, request=community_request) - community = MagicMock(spec=Community, network=mock_network) - - return community - - -class Test_Transaction: - def test_create_transaction_issuance(self): - community = mock_community( community_request_issuance ) - trx = factory.create_transaction("31A6302161AC8F5938969E85399EB3415C237F93", 1, community) - assert trx is not None - assert type(trx) is Issuance - - def test_create_transaction_transfer(self): - community = mock_community( community_request_transfer ) - trx = factory.create_transaction("31A6302161AC8F5938969E85399EB3415C237F93", 15, community) - assert trx is not None - assert type(trx) is Transfer - - def test_transaction_value(self): - community = mock_community( community_request_issuance ) - trx = factory.create_transaction("31A6302161AC8F5938969E85399EB3415C237F93", 1, community) - assert trx.value() == 100 - - def test_transaction_currency(self): - community = mock_community( community_request_issuance ) - trx = factory.create_transaction("31A6302161AC8F5938969E85399EB3415C237F93", 1, community) - assert trx.currency() == "beta_brousouf" diff --git a/src/_cutecoin_test/models/test_wallet.py b/src/_cutecoin_test/models/test_wallet.py deleted file mode 100644 index 7fd7f5ac..00000000 --- a/src/_cutecoin_test/models/test_wallet.py +++ /dev/null @@ -1,79 +0,0 @@ -import pytest -import ucoin -from mock import Mock, MagicMock, patch -from cutecoin.models.wallet import Wallet -from cutecoin.models.community import Community, CommunityNetwork - - -def mock_community(): - def community_request(request): - if type(request) is ucoin.hdc.coins.List: - return { - "owner": "86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8", - "coins": [{ - "issuer": "86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8", - "ids": ["1-5-2-A-1", "2-4-1-A-1"] - }, - { - "issuer": "31A6302161AC8F5938969E85399EB3415C237F93", - "ids": ["10-1-2-F-14"] - }] - } - else: - assert 0 - - def community_eq(mock1, mock2): - return mock1.amendment_id() == mock2.amendment_id() - - mock_network = Mock(spec=CommunityNetwork, request=community_request) - community = MagicMock(spec=Community, network=mock_network, __eq__=community_eq) - - return community - - -class Test_Wallet: - def test_wallet_create(self,): - wallet = Wallet([], mock_community()) - assert wallet is not None - - #TODO: Test json - def test_wallet_load(self): - pass - - def test_wallet_value(self): - wallet = Wallet([], mock_community()) - assert wallet.value() == 0 - wallet.refresh_coins("86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8") - assert wallet.value() == 640 - pass - - def test_wallet_get_text(self): - pass - - def test_eq(self): - mock1 = mock_community() - mock1.amendment_id.return_value = "2-AMENDMENTTEST" - mock2 = mock_community() - mock2.amendment_id.return_value = "2-AMENDMENTTEST" - wallet1 = Wallet([], mock1) - wallet2 = Wallet([], mock2) - - assert wallet1 == wallet2 - - def test_not_eq(self): - mock1 = mock_community() - mock1.amendment_id.return_value = "2-AMENDMENTTEST" - mock2 = mock_community() - mock2.amendment_id.return_value = "1-AMENDMENTTEST" - wallet1 = Wallet([], mock1) - wallet2 = Wallet([], mock2) - - assert wallet1 != wallet2 - - def test_wallet_jsonify(self, monkeypatch): - wallet = Wallet([], mock_community()) - wallet.refresh_coins("86F7E437FAA5A7FCE15D1DDCB9EAEAEA377667B8") - json = wallet.jsonify() - wallet2 = Wallet.load(json, mock_community()) - same_coins = [coin1 for coin1, coin2 in zip(wallet.coins, wallet2.coins) if coin1 == coin2] - assert len(same_coins) == len(wallet.coins) and len(same_coins) == len(wallet2.coins) \ No newline at end of file -- GitLab