-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:kobotoolbox/kpi
- Loading branch information
Showing
3 changed files
with
34 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,44 +2,43 @@ | |
from constance.test import override_config | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase, override_settings, Client | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
from django.utils import translation | ||
from django.utils.timezone import now | ||
from hub.models.sitewide_message import SitewideMessage | ||
from model_bakery import baker | ||
from pyquery import PyQuery | ||
from rest_framework import status | ||
|
||
from hub.models.sitewide_message import SitewideMessage | ||
from kobo.apps.accounts.forms import SignupForm, SocialSignupForm | ||
from kpi.utils.json import LazyJSONSerializable | ||
|
||
|
||
class AccountFormsTestCase(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = baker.make(settings.AUTH_USER_MODEL) | ||
cls.sociallogin = baker.make( | ||
"socialaccount.SocialAccount", user=cls.user | ||
) | ||
cls.user = baker.make(settings.AUTH_USER_MODEL, email='[email protected]') | ||
cls.sociallogin = baker.make('socialaccount.SocialAccount', user=cls.user) | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
self.url = reverse('account_signup') | ||
|
||
@override_settings(UNSAFE_SSO_REGISTRATION_EMAIL_DISABLE=True) | ||
def test_social_signup_form_not_email_disabled(self): | ||
form = SocialSignupForm(sociallogin=self.sociallogin) | ||
pq = PyQuery(str(form)) | ||
assert (email_input := pq("[name=email]")) | ||
assert "readonly" in email_input[0].attrib | ||
|
||
@override_settings(UNSAFE_SSO_REGISTRATION_EMAIL_DISABLE=False) | ||
def test_social_signup_form_not_email_not_disabled(self): | ||
def test_social_signup_form_email_disabled(self): | ||
form = SocialSignupForm(sociallogin=self.sociallogin) | ||
pq = PyQuery(str(form)) | ||
assert (email_input := pq("[name=email]")) | ||
assert "readonly" not in email_input[0].attrib | ||
assert (email_input := pq('[name=email]')) | ||
assert 'readonly' in email_input[0].attrib | ||
|
||
def test_social_signup_email_must_match(self): | ||
# replace [email protected] with [email protected] | ||
bad_email = self.user.email.replace('@', '+bad@') | ||
form = SocialSignupForm( | ||
sociallogin=self.sociallogin, | ||
data={'email': bad_email, 'name': 'name', 'username': 'uname'}, | ||
) | ||
self.assertEquals(form.errors['email'], ['Email must match SSO server email']) | ||
|
||
def test_only_configurable_fields_can_be_removed(self): | ||
with override_config(USER_METADATA_FIELDS='{}'): | ||
|
@@ -300,7 +299,7 @@ def _organization_field_skip_logic(self, form_type, **kwargs): | |
""" | ||
basic_data = { | ||
'username': 'foo', | ||
'email': '[email protected]', | ||
'email': kwargs.get('email', '[email protected]'), | ||
'password1': 'tooxox', | ||
'password2': 'tooxox', | ||
} | ||
|
@@ -320,6 +319,7 @@ def _organization_field_skip_logic(self, form_type, **kwargs): | |
data = basic_data.copy() | ||
data['organization_type'] = 'government' | ||
form = form_type(data, **kwargs.get('form_kwargs', {})) | ||
|
||
# No other organization fields should be required | ||
assert form.is_valid() | ||
|
||
|
@@ -419,5 +419,7 @@ def test_organization_field_skip_logic_signup_form(self): | |
|
||
def test_organization_field_skip_logic_sso_form(self): | ||
self._organization_field_skip_logic( | ||
SocialSignupForm, form_kwargs={'sociallogin': self.sociallogin} | ||
SocialSignupForm, | ||
form_kwargs={'sociallogin': self.sociallogin}, | ||
email=self.sociallogin.user.email, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters