Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 78 additions & 5 deletions github_tools/github_helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Comment on lines +122 to +124
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
self.client.execute_and_paginate(
_TEST_QUERY, _TEST_QUERY_PATH
)
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):
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
self.client.execute_and_paginate(
_TEST_QUERY, _TEST_QUERY_PATH
)
self.client.execute_and_paginate(_TEST_QUERY, _TEST_QUERY_PATH)

)

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
self.client.execute_and_paginate(
_TEST_QUERY, _TEST_QUERY_PATH
)
self.client.execute_and_paginate(_TEST_QUERY, _TEST_QUERY_PATH)

)

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
self.client.execute = mock.MagicMock(
side_effect=paging
)
self.client.execute = mock.MagicMock(side_effect=paging)

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
self.client.execute_and_paginate(
_TEST_QUERY, _TEST_QUERY_PATH
)
self.client.execute_and_paginate(_TEST_QUERY, _TEST_QUERY_PATH)

)


if __name__ == "__main__":
unittest.main()
Loading