Skip to content

Commit

Permalink
sligtly change test on _utils and add page2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
LanaNYC committed Sep 20, 2024
1 parent 95569af commit 1d9800b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/utils_pagination_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ def test_fetch_next_page_no_next_link(self):
@patch("fhirclient._utils._execute_pagination_request")
def test_iter_pages(self, mock_fetch_next_page):
inst = self.instantiate_from("bundle-example.json")
inst_page2 = self.instantiate_from("bundle-example-page2.json")

# Set up the mock to return a new bundle, then None to stop iteration
mock_fetch_next_page.side_effect = [inst, None]
mock_fetch_next_page.side_effect = [inst_page2, None]
pages = list(iter_pages(inst))

# Check that two bundles were returned (the first bundle and the one from mock)
self.assertEqual(len(pages), 2)
self.assertIsInstance(pages[0], Bundle)
self.assertIsInstance(pages[1], Bundle)

# Compare JSON representations instead of object instances
self.assertNotEqual(pages[0].as_json(), pages[1].as_json()) # Ensure the two pages are different
self.assertEqual(pages[0].as_json(), inst.as_json())
self.assertEqual(pages[1].as_json(), inst.as_json())
self.assertEqual(pages[1].as_json(), inst_page2.as_json()) # Ensure the second page is correct

# Ensure that _fetch_next_page was called twice
self.assertEqual(mock_fetch_next_page.call_count, 2)

0 comments on commit 1d9800b

Please sign in to comment.