generated from ocadotechnology/codeforlife-template-backend
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,19 +35,6 @@ def test_retrieve(self): | |
"""Can retrieve a single contributor.""" | ||
self.client.retrieve(model=self.contributor1) | ||
|
||
def test_create(self): | ||
"""Can create a contributor.""" | ||
self.client.create( | ||
data={ | ||
"id": 100, | ||
"email": "[email protected]", | ||
"name": "Test Contributor", | ||
"location": "Hatfield", | ||
"html_url": "https://github.com/contributortest", | ||
"avatar_url": "https://contributortest.github.io/", | ||
} | ||
) | ||
|
||
def test_log_into_github__no_code(self): | ||
"""Login API call does not return a code.""" | ||
self.client.get( | ||
|
@@ -118,56 +105,6 @@ def test_log_into_github__code_expired(self): | |
timeout=5, | ||
) | ||
|
||
def test_log_into_github__null_email(self): | ||
"""Users must have their email as PUBLIC on github""" | ||
response_post = requests.Response() | ||
response_post.status_code = status.HTTP_200_OK | ||
response_post.encoding = "utf-8" | ||
# pylint: disable-next=protected-access | ||
response_post._content = json.dumps( | ||
{"access_token": "123254", "token_type": "Bearer"} | ||
).encode("utf-8") | ||
|
||
response_get = requests.Response() | ||
response_get.status_code = status.HTTP_200_OK | ||
response_get.encoding = "utf-8" | ||
# pylint: disable-next=protected-access | ||
response_get._content = json.dumps({"email": ""}).encode("utf-8") | ||
|
||
with patch.object( | ||
requests, "post", return_value=response_post | ||
) as requests_post: | ||
with patch.object( | ||
requests, "get", return_value=response_get | ||
) as requests_get: | ||
self.client.get( | ||
self.reverse_action( | ||
"log_into_github", | ||
), | ||
{"code": "3e074f3e12656707cf7f"}, | ||
# pylint: disable-next=line-too-long | ||
status_code_assertion=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS, | ||
) | ||
|
||
requests_post.assert_called_once_with( | ||
url="https://github.com/login/oauth/access_token", | ||
headers={"Accept": "application/json"}, | ||
params={ | ||
"client_id": settings.GITHUB_CLIENT_ID, | ||
"client_secret": settings.GITHUB_CLIENT_SECRET, | ||
"code": "3e074f3e12656707cf7f", | ||
}, | ||
timeout=5, | ||
) | ||
requests_get.assert_called_once_with( | ||
url="https://api.github.com/user", | ||
headers={ | ||
"Accept": "application/json", | ||
"Authorization": "Bearer 123254", | ||
}, | ||
timeout=5, | ||
) | ||
|
||
def test_log_into_github__existing_contributor(self): | ||
"""User already logged-in in the past and exists as a contributor""" | ||
response_post = requests.Response() | ||
|
@@ -204,7 +141,7 @@ def test_log_into_github__existing_contributor(self): | |
"log_into_github", | ||
), | ||
{"code": "3e074f3e12656707cf7f"}, | ||
status_code_assertion=status.HTTP_200_OK, | ||
status_code_assertion=status.HTTP_201_CREATED, | ||
) | ||
|
||
requests_post.assert_called_once_with( | ||
|
@@ -285,62 +222,3 @@ def test_log_into_github__new_contributor(self): | |
}, | ||
timeout=5, | ||
) | ||
|
||
def test_log_into_github__invalid_serializer(self): | ||
"""User data retrieved from Github is not in the valid format.""" | ||
response_post = requests.Response() | ||
response_post.status_code = status.HTTP_200_OK | ||
response_post.encoding = "utf-8" | ||
# pylint: disable-next=protected-access | ||
response_post._content = json.dumps( | ||
{"access_token": "123254", "token_type": "Bearer"} | ||
).encode("utf-8") | ||
|
||
response_get = requests.Response() | ||
response_get.status_code = status.HTTP_200_OK | ||
response_get.encoding = "utf-8" | ||
# pylint: disable-next=protected-access | ||
response_get._content = json.dumps( | ||
{ | ||
"id": 999999999999999, | ||
"email": "1223533", | ||
"name": "contributor new", | ||
"location": "London", | ||
"html_url": "https://github.com/contributornew", | ||
"avatar_url": "https://contributornew.github.io/", | ||
} | ||
).encode("utf-8") | ||
|
||
with patch.object( | ||
requests, "post", return_value=response_post | ||
) as requests_post: | ||
with patch.object( | ||
requests, "get", return_value=response_get | ||
) as requests_get: | ||
self.client.get( | ||
self.reverse_action( | ||
"log_into_github", | ||
), | ||
{"code": "3e074f3e12656707cf7f"}, | ||
# pylint: disable-next=line-too-long | ||
status_code_assertion=status.HTTP_451_UNAVAILABLE_FOR_LEGAL_REASONS, | ||
) | ||
|
||
requests_post.assert_called_once_with( | ||
url="https://github.com/login/oauth/access_token", | ||
headers={"Accept": "application/json"}, | ||
params={ | ||
"client_id": settings.GITHUB_CLIENT_ID, | ||
"client_secret": settings.GITHUB_CLIENT_SECRET, | ||
"code": "3e074f3e12656707cf7f", | ||
}, | ||
timeout=5, | ||
) | ||
requests_get.assert_called_once_with( | ||
url="https://api.github.com/user", | ||
headers={ | ||
"Accept": "application/json", | ||
"Authorization": "Bearer 123254", | ||
}, | ||
timeout=5, | ||
) |