From 58ecbf526fdfc1dc580d6dcc52c6bd4d45514c6d Mon Sep 17 00:00:00 2001 From: a9phhzz Date: Wed, 26 May 2021 15:31:16 -0500 Subject: [PATCH 1/2] add support for is_in attribute condition --- falcano/attributes.py | 4 ++-- tests/unit/test_model.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/falcano/attributes.py b/falcano/attributes.py index f849230..931f58c 100644 --- a/falcano/attributes.py +++ b/falcano/attributes.py @@ -214,8 +214,8 @@ def eq(self, value: Any) -> 'Eq': # pylint: disable=invalid-name '''Return a condition that this attribute is equal to the value''' return self.attr_fn()(self.attr_name).eq(value) - # def is_in(self, *values: Any) -> 'In': - # return Path(self).is_in(*values) + def is_in(self, *values: Any) -> 'In': + return Attr(self).is_in(*values) def exists(self) -> 'Exists': '''Return a condition that this attribute exists''' diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py index f0490ed..1cb4e0c 100644 --- a/tests/unit/test_model.py +++ b/tests/unit/test_model.py @@ -427,6 +427,22 @@ def test_query(mock_table_resource): Select='SPECIFIC_ATTRIBUTES', ExpressionAttributeNames={'#0': 'FirstName', '#1': 'LastName'} ) + Person.query( + morty.PK, + range_key_condition=Person.SK.startswith("person"), + filter_condition=Person.LastName.is_in(["Smith", "Sanchez"]), + consistent_read=True, + limit=1, + attributes_to_get=['FirstName', 'LastName'], + page_size=20 + ) + mock_table.query.assert_called_with( + TableName='unit-test-table', + KeyConditionExpression=Person.get_hash_key().eq(morty.PK) & Person.SK.startswith("person"), + FilterExpression=Person.LastName.is_in(["Smith", "Sanchez"]), ConsistentRead=True, Limit=20, ProjectionExpression='#0, #1', + Select='SPECIFIC_ATTRIBUTES', ExpressionAttributeNames={'#0': 'FirstName', '#1': 'LastName'} + ) + def test_serialize(): attrs = rick.serialize() From 2ae86065ba97427e4a1a5efd8bcf51fb1ae5cb33 Mon Sep 17 00:00:00 2001 From: a9phhzz Date: Wed, 26 May 2021 15:40:42 -0500 Subject: [PATCH 2/2] fix lint --- falcano/attributes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/falcano/attributes.py b/falcano/attributes.py index 931f58c..aec4701 100644 --- a/falcano/attributes.py +++ b/falcano/attributes.py @@ -215,6 +215,7 @@ def eq(self, value: Any) -> 'Eq': # pylint: disable=invalid-name return self.attr_fn()(self.attr_name).eq(value) def is_in(self, *values: Any) -> 'In': + ''' Return a condition that the value is in a set of values ''' return Attr(self).is_in(*values) def exists(self) -> 'Exists':