Exemplo n.º 1
0
 def test__getitem__(self):
     """
     Check the DataStore base class gets the requested item and does the
     necessary magic to return the value without associated metadata.
     """
     self.assertTrue(hasattr(DataStore, '__getitem__'))
     ds = DataStore()
     val = 'some arbitrary yet meaningless value'
     ds._get_item = MagicMock(return_value=(val, None, None))
     result = ds['foo']
     self.assertEqual(val, result)
     ds._get_item.assert_called_once_with('foo')
Exemplo n.º 2
0
 def test_updated(self):
     """
     Check the DataStore base class gets the requested item and returns the
     timestamp in position 1 of the tuple.
     """
     self.assertTrue(hasattr(DataStore, 'updated'))
     ds = DataStore()
     timestamp = time.time()
     ds._get_item = MagicMock(return_value=(None, timestamp, None))
     result = ds.updated('foo')
     self.assertEqual(timestamp, result)
     ds._get_item.assert_called_once_with('foo')
Exemplo n.º 3
0
 def test__setitem__(self):
     """
     Check the DataStore base class has a __setitem__ method.
     """
     self.assertTrue(hasattr(DataStore, '__setitem__'))
     ds = DataStore()
     val = 'some arbitrary yet meaningless value'
     ds._set_item = MagicMock()
     ds['foo'] = val
     self.assertEqual(1, ds._set_item.call_count)
     call_args = ds._set_item.call_args[0]
     self.assertEqual('foo', call_args[0])
     self.assertIsInstance(call_args[1], tuple)
     self.assertEqual(val, call_args[1][0])
     self.assertIsInstance(call_args[1][1], float)
Exemplo n.º 4
0
 def test_publisher(self):
     """
     Check the DataStore base class gets the requested item and returns the
     public key of the publisher associated with the item.
     """
     self.assertTrue(hasattr(DataStore, 'publisher'))
     ds = DataStore()
     val = {
         '_p4p2p': {
             'public_key': PUBLIC_KEY
         }
     }
     ds._get_item = MagicMock(return_value=(val, None, None))
     result = ds.publisher('foo')
     self.assertEqual(PUBLIC_KEY, result)
     ds._get_item.assert_called_once_with('foo')
Exemplo n.º 5
0
 def test_created(self):
     """
     Check the DataStore base class gets the requested item and returns the
     creation timestamp that the publisher has associated with the item.
     """
     self.assertTrue(hasattr(DataStore, 'created'))
     ds = DataStore()
     timestamp = time.time()
     val = {
         '_p4p2p': {
             'timestamp': timestamp
         }
     }
     ds._get_item = MagicMock(return_value=(val, None, None))
     result = ds.created('foo')
     self.assertEqual(timestamp, result)
     ds._get_item.assert_called_once_with('foo')