Skip to content

Commit

Permalink
Merge pull request #43 from 3mcloud/feature/is_in
Browse files Browse the repository at this point in the history
add support for is_in attribute condition
  • Loading branch information
jjf130 authored May 26, 2021
2 parents 5012139 + 2ae8606 commit d521d7b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions falcano/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ 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 a condition that the value is in a set of values '''
return Attr(self).is_in(*values)

def exists(self) -> 'Exists':
'''Return a condition that this attribute exists'''
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit d521d7b

Please sign in to comment.