Skip to content

Commit

Permalink
✅ add test coverage for querying storage record with pagination and p…
Browse files Browse the repository at this point in the history
…ost_filter

Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Jul 3, 2024
1 parent d092771 commit 3ebce10
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions aries_cloudagent/messaging/models/tests/test_base_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,37 @@ async def test_query_with_limit_and_offset(self):
assert result[0]._id == record_id
assert result[0].value == record_value
assert result[0].a == "one"

async def test_query_with_limit_and_offset_and_post_filter(self):
session = InMemoryProfile.test_session()
mock_storage = mock.MagicMock(BaseStorage, autospec=True)
session.context.injector.bind_instance(BaseStorage, mock_storage)
record_id = "record_id"
a_record = ARecordImpl(ident=record_id, a="one", b="two", code="red")
record_value = a_record.record_value
record_value.update({"created_at": time_now(), "updated_at": time_now()})
tag_filter = {"code": "red"}
stored = StorageRecord(
ARecordImpl.RECORD_TYPE,
json.dumps(record_value),
{"code": "red"},
record_id,
)
mock_storage.find_all_records.return_value = [stored] * 15 # return 15 records

# Query with limit and offset
result = await ARecordImpl.query(
session,
tag_filter,
limit=10,
offset=5,
post_filter_positive={"a": "one"},
)
mock_storage.find_all_records.assert_awaited_once_with(
type_filter=ARecordImpl.RECORD_TYPE, tag_query=tag_filter
)
assert len(result) == 10
assert result and isinstance(result[0], ARecordImpl)
assert result[0]._id == record_id
assert result[0].value == record_value
assert result[0].a == "one"

0 comments on commit 3ebce10

Please sign in to comment.