-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate namespace by checking cloud platform repo (#1453)
* Validate namespace by checking cloud platform repo * Fixed formatting errors * Fixed tests * Refactored code to check both dev and prod exist before creating app * Fixed not being able to add capitalised username in restricted tool release * Made error message more relevant * Ran black * Added tests for githubapi * Ran black * Ran isort
- Loading branch information
1 parent
7969407
commit 635c46e
Showing
5 changed files
with
117 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Standard library | ||
from unittest.mock import Mock, patch | ||
|
||
# Third-party | ||
import pytest | ||
|
||
# First-party/Local | ||
from controlpanel.api.github import GithubAPI, RepositoryNotFound | ||
|
||
|
||
@pytest.fixture() | ||
def requests(): | ||
""" | ||
Mock calls to requests | ||
""" | ||
with patch("controlpanel.api.github.requests") as requests: | ||
yield requests | ||
|
||
|
||
@pytest.fixture() | ||
def request_get_success(requests): | ||
""" | ||
Mock calls to requests | ||
""" | ||
response = Mock() | ||
response.status_code = 200 | ||
response.json.return_value = {"repo": "test-repo-name"} | ||
requests.get.return_value = response | ||
|
||
yield requests | ||
|
||
|
||
@pytest.fixture() | ||
def request_get_not_found(requests): | ||
""" | ||
Mock calls to requests | ||
""" | ||
response = Mock() | ||
response.status_code = 404 | ||
requests.get.return_value = response | ||
|
||
yield requests | ||
|
||
|
||
def test_get_repository_success(request_get_success): | ||
|
||
test_api_token = "abc123" | ||
response = GithubAPI(test_api_token).get_repository("test-repo-name") | ||
|
||
assert response["repo"] == "test-repo-name" | ||
|
||
|
||
def test_get_repository_not_found(request_get_not_found): | ||
|
||
with pytest.raises( | ||
RepositoryNotFound, match="Repository 'test-repo-name' not found, it may be private" | ||
): | ||
test_api_token = "abc123" | ||
GithubAPI(test_api_token).get_repository("test-repo-name") | ||
|
||
|
||
def test_get_repository_contents_success(request_get_success): | ||
|
||
test_api_token = "abc123" | ||
response = GithubAPI(test_api_token).get_repository_contents( | ||
"test-repo-name", "some/resource/path" | ||
) | ||
|
||
assert response["repo"] == "test-repo-name" | ||
|
||
|
||
def test_get_repository_contents_not_found(request_get_not_found): | ||
|
||
with pytest.raises( | ||
RepositoryNotFound, | ||
match="Repository path 'some/resource/path' in test-repo-name not found. It may not exist", | ||
): | ||
test_api_token = "abc123" | ||
GithubAPI(test_api_token).get_repository_contents("test-repo-name", "some/resource/path") |
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