-
Notifications
You must be signed in to change notification settings - Fork 429
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
fix: Solve API GitHub integration issues #4502
Changes from 4 commits
aa91e1c
5fb7d30
e4acf8b
1357116
e57a7c4
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -547,6 +547,7 @@ def test_fetch_issues( | |||||||||||
) | ||||||||||||
|
||||||||||||
|
||||||||||||
@responses.activate | ||||||||||||
def test_fetch_issues_returns_error_on_bad_response_from_github( | ||||||||||||
admin_client_new: APIClient, | ||||||||||||
organisation: Organisation, | ||||||||||||
|
@@ -556,17 +557,62 @@ def test_fetch_issues_returns_error_on_bad_response_from_github( | |||||||||||
mocker: MockerFixture, | ||||||||||||
) -> None: | ||||||||||||
# Given | ||||||||||||
mocker.patch("requests.get", side_effect=mocked_requests_get_error) | ||||||||||||
|
||||||||||||
mock_response = { | ||||||||||||
"message": "Validation Failed", | ||||||||||||
"errors": [{"message": "Error", "code": "not_found"}], | ||||||||||||
"documentation_url": "https://docs.github.com/v3/search/", | ||||||||||||
"status": "404", | ||||||||||||
} | ||||||||||||
|
||||||||||||
responses.add( | ||||||||||||
method="GET", | ||||||||||||
url="https://api.github.com/search/issues?q=%20repo:repo/repo%20is:issue%20is:open%20in:title%20in:body&per_page=100&page=1", # noqa: E501 | ||||||||||||
status=status.HTTP_404_NOT_FOUND, | ||||||||||||
json=mock_response, | ||||||||||||
) | ||||||||||||
url = reverse("api-v1:organisations:get-github-issues", args=[organisation.id]) | ||||||||||||
data = {"repo_owner": "owner", "repo_name": "repo"} | ||||||||||||
# When | ||||||||||||
response = admin_client_new.get(url, data=data) | ||||||||||||
|
||||||||||||
# Then | ||||||||||||
assert response.status_code == status.HTTP_502_BAD_GATEWAY | ||||||||||||
assert "Failed to retrieve GitHub issues." in response.json()["detail"] | ||||||||||||
|
||||||||||||
|
||||||||||||
@responses.activate | ||||||||||||
def test_search_issues_returns_error_on_bad_search_params( | ||||||||||||
admin_client_new: APIClient, | ||||||||||||
organisation: Organisation, | ||||||||||||
github_configuration: GithubConfiguration, | ||||||||||||
github_repository: GithubRepository, | ||||||||||||
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. Nit:
Suggested change
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. I can't change this because it is the model's name.
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. Ok I guess it's too much work to change the name of the model? 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. I decided to rename the model, thanks for the suggestion. I will merge this PR afterward. |
||||||||||||
mock_github_client_generate_token: MagicMock, | ||||||||||||
mocker: MockerFixture, | ||||||||||||
) -> None: | ||||||||||||
# Given | ||||||||||||
mock_response = { | ||||||||||||
"message": "Validation Failed", | ||||||||||||
"errors": [{"message": "Error", "code": "invalid"}], | ||||||||||||
"documentation_url": "https://docs.github.com/v3/search/", | ||||||||||||
"status": "422", | ||||||||||||
} | ||||||||||||
responses.add( | ||||||||||||
method="GET", | ||||||||||||
url="https://api.github.com/search/issues?q=%20repo:owner/repo%20is:issue%20is:open%20in:title%20in:body&per_page=100&page=1", # noqa: E501 | ||||||||||||
status=status.HTTP_422_UNPROCESSABLE_ENTITY, | ||||||||||||
json=mock_response, | ||||||||||||
) | ||||||||||||
url = reverse("api-v1:organisations:get-github-issues", args=[organisation.id]) | ||||||||||||
data = {"repo_owner": "owner", "repo_name": "repo"} | ||||||||||||
# When | ||||||||||||
response = admin_client_new.get(url, data=data) | ||||||||||||
|
||||||||||||
# Then | ||||||||||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||||||||||
response_json = response.json() | ||||||||||||
assert ( | ||||||||||||
"Failed to retrieve GitHub issues. Error: HTTP Error 404" | ||||||||||||
"Failed to retrieve GitHub issues. Error: The resources do not exist or you do not have permission to view them" | ||||||||||||
in response_json["detail"] | ||||||||||||
) | ||||||||||||
|
||||||||||||
|
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.
Maybe to future proof this it could be helpful to add an
else
keyword and raise an exception.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.
I don't think it's necessary to implement this, because I am already validating it before creating the feature external resource here:
flagsmith/api/features/feature_external_resources/views.py
Line 79 in 1357116