コード例 #1
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 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, 0.0))
     result = ds['foo']
     self.assertEqual(val, result)
     ds._get_item.assert_called_once_with('foo')
コード例 #2
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test_accessed(self):
     """
     Check the DataStore baase class gets the requested item and return the
     timestamp in position 2 of the tuple.
     """
     self.assertTrue(hasattr(DataStore, 'accessed'))
     ds = DataStore()
     timestamp = time.time()
     ds._get_item = MagicMock(return_value=(None, None, timestamp))
     result = ds.accessed('foo')
     self.assertEqual(timestamp, result)
     ds._get_item.assert_called_once_with('foo')
コード例 #3
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 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 = {
         'public_key': PUBLIC_KEY
     }
     ds._get_item = MagicMock(return_value=(val, None, 0.0))
     result = ds.publisher('foo')
     self.assertEqual(PUBLIC_KEY, result)
     ds._get_item.assert_called_once_with('foo')
コード例 #4
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 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 = {
         'timestamp': timestamp
     }
     ds._get_item = MagicMock(return_value=(val, None, 0.0))
     result = ds.created('foo')
     self.assertEqual(timestamp, result)
     ds._get_item.assert_called_once_with('foo')
コード例 #5
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test_keys(self):
     """
     Check the DataStore base class has a keys method.
     """
     self.assertTrue(hasattr(DataStore, 'keys'))
     ds = DataStore()
     self.assertRaises(NotImplementedError, ds.keys)
コード例 #6
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test_get_item(self):
     """
     Check the DataStore base class has a set_item method.
     """
     self.assertTrue(hasattr(DataStore, '_get_item'))
     ds = DataStore()
     self.assertRaises(NotImplementedError, ds._get_item, 'foo')
コード例 #7
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test__del__(self):
     """
     Check the DataStore base class has a __delitem__ method.
     """
     self.assertTrue(hasattr(DataStore, '__delitem__'))
     ds = DataStore()
     with self.assertRaises(NotImplementedError):
         del ds['item']
コード例 #8
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test_set_item(self):
     """
     Check the DataStore base class has a set_item method.
     """
     self.assertTrue(hasattr(DataStore, '_set_item'))
     ds = DataStore()
     self.assertRaises(NotImplementedError, ds._set_item, 'foo',
                       'some arbitrary yet meaningless value')
コード例 #9
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test__setitem__existing_value(self):
     """
     Check the DataStore base class has a __setitem__ method.
     """
     self.assertTrue(hasattr(DataStore, '__setitem__'))
     ds = DataStore()
     val = 'some arbitrary yet meaningless value'
     timestamp = time.time()
     ds._get_item = MagicMock(return_value=(val, timestamp, 0.0))
     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.assertTrue(timestamp < call_args[1][1])
     self.assertEqual(0.0, call_args[1][2])
コード例 #10
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
    def test__setitem__new_value(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()

        def side_effect(*args, **kwargs):
            raise KeyError()

        ds._get_item = MagicMock(side_effect=side_effect)
        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)
        self.assertEqual(call_args[1][2], 0.0)
コード例 #11
0
ファイル: test_storage.py プロジェクト: waseem18/drogulus
 def test_touch(self):
     """
     Ensure that the touch method updates the timestamp for a referenced
     item.
     """
     self.assertTrue(hasattr(DataStore, 'touch'))
     ds = DataStore()
     timestamp = time.time()
     ds._get_item = MagicMock(return_value=('bar', timestamp, timestamp))
     ds._set_item = MagicMock()
     ds.touch('foo')
     self.assertEqual(1, ds._set_item.call_count)
     args = ds._set_item.call_args_list[0][0]
     self.assertEqual('foo', args[0])
     self.assertEqual('bar', args[1][0])
     self.assertEqual(args[1][1], timestamp)
     self.assertTrue(args[1][2] > timestamp)