def test_join_with_peers(self): """ Ensure that the join method works as expected given a valid list of existing contacts on the network. """ version = get_version() data_dump = { 'contacts': [ { 'public_key': PUBLIC_KEY, 'version': version, 'uri': 'http://192.168.0.1:1908', }, ], 'blacklist': [BAD_PUBLIC_KEY, ] } drog = Drogulus(PRIVATE_KEY, PUBLIC_KEY, self.event_loop, self.connector) result = asyncio.Future() drog._node.join = MagicMock(return_value=result) drog.join(data_dump) drog._node.join.assert_called_once_with(data_dump) drog.set = MagicMock() result.set_result(True) self.event_loop.run_until_complete(result) drog.set.assert_called_once_with(drog.whoami['public_key'], drog.whoami)
def test_join_with_peers(self): """ Ensure that the join method works as expected given a valid list of existing contacts on the network. """ version = get_version() data_dump = { 'contacts': [ { 'public_key': PUBLIC_KEY, 'version': version, 'uri': 'http://192.168.0.1:1908', }, ], 'blacklist': [ BAD_PUBLIC_KEY, ] } drog = Drogulus(PRIVATE_KEY, PUBLIC_KEY, self.event_loop, self.connector) result = asyncio.Future() drog._node.join = MagicMock(return_value=result) drog.join(data_dump) drog._node.join.assert_called_once_with(data_dump) drog.set = MagicMock() result.set_result(True) self.event_loop.run_until_complete(result) drog.set.assert_called_once_with(drog.whoami['public_key'], drog.whoami)
def test_set_bespoke_duplication_count(self): """ Ensure the duplication count is passed into the replicate method. """ drog = Drogulus(PRIVATE_KEY, PUBLIC_KEY, self.event_loop, self.connector) result = [] for i in range(20): result.append(asyncio.Future()) drog._node.replicate = MagicMock(return_value=result) pending_result = drog.set('foo', 'bar', duplicate=5) self.assertIsInstance(pending_result, list) self.assertEqual(1, drog._node.replicate.call_count) called_with = drog._node.replicate.call_args_list[0][0] self.assertEqual(called_with[0], 5) self.assertEqual(called_with[1], construct_key(PUBLIC_KEY, 'foo')) self.assertEqual(called_with[2], 'bar') self.assertIsInstance(called_with[3], float) self.assertEqual(called_with[4], 0.0) self.assertEqual(called_with[5], self.version) self.assertEqual(called_with[6], PUBLIC_KEY) self.assertEqual(called_with[7], 'foo') self.assertIsInstance(called_with[8], str)
def test_set(self): """ Ensure a basic set operation works as expected. """ drog = Drogulus(PRIVATE_KEY, PUBLIC_KEY, self.event_loop, self.connector) result = [] for i in range(20): result.append(asyncio.Future()) drog._node.replicate = MagicMock(return_value=result) pending_result = drog.set('foo', 'bar') self.assertIsInstance(pending_result, list) self.assertEqual(1, drog._node.replicate.call_count) called_with = drog._node.replicate.call_args_list[0][0] self.assertEqual(called_with[0], DUPLICATION_COUNT) self.assertEqual(called_with[1], construct_key(PUBLIC_KEY, 'foo')) self.assertEqual(called_with[2], 'bar') self.assertIsInstance(called_with[3], float) self.assertEqual(called_with[4], 0.0) self.assertEqual(called_with[5], self.version) self.assertEqual(called_with[6], PUBLIC_KEY) self.assertEqual(called_with[7], 'foo') self.assertIsInstance(called_with[8], str)