This repository has been archived by the owner on Dec 23, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
213 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
test: | ||
flake8 userprofiles --ignore=E501,E128 | ||
coverage run --branch --source=userprofiles `which django-admin.py` test --settings=test_project.settings userprofiles | ||
coverage report --show-missing --omit=userprofiles/test* | ||
coverage report --show-missing --omit=*test* |
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
Empty file.
58 changes: 58 additions & 0 deletions
58
userprofiles/contrib/accountverification/tests/test_models.py
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from datetime import timedelta | ||
from django.test import TestCase | ||
from userprofiles.contrib.accountverification.models import AccountVerification | ||
from userprofiles.settings import up_settings | ||
|
||
|
||
class ViewTests(TestCase): | ||
def setUp(self): | ||
self.data = { | ||
'username': 'newuser', | ||
'email': 'newuser@example.com', | ||
'email_repeat': 'newuser@example.com', | ||
'password': 'newuserpass', | ||
'password_repeat': 'newuserpass', | ||
'first_name': 'New', | ||
'last_name': 'User', | ||
} | ||
|
||
def test_activation(self): | ||
user = AccountVerification.objects.create_inactive_user( | ||
self.data['username'], self.data['password'], self.data['email']) | ||
user.date_joined = user.date_joined - timedelta(days=up_settings.ACCOUNT_VERIFICATION_DAYS + 1) | ||
user.save() | ||
verification = AccountVerification.objects.get(user=user) | ||
|
||
self.assertFalse( | ||
AccountVerification.objects.activate_user('wrong-pattern-format')) | ||
|
||
self.assertFalse( | ||
AccountVerification.objects.activate_user('f4a80274f851cb41ef9c20d00426d72fc4874471')) | ||
|
||
self.assertFalse( | ||
AccountVerification.objects.activate_user(verification.activation_key)) | ||
|
||
def test_delete_expired_users(self): | ||
user = AccountVerification.objects.create_inactive_user( | ||
self.data['username'], self.data['password'], self.data['email']) | ||
|
||
user.is_active = True | ||
user.save() | ||
AccountVerification.objects.delete_expired_users() | ||
|
||
user.date_joined = user.date_joined - timedelta(days=up_settings.ACCOUNT_VERIFICATION_DAYS + 1) | ||
user.save() | ||
AccountVerification.objects.delete_expired_users() | ||
self.assertTrue(AccountVerification.objects.all().exists()) | ||
|
||
user.is_active = False | ||
user.save() | ||
AccountVerification.objects.delete_expired_users() | ||
self.assertFalse(AccountVerification.objects.all().exists()) | ||
|
||
def test_unicode(self): | ||
user = AccountVerification.objects.create_inactive_user( | ||
self.data['username'], self.data['password'], self.data['email']) | ||
self.assertEqual( | ||
AccountVerification.objects.get(user=user).__unicode__(), | ||
'Account verification: %s' % user.username) |
38 changes: 38 additions & 0 deletions
38
userprofiles/contrib/accountverification/tests/test_views.py
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
from userprofiles.contrib.accountverification.models import AccountVerification | ||
from django.core import mail | ||
|
||
import re | ||
|
||
|
||
class ViewTests(TestCase): | ||
def setUp(self): | ||
self.data = { | ||
'username': 'newuser', | ||
'email': 'newuser@example.com', | ||
'email_repeat': 'newuser@example.com', | ||
'password': 'newuserpass', | ||
'password_repeat': 'newuserpass', | ||
'first_name': 'New', | ||
'last_name': 'User', | ||
} | ||
|
||
@override_settings(USE_ACCOUNT_VERIFICATION=True) | ||
def test_registration_activate(self): | ||
AccountVerification.objects.create_inactive_user( | ||
username=self.data['username'], | ||
password=self.data['password'], | ||
email=self.data['email']) | ||
mailbody = mail.outbox[0].body | ||
|
||
activation_key = re.findall( | ||
r'http://example.com/userprofiles/activate/(\w+)', mailbody, re.MULTILINE)[0] | ||
|
||
url = reverse('userprofiles_registration_activate', | ||
kwargs={'activation_key': activation_key}) | ||
response = self.client.get(url) | ||
self.assertTrue( | ||
'We activated your account. You are now able to log in. Have fun!' in | ||
response.content) |
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 |
---|---|---|
|
@@ -17,4 +17,3 @@ def get_context_data(self, **kwargs): | |
} | ||
|
||
registration_activate = RegistrationActivateView.as_view() | ||
|
Empty file.
56 changes: 56 additions & 0 deletions
56
userprofiles/contrib/emailverification/tests/test_views.py
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
from django.contrib.auth.models import User | ||
from django.test.utils import override_settings | ||
from userprofiles.contrib.emailverification.models import EmailVerification | ||
from userprofiles.settings import up_settings | ||
|
||
|
||
class ViewTests(TestCase): | ||
|
||
def setUp(self): | ||
self.data = { | ||
'username': 'newuser', | ||
'email': 'newuser@example.com', | ||
'email_repeat': 'newuser@example.com', | ||
'password': 'newuserpass', | ||
'password_repeat': 'newuserpass', | ||
'first_name': 'New', | ||
'last_name': 'User', | ||
} | ||
|
||
self.user = User.objects.create_user(self.data['username'], self.data['email'], | ||
self.data['password']) | ||
|
||
def tearDown(self): | ||
self.user.delete() | ||
|
||
@override_settings(USERPROFILES_USE_PROFILE=False, USERPROFILES_USE_ACCOUNT_VERIFICATION=True) | ||
def test_email_change(self): | ||
self.client.login(username=self.data['username'], password=self.data['password']) | ||
response = self.client.post(reverse('userprofiles_email_change'), {'new_email': 'test@example.com'}, follow=True) | ||
self.assertEqual(response.context['expiration_days'], up_settings.EMAIL_VERIFICATION_DAYS) | ||
|
||
@override_settings(USERPROFILES_USE_PROFILE=False, USERPROFILES_USE_ACCOUNT_VERIFICATION=True) | ||
def test_email_change_approve(self): | ||
verification = EmailVerification.objects.create( | ||
user=self.user, old_email=self.user.email, new_email='test@example.com') | ||
|
||
self.client.login(username=self.data['username'], password=self.data['password']) | ||
url = reverse('userprofiles_email_change_approve', | ||
kwargs={'token': verification.token, 'code': verification.code}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(User.objects.get(pk=self.user.pk).email, 'test@example.com') | ||
|
||
@override_settings(USERPROFILES_USE_PROFILE=False, USERPROFILES_USE_ACCOUNT_VERIFICATION=True) | ||
def test_email_change_approve_not_exists(self): | ||
verification = EmailVerification.objects.create( | ||
user=self.user, old_email=self.user.email, new_email='test@example.com') | ||
|
||
self.client.login(username=self.data['username'], password=self.data['password']) | ||
url = reverse('userprofiles_email_change_approve', | ||
kwargs={'token': verification.token, 'code': 'wrong-code'}) | ||
response = self.client.get(url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(User.objects.get(pk=self.user.pk).email, self.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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from django.test import TestCase | ||
from django.core.urlresolvers import reverse | ||
from django.contrib.auth.models import User | ||
from django.test.utils import override_settings | ||
from django.conf import settings | ||
from test_project.test_accounts.models import Profile | ||
|
||
|
||
@override_settings(INSTALLED_APPS=settings.INSTALLED_APPS + ['userprofiles.contrib.profiles']) | ||
class ViewTests(TestCase): | ||
def setUp(self): | ||
self.data = { | ||
'username': 'newuser', | ||
'email': 'newuser@example.com', | ||
'email_repeat': 'newuser@example.com', | ||
'password': 'newuserpass', | ||
'password_repeat': 'newuserpass', | ||
'first_name': 'New', | ||
'last_name': 'User', | ||
} | ||
user = User.objects.create_user(self.data['username'], self.data['email'], | ||
self.data['password']) | ||
Profile(user=user).save() | ||
|
||
def tearDown(self): | ||
User.objects.get(username=self.data['username']).delete() | ||
|
||
@override_settings(USERPROFILES_USE_PROFILE=True) | ||
def test_profile_view(self): | ||
self.client.login(username=self.data['username'], password=self.data['password']) | ||
url = reverse('userprofiles_profile') | ||
response = self.client.get(url) | ||
self.assertTrue('newuser' in response.content) | ||
|
||
@override_settings(USERPROFILES_USE_PROFILE=True, USERPROFILES_REGISTRATION_FULLNAME=True) | ||
def test_profile_change_fullname_enabled(self): | ||
settings.AUTH_PROFILE_MODULE = 'test_accounts.Profile' | ||
self.client.login(username=self.data['username'], password=self.data['password']) | ||
url = reverse('userprofiles_profile_change') | ||
response = self.client.get(url) | ||
self.assertTrue('first_name' in response.content and | ||
'last_name' in response.content) | ||
self.client.post(url, {'first_name': 'john', 'last_name': 'doe'}) | ||
response = self.client.get(url) | ||
self.assertTrue('john' in response.content and | ||
'doe' in response.content) | ||
|
||
@override_settings(USERPROFILES_USE_PROFILE=True, USERPROFILES_REGISTRATION_FULLNAME=False) | ||
def test_profile_change_fullname_disabled(self): | ||
settings.AUTH_PROFILE_MODULE = 'test_accounts.Profile' | ||
self.client.login(username=self.data['username'], password=self.data['password']) | ||
url = reverse('userprofiles_profile_change') | ||
response = self.client.get(url) | ||
self.assertFalse('first_name' in response.content and | ||
'last_name' in response.content) |
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