예제 #1
0
파일: test_storage.py 프로젝트: ntoll/p4p2p
 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')
예제 #2
0
파일: test_storage.py 프로젝트: ntoll/p4p2p
 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')
예제 #3
0
파일: test_storage.py 프로젝트: ntoll/p4p2p
 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)
예제 #4
0
파일: test_storage.py 프로젝트: ntoll/p4p2p
 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')
예제 #5
0
파일: test_storage.py 프로젝트: ntoll/p4p2p
 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')