Skip to content

Commit 53d4e73

Browse files
committed
Fixing user_views_tests
- Added DB annottion of pytest due to a conflit occurs after adding the sign in with google feature
1 parent c651be3 commit 53d4e73

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

users/tests/test_allauth.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import, unicode_literals
3-
4-
from importlib import import_module
53
from requests.exceptions import HTTPError
6-
7-
from django.conf import settings
4+
# from django.conf import settings
85
from django.contrib.auth.models import User
9-
from django.core import mail
6+
# from django.core import mail
107
from django.test.client import RequestFactory
118
from django.test import override_settings
129
from django.urls import reverse
13-
1410
from allauth.account import app_settings as account_settings
15-
from allauth.account.adapter import get_adapter
11+
# from allauth.account.adapter import get_adapter
1612
from allauth.account.models import EmailAddress, EmailConfirmation
1713
from allauth.account.signals import user_signed_up
1814
from allauth.socialaccount.models import SocialAccount, SocialToken
1915
from allauth.socialaccount.tests import OAuth2TestsMixin
20-
from allauth.tests import MockedResponse, patch
2116
from allauth.socialaccount.providers.google.provider import GoogleProvider
2217
from pytest_django.asserts import assertTemplateUsed
2318
import pytest
24-
2519
from unittest import mock
2620

2721

2822
@pytest.mark.django_db
2923
# Using this annotation to ensure what settings defined for the tests of google sign-in features in this class
30-
3124
class GoogleTests(OAuth2TestsMixin):
3225
provider_id = GoogleProvider.id
3326

@@ -60,7 +53,8 @@ def default_event_data_without_verified_email(family_name, name, email):
6053
return {
6154
"family_name": f'{family_name}',
6255
"name": f'{name}',
63-
"picture": "https://lh3.googleusercontent.com/a-/AOh14GhRHk2sL-xgCAYTscap9ByHf_16PYyebVwRkI6l1g=s96-c-rg-br100",
56+
"picture": "https://lh3.googleusercontent.com/a-/A"
57+
"Oh14GhRHk2sL-xgCAYTscap9ByHf_16PYyebVwRkI6l1g=s96-c-rg-br100",
6458
"locale": "en-US",
6559
"gender": "male",
6660
"email": f'{email}',
@@ -119,7 +113,8 @@ def verified_mail_mocked_response(self, api_client, verified_email_event_data):
119113
def unverified_mail_mocked_response(self, api_client, unverified_email_event_data):
120114
return api_client.post('create-service', data=unverified_email_event_data)
121115

122-
# Imitating a response returned by google API by fabricating data partially and returning a json format string
116+
# Imitating a response returned by google API by
117+
# fabricating data partially and returning a json format string
123118

124119
@override_settings(
125120
SOCIALACCOUNT_AUTO_SIGNUP=True,
@@ -141,7 +136,9 @@ def test_google_complete_login_401(self, api_client, event_data_401_code):
141136
token = SocialToken(token="some_token")
142137
# How can I connect the response to the process here without defining the mock response with
143138
# patch and then assigning it as appeared here:
144-
'''LessMockedResponse was a class that inherites from MockedResponse class and overriding/adding a raise_for_status method that raises HTTPError when the status code is NOT 200
139+
'''LessMockedResponse was a class that inherites from MockedResponse
140+
class and overriding/adding a raise_for_status method that raises HTTPError
141+
when the status code is NOT 200-> here below:
145142
response_with_401 = LessMockedResponse(
146143
401,
147144
"""
@@ -164,7 +161,7 @@ def test_google_complete_login_401(self, api_client, event_data_401_code):
164161
response_with_401 = api_client.post('create-service', data=event_data_401_code)
165162
with pytest.raises(HTTPError):
166163
adapter.complete_login(request, app, token)
167-
assert response.status_code == 401
164+
assert response_with_401.status_code == 401
168165

169166
def test_username_based_on_email_address(
170167
self, email, verified_mail_mocked_response

users/tests/test_users_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ def test_profile_anonymous_GET(self, client):
2727
response = client.get(reverse('profile'))
2828
assert response.status_code == 302
2929

30+
@pytest.mark.django_db
3031
def test_login_GET(self, client):
3132
response = client.get(reverse('login'))
3233
assert response.status_code == 200
3334
assertTemplateUsed(response, 'users/login.html')
3435

36+
@pytest.mark.django_db
3537
def test_logout_GET(self, client):
3638
response = client.get(reverse('logout'))
3739
assert response.status_code == 200

0 commit comments

Comments
 (0)