-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.96.1: Fix #1404: Handle transient errors from GitHub repo collabora…
…tors sync (#1406) ### Summary Fix for #1404. Made this as a separate PR from #1405 since I can't push up to the etsy fork. ### Related issues or links - #1404 ### Checklist Provide proof that this works (this makes reviews move faster). Please perform one or more of the following: - [x] Update/add unit or integration tests. - [x] Include a screenshot showing what the graph looked like before and after your changes. - [ ] Include console log trace showing what happened before and after your changes. **Not applicable** If you are changing a node or relationship: - [ ] Update the [schema](https://github.com/lyft/cartography/tree/master/docs/root/modules) and [readme](https://github.com/lyft/cartography/blob/master/docs/schema/README.md). **Not applicable** If you are implementing a new intel module: - [ ] Use the NodeSchema [data model](https://cartography-cncf.github.io/cartography/dev/writing-intel-modules.html#defining-a-node). --------- Signed-off-by: Daniel Brauer <[email protected]> Co-authored-by: Daniel Brauer <[email protected]>
- Loading branch information
Showing
6 changed files
with
124 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,37 @@ | ||
from unittest.mock import MagicMock | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from cartography.intel.github.repos import _get_repo_collaborators_for_multiple_repos | ||
|
||
|
||
@patch('time.sleep', return_value=None) | ||
@patch('cartography.intel.github.repos._get_repo_collaborators') | ||
@patch('cartography.intel.github.repos.backoff_handler', spec=True) | ||
def test_get_team_users_github_returns_none(mock_backoff_handler, mock_get_team_collaborators, mock_sleep): | ||
""" | ||
This test happens to use 'OUTSIDE' affiliation, but it's irrelevant for the test, it just needs either valid value. | ||
""" | ||
# Arrange | ||
repo_data = [{'name': 'repo1', 'url': 'https://github.com/repo1', 'outsideCollaborators': {'totalCount': 1}}] | ||
mock_repo_collabs = MagicMock() | ||
# Set up the condition where GitHub returns a None url and None edge as in #1334. | ||
mock_repo_collabs.nodes = [None] | ||
mock_repo_collabs.edges = [None] | ||
mock_get_team_collaborators.return_value = mock_repo_collabs | ||
|
||
# Assert we raise an exception | ||
with pytest.raises(TypeError): | ||
_get_repo_collaborators_for_multiple_repos( | ||
repo_data, | ||
'OUTSIDE', | ||
'test-org', | ||
'https://api.github.com', | ||
'test-token', | ||
) | ||
|
||
# Assert that we retry and give up | ||
assert mock_sleep.call_count == 4 | ||
assert mock_get_team_collaborators.call_count == 5 | ||
assert mock_backoff_handler.call_count == 4 |
This file contains 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