-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add robust edge case tests to github_helpers.py #5774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
be61c7f
df5bad3
7e5617d
9ca5e2a
97b2dfb
dcc194b
aae792a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -117,11 +117,12 @@ def test_execute_and_paginate_one_page_count_mismatch(self): | |||||||||
self.client.execute = mock.MagicMock( | ||||||||||
return_value=self.mock_result(["foo"], total_count=2), | ||||||||||
) | ||||||||||
self.assertRaises( | ||||||||||
AssertionError, | ||||||||||
list, | ||||||||||
self.client.execute_and_paginate(_TEST_QUERY, _TEST_QUERY_PATH), | ||||||||||
) | ||||||||||
with self.assertRaises(AssertionError): | ||||||||||
list( | ||||||||||
self.client.execute_and_paginate( | ||||||||||
_TEST_QUERY, _TEST_QUERY_PATH | ||||||||||
) | ||||||||||
) | ||||||||||
self.client.execute.assert_called_once_with(_EXP_QUERY_FIRST_PAGE) | ||||||||||
|
||||||||||
def test_execute_and_paginate_two_page(self): | ||||||||||
|
@@ -176,6 +177,78 @@ def test_execute_and_paginate_first_page_continue(self): | |||||||||
) | ||||||||||
self.client.execute.assert_called_once_with(_EXP_QUERY_SECOND_PAGE) | ||||||||||
|
||||||||||
def test_execute_and_paginate_invalid_nodes_type(self): | ||||||||||
invalid_result = { | ||||||||||
"top": { | ||||||||||
"child": { | ||||||||||
"nodes": "not-a-list", | ||||||||||
"pageInfo": { | ||||||||||
"hasNextPage": False, | ||||||||||
"endCursor": None, | ||||||||||
}, | ||||||||||
"totalCount": 1, | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
self.client.execute = mock.MagicMock(return_value=invalid_result) | ||||||||||
with self.assertRaises(TypeError): | ||||||||||
list( | ||||||||||
self.client.execute_and_paginate( | ||||||||||
_TEST_QUERY, _TEST_QUERY_PATH | ||||||||||
) | ||||||||||
Comment on lines
+196
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [diff] reported by reviewdog 🐶
Suggested change
|
||||||||||
) | ||||||||||
|
||||||||||
def test_execute_and_paginate_api_failure(self): | ||||||||||
self.client.execute = mock.MagicMock( | ||||||||||
side_effect=RuntimeError("API down") | ||||||||||
) | ||||||||||
with self.assertRaises(RuntimeError): | ||||||||||
list( | ||||||||||
self.client.execute_and_paginate( | ||||||||||
_TEST_QUERY, _TEST_QUERY_PATH | ||||||||||
) | ||||||||||
Comment on lines
+207
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [diff] reported by reviewdog 🐶
Suggested change
|
||||||||||
) | ||||||||||
|
||||||||||
def test_execute_and_paginate_large_pagination(self): | ||||||||||
def paging(query): | ||||||||||
if query == _EXP_QUERY_FIRST_PAGE: | ||||||||||
return self.mock_result( | ||||||||||
[f"user{i}" for i in range(100)], | ||||||||||
total_count=150, | ||||||||||
has_next_page=True, | ||||||||||
) | ||||||||||
elif query == _EXP_QUERY_SECOND_PAGE: | ||||||||||
return self.mock_result([f"user{i}" for i in range(100, 150)]) | ||||||||||
|
||||||||||
self.client.execute = mock.MagicMock( | ||||||||||
side_effect=paging | ||||||||||
) | ||||||||||
Comment on lines
+223
to
+225
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [diff] reported by reviewdog 🐶
Suggested change
|
||||||||||
result = list( | ||||||||||
self.client.execute_and_paginate(_TEST_QUERY, _TEST_QUERY_PATH) | ||||||||||
) | ||||||||||
self.assertEqual(len(result), 150) | ||||||||||
|
||||||||||
def test_execute_and_paginate_missing_cursor_with_has_next(self): | ||||||||||
bad_result = { | ||||||||||
"top": { | ||||||||||
"child": { | ||||||||||
"nodes": ["foo"], | ||||||||||
"pageInfo": { | ||||||||||
"hasNextPage": True, | ||||||||||
"endCursor": None, | ||||||||||
}, | ||||||||||
"totalCount": 2, | ||||||||||
} | ||||||||||
} | ||||||||||
} | ||||||||||
self.client.execute = mock.MagicMock(return_value=bad_result) | ||||||||||
with self.assertRaises(Exception): | ||||||||||
list( | ||||||||||
self.client.execute_and_paginate( | ||||||||||
_TEST_QUERY, _TEST_QUERY_PATH | ||||||||||
) | ||||||||||
Comment on lines
+247
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [diff] reported by reviewdog 🐶
Suggested change
|
||||||||||
) | ||||||||||
|
||||||||||
|
||||||||||
if __name__ == "__main__": | ||||||||||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[diff] reported by reviewdog 🐶