Skip to content
Snippets Groups Projects
Commit 48257445 authored by unknown's avatar unknown
Browse files

74% coverage of models

parent a673ac88
No related branches found
No related tags found
No related merge requests found
[run]
omit =
src/cutecoin/gen_resources/*
src/cutecoin/gui/*
src/cutecoin/core/*
src/cutecoin/models/*Model*
source = src/cutecoin
[html]
directory = doc/coverage
...@@ -71,5 +71,3 @@ class Test_Wallets: ...@@ -71,5 +71,3 @@ class Test_Wallets:
assert wallets.get_wallet(mock_wallet1) is None assert wallets.get_wallet(mock_wallet1) is None
assert wallets.get_wallet(mock_wallet2) is not None assert wallets.get_wallet(mock_wallet2) is not None
def test_wallets_jsonify(self):
pass
...@@ -3,6 +3,9 @@ from mock import Mock ...@@ -3,6 +3,9 @@ from mock import Mock
import ucoinpy as ucoin import ucoinpy as ucoin
from cutecoin.models.community import Community from cutecoin.models.community import Community
from cutecoin.models.community import Node 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(): ...@@ -154,8 +157,15 @@ class Test_Community():
assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints() assert "3F871197FAB029D8669EF85E82457A1587CA0ED9C" not in community.voters_fingerprints()
#TODO: Test community json #TODO: Test community json
def test_community_to_json(self): def test_community_jsonify(self, monkeypatch):
pass monkeypatch.setattr(ucoin.hdc.amendments.Current,
'__get__', patch_amendment_current_get)
def test_community_from_json(self): main_node = Node(trust=True, hoster=True,
pass 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
...@@ -38,6 +38,14 @@ def patch_peer_get(*args, **kwargs): ...@@ -38,6 +38,14 @@ def patch_peer_get(*args, **kwargs):
"port": "3800", "port": "3800",
"signature": "-----BEGIN PGP SIGNATURE----- ... -----END PGP SIGNATURE-----" "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(): class Test_Node():
...@@ -57,6 +65,20 @@ class Test_Node(): ...@@ -57,6 +65,20 @@ class Test_Node():
assert peering["ipv4"] == "192.168.100.10" assert peering["ipv4"] == "192.168.100.10"
assert peering["port"] == str(3800) assert peering["port"] == str(3800)
#TODO: Test node json def test_eq(self, monkeypatch):
def test_node_jsonify(self): node1 = Node("192.168.100.12", 3800)
pass 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
...@@ -55,8 +55,10 @@ class Test_Person(): ...@@ -55,8 +55,10 @@ class Test_Person():
assert person.fingerprint == "2E69197FAB029D8669EF85E82457A1587CA0ED9C" assert person.fingerprint == "2E69197FAB029D8669EF85E82457A1587CA0ED9C"
assert person.email == "mistertest2@testmail.com" assert person.email == "mistertest2@testmail.com"
def test_person_jsonify(self): def test_person_jsonify(self, monkeypatch, mock_community):
pass person = Person.lookup("2E69197FAB029D8669EF85E82457A1587CA0ED9C", mock_community)
json = person.jsonify()
def test_person_from_json(self): person2 = Person.from_json(json)
pass assert person2.name == person.name
assert person2.fingerprint == person.fingerprint
assert person2.email == person.email
...@@ -70,6 +70,10 @@ class Test_Wallet: ...@@ -70,6 +70,10 @@ class Test_Wallet:
assert wallet1 != wallet2 assert wallet1 != wallet2
def test_wallet_jsonify(self, monkeypatch):
def test_wallet_jsonify(self): wallet = Wallet([], mock_community())
pass 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment