[dynamodb2] adds lookup method to Table class

includes additional test coverage
This commit is contained in:
Zack Kourouma 2015-05-20 11:20:16 -04:00
parent be5f041416
commit f03ded7e90
2 changed files with 30 additions and 0 deletions

View File

@ -288,6 +288,16 @@ class Table(object):
results.append(result)
return results, scanned_count, last_page
def lookup(self, *args, **kwargs):
if not self.schema:
self.describe()
for x, arg in enumerate(args):
kwargs[self.schema[x].name] = arg
ret = self.get_item(**kwargs)
if not ret.keys():
return None
return ret
class DynamoDBBackend(BaseBackend):

View File

@ -533,3 +533,23 @@ def test_query_with_global_indexes():
results = table.query(status__eq='active')
list(results).should.have.length_of(0)
@mock_dynamodb2
def test_lookup():
from decimal import Decimal
table = Table.create('messages', schema=[
HashKey('test_hash'),
RangeKey('test_range'),
], throughput={
'read': 10,
'write': 10,
})
hash_key = 3241526475
range_key = 1234567890987
data = {'test_hash': hash_key, 'test_range': range_key}
table.put_item(data=data)
message = table.lookup(hash_key, range_key)
message.get('test_hash').should.equal(Decimal(hash_key))
message.get('test_range').should.equal(Decimal(range_key))