-
Notifications
You must be signed in to change notification settings - Fork 14
Fix for not retrieving all items when response has multiple pages of items #318
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
Merged
renoyjohnm
merged 6 commits into
development
from
rjohn/fix_not_retrieving_all_pages_pagination
Dec 13, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d8348fb
Fix for not retrieving all items when response has multipage items
renoyjohnm 94ad48c
Fix issue with formatting
renoyjohnm d6ad6bd
Fixing test failures
renoyjohnm e029e22
Use ThreadPoolExecutor to parallelize fetching of multi pages of items
renoyjohnm 5dd9c4a
Revert "Use ThreadPoolExecutor to parallelize fetching of multi pages…
renoyjohnm a093c0c
Adding --query-page-size argument to tabcmd
renoyjohnm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| import unittest | ||
| from unittest.mock import MagicMock, patch | ||
| import tableauserverclient as TSC | ||
| from tabcmd.commands.server import Server | ||
|
|
||
|
|
||
| class TestServer(unittest.TestCase): | ||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_returns_items(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = None | ||
|
|
||
| pagination_item = MagicMock() | ||
| pagination_item.total_available = 1 | ||
| pagination_item.page_number = 1 | ||
| pagination_item.page_size = 1 | ||
|
|
||
| item = MagicMock() | ||
| item_endpoint.get.return_value = ([item], pagination_item) | ||
|
|
||
| result = Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| self.assertEqual(result, [item]) | ||
| logger.debug.assert_called() | ||
| item_endpoint.get.assert_called() | ||
|
|
||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_no_items_found(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = None | ||
|
|
||
| pagination_item = MagicMock() | ||
| pagination_item.total_available = 0 | ||
| pagination_item.page_number = 1 | ||
| pagination_item.page_size = 1 | ||
|
|
||
| item_endpoint.get.return_value = ([], pagination_item) | ||
|
|
||
| with self.assertRaises(TSC.ServerResponseError): | ||
| Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| logger.debug.assert_called() | ||
| item_endpoint.get.assert_called() | ||
|
|
||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_with_container(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = MagicMock() | ||
| container.id = "container_id" | ||
|
|
||
| pagination_item = MagicMock() | ||
| pagination_item.total_available = 1 | ||
| pagination_item.page_number = 1 | ||
| pagination_item.page_size = 1 | ||
|
|
||
| item = MagicMock() | ||
| item.project_id = "container_id" | ||
| item_endpoint.get.return_value = ([item], pagination_item) | ||
|
|
||
| result = Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| self.assertEqual(result, [item]) | ||
| logger.debug.assert_called() | ||
| item_endpoint.get.assert_called() | ||
|
|
||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_with_container_no_match(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = MagicMock() | ||
| container.id = "container_id" | ||
|
|
||
| pagination_item = MagicMock() | ||
| pagination_item.total_available = 1 | ||
| pagination_item.page_number = 1 | ||
| pagination_item.page_size = 1 | ||
|
|
||
| item = MagicMock() | ||
| item.project_id = "different_container_id" | ||
| item_endpoint.get.return_value = ([item], pagination_item) | ||
|
|
||
| result = Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| self.assertEqual(result, []) | ||
| logger.debug.assert_called() | ||
| item_endpoint.get.assert_called() | ||
|
|
||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_multiple_pages(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = None | ||
|
|
||
| pagination_item_1 = MagicMock() | ||
| pagination_item_1.total_available = 3 | ||
| pagination_item_1.page_number = 1 | ||
| pagination_item_1.page_size = 1 | ||
|
|
||
| pagination_item_2 = MagicMock() | ||
| pagination_item_2.total_available = 3 | ||
| pagination_item_2.page_number = 2 | ||
| pagination_item_2.page_size = 1 | ||
|
|
||
| pagination_item_3 = MagicMock() | ||
| pagination_item_3.total_available = 3 | ||
| pagination_item_3.page_number = 3 | ||
| pagination_item_3.page_size = 1 | ||
|
|
||
| item_1 = MagicMock() | ||
| item_2 = MagicMock() | ||
| item_3 = MagicMock() | ||
|
|
||
| item_endpoint.get.side_effect = [ | ||
| ([item_1], pagination_item_1), | ||
| ([item_2], pagination_item_2), | ||
| ([item_3], pagination_item_3), | ||
| ] | ||
|
|
||
| result = Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| self.assertEqual(result, [item_1, item_2, item_3]) | ||
| self.assertEqual(item_endpoint.get.call_count, 3) | ||
| logger.debug.assert_called() | ||
|
|
||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_multiple_pages_with_container(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = MagicMock() | ||
| container.id = "container_id" | ||
|
|
||
| pagination_item_1 = MagicMock() | ||
| pagination_item_1.total_available = 3 | ||
| pagination_item_1.page_number = 1 | ||
| pagination_item_1.page_size = 1 | ||
|
|
||
| pagination_item_2 = MagicMock() | ||
| pagination_item_2.total_available = 3 | ||
| pagination_item_2.page_number = 2 | ||
| pagination_item_2.page_size = 1 | ||
|
|
||
| pagination_item_3 = MagicMock() | ||
| pagination_item_3.total_available = 3 | ||
| pagination_item_3.page_number = 3 | ||
| pagination_item_3.page_size = 1 | ||
|
|
||
| item_1 = MagicMock() | ||
| item_1.project_id = "container_id_1" | ||
| item_2 = MagicMock() | ||
| item_2.project_id = "container_id" | ||
| item_3 = MagicMock() | ||
| item_3.project_id = "container_id_2" | ||
|
|
||
| item_endpoint.get.side_effect = [ | ||
| ([item_1], pagination_item_1), | ||
| ([item_2], pagination_item_2), | ||
| ([item_3], pagination_item_3), | ||
| ] | ||
|
|
||
| result = Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| self.assertEqual(result, [item_2]) | ||
| self.assertEqual(item_endpoint.get.call_count, 3) | ||
| logger.debug.assert_called() | ||
|
|
||
| @patch("tabcmd.commands.server.TSC.RequestOptions") | ||
| @patch("tabcmd.commands.server.TSC.Filter") | ||
| def test_get_items_by_name_multiple_pages_no_container_match(self, MockFilter, MockRequestOptions): | ||
| logger = MagicMock() | ||
| item_endpoint = MagicMock() | ||
| item_name = "test_item" | ||
| container = MagicMock() | ||
| container.id = "container_id" | ||
|
|
||
| pagination_item_1 = MagicMock() | ||
| pagination_item_1.total_available = 3 | ||
| pagination_item_1.page_number = 1 | ||
| pagination_item_1.page_size = 1 | ||
|
|
||
| pagination_item_2 = MagicMock() | ||
| pagination_item_2.total_available = 3 | ||
| pagination_item_2.page_number = 2 | ||
| pagination_item_2.page_size = 1 | ||
|
|
||
| pagination_item_3 = MagicMock() | ||
| pagination_item_3.total_available = 3 | ||
| pagination_item_3.page_number = 3 | ||
| pagination_item_3.page_size = 1 | ||
|
|
||
| item_1 = MagicMock() | ||
| item_1.project_id = "different_container_id_1" | ||
| item_2 = MagicMock() | ||
| item_2.project_id = "different_container_id_2" | ||
| item_3 = MagicMock() | ||
| item_3.project_id = "different_container_id_3" | ||
|
|
||
| item_endpoint.get.side_effect = [ | ||
| ([item_1], pagination_item_1), | ||
| ([item_2], pagination_item_2), | ||
| ([item_3], pagination_item_3), | ||
| ] | ||
|
|
||
| result = Server.get_items_by_name(logger, item_endpoint, item_name, container) | ||
|
|
||
| self.assertEqual(result, []) | ||
| self.assertEqual(item_endpoint.get.call_count, 3) | ||
| logger.debug.assert_called() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.