-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixes #766 -- Records email verification - Send email and deactivate user if email is not confirmed - Fix #676 -- Send confirmation email when email is changed - Bump django-skivvy to 0.1.2
- Loading branch information
1 parent
4430e30
commit 0790afb
Showing
8 changed files
with
170 additions
and
12 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,6 +2,9 @@ | |
|
||
from django.utils.translation import gettext as _ | ||
from django.test import TestCase | ||
from django.core import mail | ||
from django.http import HttpRequest | ||
from django.contrib.messages.storage.fallback import FallbackStorage | ||
|
||
from ..models import User | ||
from ..forms import RegisterForm, ProfileForm | ||
|
@@ -78,17 +81,28 @@ def test_signup_with_restricted_username(self): | |
class ProfileFormTest(UserTestCase, TestCase): | ||
def test_update_user(self): | ||
user = UserFactory.create(username='imagine71', | ||
email='[email protected]') | ||
email='[email protected]', | ||
email_verified=True) | ||
data = { | ||
'username': 'imagine71', | ||
'email': 'john@beatles.uk', | ||
'email': 'john2@beatles.uk', | ||
'full_name': 'John Lennon', | ||
} | ||
form = ProfileForm(data, instance=user) | ||
|
||
request = HttpRequest() | ||
setattr(request, 'session', 'session') | ||
self.messages = FallbackStorage(request) | ||
setattr(request, '_messages', self.messages) | ||
request.META['SERVER_NAME'] = 'testserver' | ||
request.META['SERVER_PORT'] = '80' | ||
|
||
form = ProfileForm(data, request=request, instance=user) | ||
form.save() | ||
|
||
user.refresh_from_db() | ||
assert user.full_name == 'John Lennon' | ||
assert user.email_verified is False | ||
assert len(mail.outbox) == 1 | ||
|
||
def test_display_name(self): | ||
user = UserFactory.create(username='imagine71', | ||
|
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
import datetime | ||
from django.test import TestCase | ||
from django.core import mail | ||
from skivvy import ViewTestCase | ||
|
||
from accounts.tests.factories import UserFactory | ||
from core.tests.utils.cases import UserTestCase | ||
from ..views.default import AccountProfile | ||
|
||
from allauth.account.models import EmailConfirmation, EmailAddress | ||
|
||
from ..views.default import AccountProfile, AccountLogin, ConfirmEmail | ||
from ..forms import ProfileForm | ||
|
||
|
||
|
@@ -58,3 +63,72 @@ def test_update_profile_duplicate_email(self): | |
|
||
response = self.request(method='POST', user=user2, post_data=post_data) | ||
assert 'Failed to update profile information' in response.messages | ||
|
||
|
||
class LoginTest(ViewTestCase, UserTestCase, TestCase): | ||
view_class = AccountLogin | ||
|
||
def setup_models(self): | ||
self.user = UserFactory.create(username='imagine71', | ||
email='[email protected]', | ||
password='iloveyoko79') | ||
|
||
def test_successful_login(self): | ||
data = {'login': 'imagine71', 'password': 'iloveyoko79'} | ||
response = self.request(method='POST', post_data=data) | ||
assert response.status_code == 302 | ||
assert 'dashboard' in response.location | ||
|
||
def test_successful_login_with_unverified_user(self): | ||
self.user.verify_email_by = datetime.datetime.now() | ||
self.user.save() | ||
|
||
data = {'login': 'imagine71', 'password': 'iloveyoko79'} | ||
response = self.request(method='POST', post_data=data) | ||
assert response.status_code == 302 | ||
assert 'account/inactive' in response.location | ||
assert len(mail.outbox) == 1 | ||
self.user.refresh_from_db() | ||
assert self.user.is_active is False | ||
|
||
|
||
class ConfirmEmailTest(ViewTestCase, UserTestCase, TestCase): | ||
view_class = ConfirmEmail | ||
url_kwargs = {'key': '123'} | ||
|
||
def setup_models(self): | ||
self.user = UserFactory.create(email='[email protected]') | ||
self.email_address = EmailAddress.objects.create( | ||
user=self.user, | ||
email='[email protected]', | ||
verified=False, | ||
primary=True | ||
) | ||
self.confirmation = EmailConfirmation.objects.create( | ||
email_address=self.email_address, | ||
sent=datetime.datetime.now(), | ||
key='123' | ||
) | ||
|
||
def test_activate(self): | ||
response = self.request(user=self.user) | ||
assert response.status_code == 302 | ||
assert 'dashboard' in response.location | ||
|
||
self.user.refresh_from_db() | ||
assert self.user.email_verified is True | ||
assert self.user.is_active is True | ||
|
||
self.email_address.refresh_from_db() | ||
assert self.email_address.verified is True | ||
|
||
def test_activate_with_invalid_token(self): | ||
response = self.request(user=self.user, url_kwargs={'key': 'abc'}) | ||
assert response.status_code == 200 | ||
|
||
self.user.refresh_from_db() | ||
assert self.user.email_verified is False | ||
assert self.user.is_active is True | ||
|
||
self.email_address.refresh_from_db() | ||
assert self.email_address.verified is False |
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
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