Skip to content

Commit

Permalink
Black!
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 18, 2024
1 parent 3e581fd commit 33f6fc3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 79 deletions.
9 changes: 5 additions & 4 deletions api/auth/backends/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
© Ocado Group
Created on 05/08/2024 at 12:48:13(+01:00).
"""

import typing as t

import requests
Expand All @@ -17,10 +18,10 @@ class GitHubBackend(BaseBackend):
"""Authenticate a user using the code returned by github's callback url."""

def authenticate( # type: ignore[override]
self,
request: t.Optional[HttpRequest],
code: t.Optional[str] = None,
**kwargs,
self,
request: t.Optional[HttpRequest],
code: t.Optional[str] = None,
**kwargs,
):
if code is None:
return None
Expand Down
4 changes: 2 additions & 2 deletions api/auth/backends/github_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_login__invalid_code(self):
response.status_code = status.HTTP_404_NOT_FOUND

with patch.object(
requests, "post", return_value=response
requests, "post", return_value=response
) as requests_post:
contributor = self.backend.authenticate(
request=self.request, code=code
Expand All @@ -98,7 +98,7 @@ def test_login__error(self):
response._content = json.dumps({"error": ""}).encode("utf-8")

with patch.object(
requests, "post", return_value=response
requests, "post", return_value=response
) as requests_post:
contributor = self.backend.authenticate(
request=self.request, code=code
Expand Down
106 changes: 53 additions & 53 deletions api/common/api_request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def request(self, user: t.Optional[Contributor] = None, **kwargs):

# pylint: disable-next=too-many-arguments
def generic(
self,
method: str,
path: t.Optional[str] = None,
data: t.Optional[str] = None,
content_type: t.Optional[str] = None,
secure: bool = True,
user: t.Optional[Contributor] = None,
**extra
self,
method: str,
path: t.Optional[str] = None,
data: t.Optional[str] = None,
content_type: t.Optional[str] = None,
secure: bool = True,
user: t.Optional[Contributor] = None,
**extra
):
return t.cast(
Request,
Expand All @@ -65,11 +65,11 @@ def generic(
)

def get( # type: ignore[override]
self,
path: t.Optional[str] = None,
data: t.Any = None,
user: t.Optional[Contributor] = None,
**extra
self,
path: t.Optional[str] = None,
data: t.Any = None,
user: t.Optional[Contributor] = None,
**extra
):
return t.cast(
Request,
Expand All @@ -83,14 +83,14 @@ def get( # type: ignore[override]

# pylint: disable-next=too-many-arguments
def post( # type: ignore[override]
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
):
if format is None and content_type is None:
format = "json"
Expand All @@ -109,14 +109,14 @@ def post( # type: ignore[override]

# pylint: disable-next=too-many-arguments
def put( # type: ignore[override]
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
):
if format is None and content_type is None:
format = "json"
Expand All @@ -135,14 +135,14 @@ def put( # type: ignore[override]

# pylint: disable-next=too-many-arguments
def patch( # type: ignore[override]
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
):
if format is None and content_type is None:
format = "json"
Expand All @@ -161,14 +161,14 @@ def patch( # type: ignore[override]

# pylint: disable-next=too-many-arguments
def delete( # type: ignore[override]
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
self,
path: t.Optional[str] = None,
data: t.Any = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
):
if format is None and content_type is None:
format = "json"
Expand All @@ -187,14 +187,14 @@ def delete( # type: ignore[override]

# pylint: disable-next=too-many-arguments
def options( # type: ignore[override]
self,
path: t.Optional[str] = None,
data: t.Optional[t.Union[t.Dict[str, str], str]] = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
self,
path: t.Optional[str] = None,
data: t.Optional[t.Union[t.Dict[str, str], str]] = None,
# pylint: disable-next=redefined-builtin
format: t.Optional[str] = None,
content_type: t.Optional[str] = None,
user: t.Optional[Contributor] = None,
**extra
):
if format is None and content_type is None:
format = "json"
Expand Down
11 changes: 5 additions & 6 deletions api/common/model_view_set_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, enforce_csrf_checks: bool = False, **defaults):

# pylint: disable-next=arguments-differ
def login( # type: ignore[override]
self, contributor: t.Union[int, Contributor]
self, contributor: t.Union[int, Contributor]
):
# Logout current user (if any) before logging in next user.
self.logout()
Expand Down Expand Up @@ -91,13 +91,12 @@ def login( # type: ignore[override]
).encode("utf-8")

with patch.object(
requests, "post", return_value=access_token_response
requests, "post", return_value=access_token_response
) as post:
with patch.object(
requests,
"get",
side_effect=[get_contributor_response,
list_emails_response],
requests,
"get",
side_effect=[get_contributor_response, list_emails_response],
) as get:
assert APIClient.login(self, code=code), "Failed to login."

Expand Down
2 changes: 1 addition & 1 deletion api/serializers/agreement_signature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_validate_agreement_id__only_latest(self):
response._content = json.dumps([{"sha": "b"}]).encode("utf-8")

with patch.object(
requests, "get", return_value=response
requests, "get", return_value=response
) as requests_get:
self.assert_validate_field(
name="agreement_id",
Expand Down
8 changes: 4 additions & 4 deletions api/views/agreement_signature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_create(self):
self.client.login_as(contributor)

with patch.object(
requests, "get", return_value=response
requests, "get", return_value=response
) as requests_get:
self.client.create(
data={
Expand All @@ -120,7 +120,7 @@ def test_create(self):
)

def _test_check_signed_latest(
self, contributor: Contributor, is_signed: bool, reason: str = ""
self, contributor: Contributor, is_signed: bool, reason: str = ""
):
latest_commit_id = "76241fa5e96ce9a620472842fee1ddadfd13cd86"

Expand All @@ -135,7 +135,7 @@ def _test_check_signed_latest(
self.client.login_as(contributor)

with patch.object(
requests, "get", return_value=response
requests, "get", return_value=response
) as requests_get:
response = self.client.get(
self.reverse_action("check-signed-latest")
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_check_signed_latest__github_api_error(self):
self.client.login_as(self.contributor3)

with patch.object(
requests, "get", return_value=response
requests, "get", return_value=response
) as requests_get:
self.client.get(
self.reverse_action("check-signed-latest"),
Expand Down
4 changes: 3 additions & 1 deletion api/views/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
© Ocado Group
Created on 05/08/2024 at 17:23:01(+01:00).
"""

import json
import typing as t
from urllib.parse import quote_plus
Expand Down Expand Up @@ -35,7 +36,8 @@ def form_valid(self, form: GitHubLoginForm): # type: ignore

# pylint: disable-next=line-too-long
self.request.session.clear_expired(
contributor_id=contributor.pk) # type: ignore
contributor_id=contributor.pk
) # type: ignore

login(self.request, contributor) # type: ignore

Expand Down
16 changes: 8 additions & 8 deletions api/views/session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ def test_login__new_contributor(self):
).encode("utf-8")

with patch.object(
requests, "post", return_value=self.gh_access_token_response
requests, "post", return_value=self.gh_access_token_response
) as requests_post:
with patch.object(
requests,
"get",
side_effect=[response_get, list_emails_response],
requests,
"get",
side_effect=[response_get, list_emails_response],
) as requests_get:
response = self.client.post(
reverse("session-login"),
Expand Down Expand Up @@ -170,12 +170,12 @@ def test_login__existing_contributor(self):
).encode("utf-8")

with patch.object(
requests, "post", return_value=self.gh_access_token_response
requests, "post", return_value=self.gh_access_token_response
) as requests_post:
with patch.object(
requests,
"get",
side_effect=[response_get, list_emails_response],
requests,
"get",
side_effect=[response_get, list_emails_response],
) as requests_get:
response = self.client.post(
reverse("session-login"),
Expand Down

0 comments on commit 33f6fc3

Please sign in to comment.