1
1
# -*- coding: utf-8 -*-
2
2
from __future__ import absolute_import , unicode_literals
3
-
4
- from importlib import import_module
5
3
from requests .exceptions import HTTPError
6
-
7
- from django .conf import settings
4
+ # from django.conf import settings
8
5
from django .contrib .auth .models import User
9
- from django .core import mail
6
+ # from django.core import mail
10
7
from django .test .client import RequestFactory
11
8
from django .test import override_settings
12
9
from django .urls import reverse
13
-
14
10
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
16
12
from allauth .account .models import EmailAddress , EmailConfirmation
17
13
from allauth .account .signals import user_signed_up
18
14
from allauth .socialaccount .models import SocialAccount , SocialToken
19
15
from allauth .socialaccount .tests import OAuth2TestsMixin
20
- from allauth .tests import MockedResponse , patch
21
16
from allauth .socialaccount .providers .google .provider import GoogleProvider
22
17
from pytest_django .asserts import assertTemplateUsed
23
18
import pytest
24
-
25
19
from unittest import mock
26
20
27
21
28
22
@pytest .mark .django_db
29
23
# Using this annotation to ensure what settings defined for the tests of google sign-in features in this class
30
-
31
24
class GoogleTests (OAuth2TestsMixin ):
32
25
provider_id = GoogleProvider .id
33
26
@@ -60,7 +53,8 @@ def default_event_data_without_verified_email(family_name, name, email):
60
53
return {
61
54
"family_name" : f'{ family_name } ' ,
62
55
"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" ,
64
58
"locale" : "en-US" ,
65
59
"gender" : "male" ,
66
60
"email" : f'{ email } ' ,
@@ -119,7 +113,8 @@ def verified_mail_mocked_response(self, api_client, verified_email_event_data):
119
113
def unverified_mail_mocked_response (self , api_client , unverified_email_event_data ):
120
114
return api_client .post ('create-service' , data = unverified_email_event_data )
121
115
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
123
118
124
119
@override_settings (
125
120
SOCIALACCOUNT_AUTO_SIGNUP = True ,
@@ -141,7 +136,9 @@ def test_google_complete_login_401(self, api_client, event_data_401_code):
141
136
token = SocialToken (token = "some_token" )
142
137
# How can I connect the response to the process here without defining the mock response with
143
138
# 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:
145
142
response_with_401 = LessMockedResponse(
146
143
401,
147
144
"""
@@ -164,7 +161,7 @@ def test_google_complete_login_401(self, api_client, event_data_401_code):
164
161
response_with_401 = api_client .post ('create-service' , data = event_data_401_code )
165
162
with pytest .raises (HTTPError ):
166
163
adapter .complete_login (request , app , token )
167
- assert response .status_code == 401
164
+ assert response_with_401 .status_code == 401
168
165
169
166
def test_username_based_on_email_address (
170
167
self , email , verified_mail_mocked_response
0 commit comments