diff --git a/coverage.rc b/coverage.rc new file mode 100644 index 0000000000000000000000000000000000000000..934a392069a8b008fa467e07320571612c65eb5e --- /dev/null +++ b/coverage.rc @@ -0,0 +1,10 @@ +[run] +omit = + src/cutecoin/gen_resources/* + src/cutecoin/gui/* + src/cutecoin/core/* + src/cutecoin/models/*Model* +source = src/cutecoin + +[html] +directory = doc/coverage diff --git a/src/_cutecoin_test/models/account/test_wallets.py b/src/_cutecoin_test/models/account/test_wallets.py index a3435296e15889e369c204d7900dc6825ddd3cc1..7b2f39c8f74a41034b2bf12bf9ea5183e493be49 100644 --- a/src/_cutecoin_test/models/account/test_wallets.py +++ b/src/_cutecoin_test/models/account/test_wallets.py @@ -71,5 +71,3 @@ class Test_Wallets: assert wallets.get_wallet(mock_wallet1) is None assert wallets.get_wallet(mock_wallet2) is not None - def test_wallets_jsonify(self): - pass diff --git a/src/_cutecoin_test/models/test_community.py b/src/_cutecoin_test/models/test_community.py index d5d6a589aa358bafbf5b9a121e2a102504c04775..704c6e2be8d4ec0f80f2335004fc1d5047d966ff 100644 --- a/src/_cutecoin_test/models/test_community.py +++ b/src/_cutecoin_test/models/test_community.py @@ -3,6 +3,9 @@ from mock import Mock import ucoinpy as 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 @@ -154,8 +157,15 @@ class Test_Community(): assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints() #TODO: Test community json - def test_community_to_json(self): - pass - - def test_community_from_json(self): - pass + def test_community_jsonify(self, monkeypatch): + monkeypatch.setattr(ucoin.hdc.amendments.Current, + '__get__', patch_amendment_current_get) + main_node = Node(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 index 0e6538a08f5ce3066f4d001ad812eba1555d3d9c..eeac9ad1a280e4a9d551e46bd4d6eb7e3003b9aa 100644 --- a/src/_cutecoin_test/models/test_node.py +++ b/src/_cutecoin_test/models/test_node.py @@ -38,6 +38,14 @@ def patch_peer_get(*args, **kwargs): "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(): @@ -57,6 +65,20 @@ class Test_Node(): assert peering["ipv4"] == "192.168.100.10" assert peering["port"] == str(3800) - #TODO: Test node json - def test_node_jsonify(self): - pass + def test_eq(self, monkeypatch): + node1 = Node("192.168.100.12", 3800) + node2 = Node("192.168.100.13", 3800) + node3 = Node("192.168.100.12", 3801) + node4 = Node("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("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 + \ No newline at end of file diff --git a/src/_cutecoin_test/models/test_person.py b/src/_cutecoin_test/models/test_person.py index f329ef38fe024dd6c6903ac5096b12ed7e1e3843..8a866430973fab38cbaf1e31cf458a9221f4d63a 100644 --- a/src/_cutecoin_test/models/test_person.py +++ b/src/_cutecoin_test/models/test_person.py @@ -55,8 +55,10 @@ class Test_Person(): assert person.fingerprint == "2E69197FAB029D8669EF85E82457A1587CA0ED9C" assert person.email == "mistertest2@testmail.com" - def test_person_jsonify(self): - pass - - def test_person_from_json(self): - pass + 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_wallet.py b/src/_cutecoin_test/models/test_wallet.py index 2c4e45737f0329a7fdb3b38b9dd295dc6543cfe0..0e239c78b049da6b4a126a5fea4166f6b1bfed43 100644 --- a/src/_cutecoin_test/models/test_wallet.py +++ b/src/_cutecoin_test/models/test_wallet.py @@ -70,6 +70,10 @@ class Test_Wallet: assert wallet1 != wallet2 - - def test_wallet_jsonify(self): - pass + 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