diff --git a/api/auth/backends/github.py b/api/auth/backends/github.py index 31b0758..7ab9bf8 100644 --- a/api/auth/backends/github.py +++ b/api/auth/backends/github.py @@ -2,6 +2,7 @@ © Ocado Group Created on 05/08/2024 at 12:48:13(+01:00). """ + import typing as t import requests @@ -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 diff --git a/api/auth/backends/github_test.py b/api/auth/backends/github_test.py index 2e15bf6..295c9c5 100644 --- a/api/auth/backends/github_test.py +++ b/api/auth/backends/github_test.py @@ -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 @@ -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 diff --git a/api/common/api_request_factory.py b/api/common/api_request_factory.py index 5dba247..3218771 100644 --- a/api/common/api_request_factory.py +++ b/api/common/api_request_factory.py @@ -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, @@ -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, @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" diff --git a/api/common/model_view_set_test_case.py b/api/common/model_view_set_test_case.py index 4cb4f63..2d54daa 100644 --- a/api/common/model_view_set_test_case.py +++ b/api/common/model_view_set_test_case.py @@ -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() @@ -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." diff --git a/api/serializers/agreement_signature_test.py b/api/serializers/agreement_signature_test.py index ecaf092..34f9fca 100644 --- a/api/serializers/agreement_signature_test.py +++ b/api/serializers/agreement_signature_test.py @@ -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", diff --git a/api/views/agreement_signature_test.py b/api/views/agreement_signature_test.py index a3d4a0f..eda6a68 100644 --- a/api/views/agreement_signature_test.py +++ b/api/views/agreement_signature_test.py @@ -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={ @@ -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" @@ -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") @@ -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"), diff --git a/api/views/session.py b/api/views/session.py index 40170d1..2ba2bde 100644 --- a/api/views/session.py +++ b/api/views/session.py @@ -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 @@ -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 diff --git a/api/views/session_test.py b/api/views/session_test.py index 9037c3c..835fe2d 100644 --- a/api/views/session_test.py +++ b/api/views/session_test.py @@ -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"), @@ -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"),