Beispiel #1
0
 def test_read_table_item(self):
     client = Client(table_name='foo')
     m = Mock()
     m.get_item = Mock(
         return_value={'Item': client._serialize({'data': 'bar'})})
     client.table = m
     eq_(client.read_table_item('buz'), {'data': 'bar'})
Beispiel #2
0
 def test_generate_hash_key(self):
     with patch('hashlib.sha1') as p:
         m = Mock()
         m.hexdigest = Mock(return_value='foo')
         p.return_value = m
         client = Client(table_name='foo')
         eq_(client._generate_hash_key('bar'), 'foo')
Beispiel #3
0
 def test_delete_error(self):
     client = Client(table_name='foo')
     client.delete_table_item = Mock(
         side_effect=botocore.exceptions.ClientError(
             {'Error': {'Code': 'ResourceNotFoundException'}},
             'delete_item'))
     client.cache['bar'] = 'buz'
     eq_(client.delete('bar'), False)
Beispiel #4
0
 def test_get_error(self):
     client = Client(table_name='foo')
     client.report_error = True
     client._is_available_item = Mock(return_value=True)
     client.read_table_item = Mock(
         side_effect=botocore.exceptions.ClientError(
             {'Error': {'Code': 'ResourceNotFoundException'}}, 'get_item'))
     client.get('foo')
Beispiel #5
0
 def test_set_report_error(self):
     client = Client(table_name='foo')
     client.report_error = True
     client.put_table_item = Mock(
         side_effect=botocore.exceptions.ClientError(
             {'Error': {'Code': 'ResourceNotFoundException'}}, 'put_item'))
     client.set('bar', 'buz')
Beispiel #6
0
 def test_set(self):
     client = Client(table_name='foo')
     client.put_table_item = Mock()
     eq_(client.set('bar', 'buz'), True)
Beispiel #7
0
 def test__setitem__(self):
     client = Client(table_name='foo')
     client.set = Mock(return_value=True)
     client['bar'] = 'buz'
Beispiel #8
0
 def test_get_from_table(self):
     client = Client(table_name='foo')
     client._is_available_item = Mock(return_value=True)
     client.read_table_item = Mock(
         return_value={'data': 'qux', 'until': -1})
     eq_(client.get('foo'), 'qux')
Beispiel #9
0
 def test_get_until_time_custum(self):
     with patch('time.time') as p:
         p.return_value = 100.1
         client = Client(table_name='foo')
         eq_(client._get_until_time(100), 200)
Beispiel #10
0
 def test_delete_not_exist(self):
     client = Client(table_name='foo')
     client.delete_table_item = Mock()
     eq_(client.delete('bar'), True)
Beispiel #11
0
 def test_serialize(self):
     client = Client(table_name='foo')
     eq_(
         client._deserialize(client._serialize({'data': 'bar', 'until': 1.0})),
         {'data': 'bar', 'until': 1}
     )
Beispiel #12
0
 def test_delete_table_item(self):
     client = Client(table_name='foo')
     client.table = Mock()
     client.delete_table_item('bar')
Beispiel #13
0
 def test_put_table_item(self):
     client = Client(table_name='foo')
     client.table = Mock()
     client.put_table_item('bar', {'data': 'buz'})
Beispiel #14
0
 def test__getitem__(self):
     client = Client(table_name='foo')
     client.get = Mock(return_value='bar')
     eq_(client['buz'], 'bar')
Beispiel #15
0
 def test_is_available_item(self):
     with patch('time.time') as p:
         p.return_value = 102.0
         client = Client(table_name='foo')
         eq_(client._is_available_item({}), True)
         eq_(client._is_available_item({'until': 101}), False)
Beispiel #16
0
 def test__delitem__(self):
     client = Client(table_name='foo')
     client.delete = Mock()
     del client['bar']
Beispiel #17
0
 def test_delete(self):
     client = Client(table_name='foo')
     client.delete_table_item = Mock()
     client.cache['bar'] = 'buz'
     eq_(client.delete('bar'), True)
Beispiel #18
0
 def test_get_from_cache(self):
     client = Client(table_name='foo')
     client._is_available_item = Mock(return_value=True)
     client.cache = {'foo': {'data': 'bar', 'until': -1}}
     eq_(client.get('foo'), 'bar')
Beispiel #19
0
 def test_get_from_cache_unavailable(self):
     client = Client(table_name='foo')
     client._is_available_item = Mock(return_value=False)
     client.cache = {'foo': {'data': 'bar', 'until': -1}}
     client.read_table_item = Mock()
     eq_(client.get('foo', 'buz'), 'buz')
Beispiel #20
0
 def test_get_until_time_default(self):
     client = Client(table_name='foo')
     eq_(client._get_until_time(), -1)