Skip to content

Commit

Permalink
Adds tests for api.pure.web_services.context.TokenResponseParser
Browse files Browse the repository at this point in the history
  • Loading branch information
David Naughton authored and nihiliad committed Nov 21, 2023
1 parent 4b2ddc8 commit ad7d9a0
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions experts/api/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def items(response:OffsetResponse_contra) -> list[Mapping]:
TokenResponse_contra = TypeVar('TokenResponsee_contra', bound=TokenResponse, contravariant=True)

class TokenResponseParser(Protocol, Generic[TokenResponse_contra]):
# Not all APIs more have this:
# @staticmethod
# def total_items(response:TokenResponse_contra) -> int:
# ...
Expand Down
99 changes: 99 additions & 0 deletions tests/api/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,105 @@ def test_pure_ws_offset_response_parser():
assert parser.items_per_page(response) == response['pageInformation']['size']
assert parser.items(response) == response['items']

def test_pure_ws_token_response_parser():
parser = pure_ws_context.TokenResponseParser
response1 = {
"count": 3,
"resumptionToken": "eyJzZXF1ZW5jZU51bWJlciI6MTk0MTM1MzcyfQ==",
"moreChanges": True,
"items": [
{
"uuid": "d09e017d-4e1d-403c-a703-6c3d11b039b4",
"changeType": "UPDATE",
"family": "dk.atira.pure.api.shared.contentimport.model.ImportResult",
"familySystemName": "ImportResult",
"version": -1
},
{
"uuid": "d09e017d-4e1d-403c-a703-6c3d11b039b4",
"changeType": "UPDATE",
"family": "dk.atira.pure.api.shared.contentimport.model.ImportResult",
"familySystemName": "ImportResult",
"version": -1
},
{
"uuid": "d09e017d-4e1d-403c-a703-6c3d11b039b4",
"changeType": "UPDATE",
"family": "dk.atira.pure.api.shared.contentimport.model.ImportResult",
"familySystemName": "ImportResult",
"version": -1
},
],
"navigationLinks": [
{
"ref": "next",
"href": "https://experts.umn.edu/ws/api/516/changes/eyJzZXF1ZW5jZU51bWJlciI6MTk0MTM1MzcyfQ=="
},
],
}
assert parser.items_per_page(response1) == response1['count']
assert parser.token(response1) == response1['resumptionToken']
assert parser.more_items(response1) == response1['moreChanges']
assert parser.more_items(response1) == True
assert parser.items(response1) == response1['items']

response2 = {
"count": 0,
"resumptionToken": "eyJzZXF1ZW5jZU51bWJlciI6MTk0MTM1NDcyfQ==",
"moreChanges": True,
"navigationLinks": [
{
"ref": "next",
"href": "https://experts.umn.edu/ws/api/516/changes/eyJzZXF1ZW5jZU51bWJlciI6MTk0MTM1NDcyfQ=="
}
]
}
assert parser.items_per_page(response2) == response2['count']
assert parser.token(response2) == response2['resumptionToken']
assert parser.more_items(response2) == response2['moreChanges']
assert parser.more_items(response2) == True
assert parser.items(response2) == []

response3 = {
"count": 3,
"resumptionToken": "eyJzZXF1ZW5jZU51bWJlciI6MTk0MTM1NzcyfQ==",
"moreChanges": False,
"items": [
{
"uuid": "67073a6c-e84a-470f-9b45-d780cfe0d7cc",
"changeType": "UPDATE",
"family": "dk.atira.pure.api.shared.model.researchoutput.ResearchOutput",
"familySystemName": "ResearchOutput",
"version": 3
},
{
"uuid": "960c880e-4835-4850-9461-d0415c57abd4",
"changeType": "UPDATE",
"family": "dk.atira.pure.api.shared.model.researchoutput.ResearchOutput",
"familySystemName": "ResearchOutput",
"version": 7
},
{
"uuid": "35890d58-587a-4b59-a258-c7a70a1e49dd",
"changeType": "UPDATE",
"family": "dk.atira.pure.api.shared.model.researchoutput.ResearchOutput",
"familySystemName": "ResearchOutput",
"version": 2
},
],
"navigationLinks": [
{
"ref": "next",
"href": "https://experts.umn.edu/ws/api/516/changes/eyJzZXF1ZW5jZU51bWJlciI6MTk0MTM1NzcyfQ=="
},
],
}
assert parser.items_per_page(response3) == response3['count']
assert parser.token(response3) == response3['resumptionToken']
assert parser.more_items(response3) == response3['moreChanges']
assert parser.more_items(response3) == False
assert parser.items(response3) == response3['items']

#def test_valid_version():
# versions = common.versions
# assert len(versions) > 0
Expand Down

0 comments on commit ad7d9a0

Please sign in to comment.