diff --git a/moto/dynamodb2/models.py b/moto/dynamodb2/models.py index e679e0fd9..7e2c37f9d 100644 --- a/moto/dynamodb2/models.py +++ b/moto/dynamodb2/models.py @@ -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): diff --git a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py index 496aaed1e..a08b4b521 100644 --- a/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py +++ b/tests/test_dynamodb2/test_dynamodb_table_with_range_key.py @@ -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))