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')
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')
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')
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')