Skip to content

Commit

Permalink
Ignore type error
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmanAsh committed Aug 8, 2024
1 parent 874d3d0 commit 48ba003
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions api/forms/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ def get_invalid_login_error_message(self):
return "The code returned was invalid or expired."

def clean(self):
"""Authenticates a contributor.
Raises:
ValidationError: If there are form errors.
ValidationError: If the contributor's credentials were incorrect.
ValidationError: If the contributor's instance is incorrect.
Returns:
The cleaned form data.
"""
if self.errors:
raise ValidationError(
"Found form errors. Skipping authentication.",
Expand Down
5 changes: 3 additions & 2 deletions api/views/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ def get_form_kwargs(self):
def form_valid(self, form: GitHubLoginForm): # type: ignore
contributor = form.contributor

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

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

self.request.session.save()

Expand Down
12 changes: 10 additions & 2 deletions api/views/session_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ def setUp(self):
self.client = APIClient()

def test_login__invalid_code(self):
"""Login a user as an existing github user."""
"""Provided code must be valid and not expired."""
self.client.post(
reverse("session-login"),
data={"code": "7f06468085765cdc1578"},
format="json",
)

def test_login(self):
def test_login__form_errors(self):
"""Login a user as an existing github user."""
self.client.post(
reverse("session-login"),
data={"code": ""},
format="json",
)

def test_login(self):
"""User can login with their existing github account."""
code = "7f06468085765cdc1578"

response_post = requests.Response()
Expand Down

0 comments on commit 48ba003

Please sign in to comment.