Here are the examples of the python api asynctest.mock.Mock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
18 Examples
3
Example 1
Project: sakia Source File: test_base_graph.py
def setUp(self):
self.setUpQuamash()
QLocale.setDefault(QLocale("en_GB"))
self.account_identity = Mock(specs='core.registry.Identity')
self.account_identity.pubkey = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
self.account_identity.uid = "account_identity"
self.account_identity.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.first_identity = Mock(specs='core.registry.Identity')
self.first_identity.pubkey = "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ"
self.first_identity.uid = "first_identity"
self.first_identity.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.second_identity = Mock(specs='core.registry.Identity')
self.second_identity.pubkey = "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn"
self.second_identity.uid = "second_uid"
self.second_identity.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=False)
3
Example 2
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Community')
@patch('time.time', Mock(return_value=50000))
def test_arc_status(self, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
app = Mock()
base_graph = BaseGraph(app, community)
async def exec_test():
self.assertEquals((await base_graph.arc_status(48000)), EdgeStatus.WEAK)
self.assertEquals((await base_graph.arc_status(49500)), EdgeStatus.STRONG)
self.assertEquals((await base_graph.arc_status(49200)), EdgeStatus.WEAK)
self.lp.run_until_complete(exec_test())
3
Example 3
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Application')
@patch('sakia.core.Community')
def test_confirmation_text_expert_enabled(self, app, community):
community.network.confirmations = Mock(return_value=2)
app.preferences = {'expert_mode': True}
base_graph = BaseGraph(app, community)
self.assertEquals(base_graph.confirmation_text(200), "2/6")
3
Example 4
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Application')
@patch('sakia.core.Community')
def test_confirmation_text_expert_disabled(self, app, community):
community.network.confirmations = Mock(return_value=2)
app.preferences = {'expert_mode': False}
base_graph = BaseGraph(app, community)
self.assertEquals(base_graph.confirmation_text(200), "33 %")
3
Example 5
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_add_identity(self, app, community):
app.preferences = {'expert_mode': True}
base_graph = BaseGraph(app, community)
base_graph.add_identity(self.account_identity, NodeStatus.HIGHLIGHTED)
self.assertEqual(len(base_graph.nx_graph.nodes()), 1)
self.assertEqual(len(base_graph.nx_graph.edges()), 0)
nodes = base_graph.nx_graph.nodes(data=True)
account_node = [n for n in nodes if n[0] == self.account_identity.pubkey][0]
self.assertEqual(account_node[1]['status'], NodeStatus.HIGHLIGHTED)
self.assertEqual(account_node[1]['text'], self.account_identity.uid)
self.assertEqual(account_node[1]['tooltip'], self.account_identity.pubkey)
3
Example 6
Project: sakia Source File: test_explorer_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_explore_full_from_center(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
community.nb_members = CoroutineMock(return_value = 3)
app.preferences = {'expert_mode': True}
explorer_graph = ExplorerGraph(app, community)
async def exec_test():
await explorer_graph._explore(self.idB, 5)
self.assertEqual(len(explorer_graph.nx_graph.nodes()), 5)
self.assertEqual(len(explorer_graph.nx_graph.edges()), 4)
self.lp.run_until_complete(exec_test())
3
Example 7
Project: sakia Source File: test_explorer_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_explore_full_from_extremity(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
community.nb_members = CoroutineMock(return_value = 3)
app.preferences = {'expert_mode': True}
explorer_graph = ExplorerGraph(app, community)
async def exec_test():
await explorer_graph._explore(self.idA, 5)
self.assertEqual(len(explorer_graph.nx_graph.nodes()), 5)
self.assertEqual(len(explorer_graph.nx_graph.edges()), 4)
self.lp.run_until_complete(exec_test())
3
Example 8
Project: sakia Source File: test_explorer_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_explore_partial(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
community.nb_members = CoroutineMock(return_value = 3)
app.preferences = {'expert_mode': True}
explorer_graph = ExplorerGraph(app, community)
async def exec_test():
await explorer_graph._explore(self.idB, 1)
self.assertEqual(len(explorer_graph.nx_graph.nodes()), 3)
self.assertEqual(len(explorer_graph.nx_graph.edges()), 2)
self.lp.run_until_complete(exec_test())
3
Example 9
Project: sakia Source File: test_wot_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_explore_to_find_member(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
app.preferences = {'expert_mode': True}
wot_graph = WoTGraph(app, community)
async def exec_test():
result = await wot_graph.explore_to_find_member(self.account_identity, self.idC)
self.assertTrue(result)
self.assertEqual(len(wot_graph.nx_graph.nodes()), 3)
self.assertEqual(len(wot_graph.nx_graph.edges()), 2)
self.lp.run_until_complete(exec_test())
3
Example 10
Project: sakia Source File: test_wot_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_initialize(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
app.preferences = {'expert_mode': True}
wot_graph = WoTGraph(app, community)
async def exec_test():
await wot_graph.initialize(self.account_identity, self.account_identity)
self.assertEqual(len(wot_graph.nx_graph.nodes()), 2)
self.assertEqual(len(wot_graph.nx_graph.edges()), 1)
self.lp.run_until_complete(exec_test())
0
Example 11
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Application')
@patch('sakia.core.Community')
def test_node_status_member(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
base_graph = BaseGraph(app, community)
certifier = Mock(specs='core.registry.Identity')
certifier.pubkey = "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ"
certifier.uid = "first_identity"
certifier.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=False)
account_identity = Mock(specs='core.registry.Identity')
account_identity.pubkey = "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn"
account_identity.uid = "second_uid"
account_identity.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
async def exec_test():
self.assertEquals((await base_graph.node_status(certifier, account_identity)), NodeStatus.OUT)
self.assertEquals((await base_graph.node_status(account_identity, account_identity)), NodeStatus.HIGHLIGHTED)
self.lp.run_until_complete(exec_test())
0
Example 12
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_add_identitiers(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
app.preferences = {'expert_mode': True}
base_graph = BaseGraph(app, community)
certifications = [
{
'identity': self.first_identity,
'cert_time': 49100,
'block_number': 900
},
{
'identity': self.second_identity,
'cert_time': 49800,
'block_number': 996
}
]
async def exec_test():
await base_graph.add_certifier_list(certifications, self.account_identity, self.account_identity)
self.assertEqual(len(base_graph.nx_graph.nodes()), 3)
self.assertEqual(len(base_graph.nx_graph.edges()), 2)
nodes = base_graph.nx_graph.nodes(data=True)
edges = base_graph.nx_graph.edges(data=True)
first_node = [n for n in nodes if n[0] == self.first_identity.pubkey][0]
self.assertEqual(first_node[1]['status'], NodeStatus.NEUTRAL)
self.assertEqual(first_node[1]['text'], certifications[0]['identity'].uid)
self.assertEqual(first_node[1]['tooltip'], certifications[0]['identity'].pubkey)
second_node = [n for n in nodes if n[0] == self.second_identity.pubkey][0]
self.assertEqual(second_node[1]['status'], NodeStatus.OUT)
self.assertEqual(second_node[1]['text'], certifications[1]['identity'].uid)
self.assertEqual(second_node[1]['tooltip'], certifications[1]['identity'].pubkey)
arc_from_first = [e for e in edges if e[0] == self.first_identity.pubkey][0]
self.assertEqual(arc_from_first[1], self.account_identity.pubkey)
self.assertEqual(arc_from_first[2]['status'], EdgeStatus.WEAK)
self.assertEqual(arc_from_first[2]['cert_time'], certifications[0]['cert_time'])
arc_from_second = [e for e in edges if e[0] == self.second_identity.pubkey][0]
self.assertEqual(arc_from_second[1], self.account_identity.pubkey)
self.assertEqual(arc_from_second[2]['status'], EdgeStatus.STRONG)
self.assertEqual(arc_from_second[2]['cert_time'], certifications[1]['cert_time'])
self.lp.run_until_complete(exec_test())
0
Example 13
Project: sakia Source File: test_base_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_add_certified(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
app.preferences = {'expert_mode': True}
base_graph = BaseGraph(app, community)
certifications = [
{
'identity': self.first_identity,
'cert_time': 49100,
'block_number': 900
},
{
'identity': self.second_identity,
'cert_time': 49800,
'block_number': 996
}
]
async def exec_test():
await base_graph.add_certified_list(certifications, self.account_identity, self.account_identity)
self.assertEqual(len(base_graph.nx_graph.nodes()), 3)
self.assertEqual(len(base_graph.nx_graph.edges()), 2)
nodes = base_graph.nx_graph.nodes(data=True)
first_node = [n for n in nodes if n[0] == self.first_identity.pubkey][0]
self.assertEqual(first_node[1]['status'], NodeStatus.NEUTRAL)
self.assertEqual(first_node[1]['text'], certifications[0]['identity'].uid)
self.assertEqual(first_node[1]['tooltip'], certifications[0]['identity'].pubkey)
second_node = [n for n in nodes if n[0] == self.second_identity.pubkey][0]
self.assertEqual(second_node[1]['status'], NodeStatus.OUT)
self.assertEqual(second_node[1]['text'], certifications[1]['identity'].uid)
self.assertEqual(second_node[1]['tooltip'], certifications[1]['identity'].pubkey)
self.lp.run_until_complete(exec_test())
0
Example 14
Project: sakia Source File: test_explorer_graph.py
def setUp(self):
self.setUpQuamash()
QLocale.setDefault(QLocale("en_GB"))
## Graph to test :
## - E
## A - B - C - D
##
## Path : Between A and C
self.idA = Mock(specs='core.registry.Identity')
self.idA.pubkey = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
self.idA.uid = "A"
self.idA.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.idB = Mock(specs='core.registry.Identity')
self.idB.pubkey = "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ"
self.idB.uid = "B"
self.idB.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.idC = Mock(specs='core.registry.Identity')
self.idC.pubkey = "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn"
self.idC.uid = "C"
self.idC.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=False)
self.idD = Mock(specs='core.registry.Identity')
self.idD.pubkey = "6R11KGpG6w5Z6JfiwaPf3k4BCMY4dwhjCdmjGpvn7Gz5"
self.idD.uid = "D"
self.idD.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.idE = Mock(specs='core.registry.Identity')
self.idE.pubkey = "CZVDEsM6pPNxhAvXApGM8MJ6ExBZVpc8PNVyDZ7hKxLu"
self.idE.uid = "E"
self.idE.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=False)
self.idA.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
{
'cert_time': 49800,
'identity': self.idB,
'block_number': 996
}
])
self.idA.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[])
self.idB.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
{
'cert_time': 49100,
'identity': self.idC,
'block_number': 990
}
])
self.idB.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[
{
'cert_time': 49800,
'identity': self.idA,
'block_number': 996
}
])
self.idC.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
{
'cert_time': 49100,
'identity': self.idD,
'block_number': 990
},
{
'cert_time': 49110,
'identity': self.idE,
'block_number': 990
}
])
self.idC.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[
{
'cert_time': 49100,
'identity': self.idB,
'block_number': 990
}
])
self.idD.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
])
self.idD.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[
{
'cert_time': 49100,
'identity': self.idC,
'block_number': 990
}])
self.idE.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
])
self.idE.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[
{
'cert_time': 49100,
'identity': self.idC,
'block_number': 990
}])
0
Example 15
Project: sakia Source File: test_explorer_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_start_stop_exploration(self, app, community):
async def explore_mock(id, steps):
await asyncio.sleep(0.1)
await asyncio.sleep(0.1)
await asyncio.sleep(0.1)
explorer_graph = ExplorerGraph(app, community)
explorer_graph._explore = explore_mock
async def exec_test():
self.assertEqual(explorer_graph.exploration_task, None)
explorer_graph.start_exploration(self.idA, 1)
self.assertNotEqual(explorer_graph.exploration_task, None)
task = explorer_graph.exploration_task
explorer_graph.start_exploration(self.idA, 1)
self.assertEqual(task, explorer_graph.exploration_task)
explorer_graph.start_exploration(self.idB, 1)
await asyncio.sleep(0)
self.assertTrue(task.cancelled())
self.assertNotEqual(task, explorer_graph.exploration_task)
task2 = explorer_graph.exploration_task
explorer_graph.start_exploration(self.idB, 2)
await asyncio.sleep(0)
self.assertTrue(task2.cancelled())
task3 = explorer_graph.exploration_task
explorer_graph.stop_exploration()
await asyncio.sleep(0)
self.assertTrue(task2.cancelled())
self.lp.run_until_complete(exec_test())
0
Example 16
Project: sakia Source File: test_wot_graph.py
def setUp(self):
self.setUpQuamash()
QLocale.setDefault(QLocale("en_GB"))
## Graph to test :
##
## A - B - C
##
## Path : Between A and C
self.account_identity = Mock(specs='core.registry.Identity')
self.account_identity.pubkey = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
self.account_identity.uid = "A"
self.account_identity.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.idB = Mock(specs='core.registry.Identity')
self.idB.pubkey = "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ"
self.idB.uid = "B"
self.idB.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=True)
self.idC = Mock(specs='core.registry.Identity')
self.idC.pubkey = "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn"
self.idC.uid = "C"
self.idC.is_member = CoroutineMock(spec='core.registry.Identity.is_member', return_value=False)
self.account_identity.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
{
'cert_time': 49800,
'identity': self.idB,
'block_number': 996
}
])
self.account_identity.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[])
self.idC.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certifierd_by',
return_value=[])
self.idC.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[
{
'cert_time': 49100,
'identity': self.idB,
'block_number': 990
}
])
self.idB.unique_valid_certified_by = CoroutineMock(spec='core.registry.Identity.certified_by',
return_value=[
{
'cert_time': 49100,
'identity': self.idC,
'block_number': 996
}
])
self.idB.unique_valid_certifiers_of = CoroutineMock(spec='core.registry.Identity.certifiers_of',
return_value=[
{
'cert_time': 49800,
'identity': self.account_identity,
'block_number': 996
}
])
0
Example 17
Project: sakia Source File: test_wot_graph.py
@patch('sakia.core.Application')
@patch('sakia.core.Community')
@patch('time.time', Mock(return_value=50000))
def test_explore_to_find_unknown(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
app.preferences = {'expert_mode': True}
wot_graph = WoTGraph(app, community)
identity_unknown = Mock(specs='core.registry.Identity')
identity_unknown.pubkey = "8Fi1VSTbjkXguwThF4v2ZxC5whK7pwG2vcGTkPUPjPGU"
identity_unknown.uid = "unkwn"
async def exec_test():
result = await wot_graph.explore_to_find_member(self.account_identity, identity_unknown)
self.assertFalse(result)
self.assertEqual(len(wot_graph.nx_graph.nodes()), 3)
self.assertEqual(len(wot_graph.nx_graph.edges()), 2)
self.lp.run_until_complete(exec_test())
0
Example 18
Project: sakia Source File: test_wot_graph.py
@patch('sakia.core.Community')
@patch('sakia.core.Application')
@patch('time.time', Mock(return_value=50000))
def test_shortest_path(self, app, community):
community.parameters = CoroutineMock(return_value = {'sigValidity': 1000})
community.network.confirmations = Mock(side_effect=lambda n: 4 if 996 else None)
app.preferences = {'expert_mode': True}
wot_graph = WoTGraph(app, community)
async def exec_test():
result = await wot_graph.explore_to_find_member(self.account_identity, self.idC)
self.assertTrue(result)
self.assertEqual(len(wot_graph.nx_graph.nodes()), 3)
self.assertEqual(len(wot_graph.nx_graph.edges()), 2)
path = await wot_graph.get_shortest_path_to_identity(self.account_identity, self.idC)
self.assertEqual(path[0], self.account_identity.pubkey,)
self.assertEqual(path[1], self.idB.pubkey)
self.assertEqual(path[2], self.idC.pubkey)
self.lp.run_until_complete(exec_test())