PonyConf/accounts/tests.py

43 lines
1.6 KiB
Python
Raw Normal View History

2016-06-11 15:28:39 +00:00
from django.contrib.auth.models import User
2016-06-12 19:09:52 +00:00
from django.contrib.sites.models import Site
2016-06-11 15:28:39 +00:00
from django.core.urlresolvers import reverse
from django.test import TestCase
2016-06-07 20:59:13 +00:00
2016-06-14 19:39:04 +00:00
from .models import Profile, Participation
2016-06-11 15:28:39 +00:00
ROOT_URL = 'accounts'
class AccountTests(TestCase):
def setUp(self):
for guy in 'ab':
User.objects.create_user(guy, email='%s@example.org' % guy, password=guy)
2016-06-14 19:39:04 +00:00
Participation.objects.create(user=User.objects.first(), site=Site.objects.first())
2016-06-11 15:28:39 +00:00
2016-06-12 19:09:52 +00:00
def test_models(self):
self.assertEqual(Profile.objects.count(), 2)
2016-06-12 19:09:52 +00:00
self.client.login(username='b', password='b')
2016-06-14 19:39:04 +00:00
for model in [Profile, Participation]:
2016-06-12 19:09:52 +00:00
item = model.objects.first()
self.assertEqual(self.client.get(item.get_absolute_url()).status_code, 200)
self.assertTrue(str(item))
2016-06-11 15:28:39 +00:00
2016-06-12 19:09:52 +00:00
def test_views(self):
2016-06-11 15:28:39 +00:00
# User b wants to update its username, email and biography
user = User.objects.get(username='b')
self.assertEqual(user.email, 'b@example.org')
self.assertEqual(user.profile.biography, '')
2016-06-11 15:28:39 +00:00
self.client.login(username='b', password='b')
# He tries with an invalid address
self.client.post(reverse('profile'), {'email': 'bnewdomain.com', 'username': 'z', 'biography': 'tester'})
2016-06-11 15:28:39 +00:00
self.assertEqual(User.objects.filter(username='z').count(), 0)
self.client.post(reverse('profile'), {'email': 'b@newdomain.com', 'username': 'z', 'biography': 'tester'})
2016-06-11 15:28:39 +00:00
user = User.objects.get(username='z')
self.assertEqual(user.email, 'b@newdomain.com')
self.assertEqual(user.profile.biography, 'tester')
2016-06-12 20:19:01 +00:00
self.client.logout()