Ejemplo n.º 1
0
 def test_get_forced_refresh_no_existing_cached_value(self):
     """
     Ensures that even if there's no cached value a new lookup is executed
     if the 'forced' flag is True.
     """
     connector = HttpConnector(self.event_loop)
     self.assertEqual({}, connector.lookups)
     handler = Node(PUBLIC_KEY, PRIVATE_KEY, self.event_loop, connector,
                    1908)
     faux_lookup = asyncio.Future()
     handler.retrieve = mock.MagicMock(return_value=faux_lookup)
     test_key = hashlib.sha512().hexdigest()
     result = connector.get(test_key, handler, forced=True)
     handler.retrieve.assert_called_once_with(test_key)
     self.assertIn(test_key, connector.lookups)
     self.assertIsInstance(connector.lookups[test_key]['last_access'],
                           float)
     self.assertEqual(connector.lookups[test_key]['lookup'], faux_lookup)
     self.assertEqual(result['key'], test_key)
     self.assertEqual(result['status'], faux_lookup._state.lower())
     self.assertEqual(2, len(result))
Ejemplo n.º 2
0
 def test_get_new_lookup(self):
     """
     Getting an unknown key fires a new lookup that is initially produces a
     'pending' status.
     """
     connector = HttpConnector(self.event_loop)
     self.assertEqual({}, connector.lookups)
     handler = Node(PUBLIC_KEY, PRIVATE_KEY, self.event_loop, connector,
                    1908)
     faux_lookup = asyncio.Future()
     handler.retrieve = mock.MagicMock(return_value=faux_lookup)
     test_key = hashlib.sha512().hexdigest()
     result = connector.get(test_key, handler)
     handler.retrieve.assert_called_once_with(test_key)
     self.assertIn(test_key, connector.lookups)
     self.assertIsInstance(connector.lookups[test_key]['last_access'],
                           float)
     self.assertEqual(connector.lookups[test_key]['lookup'], faux_lookup)
     self.assertEqual(result['key'], test_key)
     self.assertEqual(result['status'], faux_lookup._state.lower())
     self.assertEqual(2, len(result))
Ejemplo n.º 3
0
 def test_get_forced_refresh_existing_value(self):
     """
     Ensures that an existing result is ignored and a new lookup is executed
     if the 'forced' flag is True.
     """
     connector = HttpConnector(self.event_loop)
     self.assertEqual({}, connector.lookups)
     handler = Node(PUBLIC_KEY, PRIVATE_KEY, self.event_loop, connector,
                    1908)
     cached_lookup = asyncio.Future()
     cached_lookup.set_result('foo')
     test_key = hashlib.sha512().hexdigest()
     connector.lookups[test_key] = cached_lookup
     new_lookup = asyncio.Future()
     handler.retrieve = mock.MagicMock(return_value=new_lookup)
     result = connector.get(test_key, handler, forced=True)
     self.assertIn(test_key, connector.lookups)
     self.assertIsInstance(connector.lookups[test_key]['last_access'],
                           float)
     self.assertEqual(connector.lookups[test_key]['lookup'], new_lookup)
     self.assertEqual(result['key'], test_key)
     self.assertEqual(result['status'], new_lookup._state.lower())
     self.assertEqual(2, len(result))