From 16f75ae262a43f4d021aebeb3ec74d63e5df6b91 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sat, 11 Jun 2016 17:28:39 +0200 Subject: [PATCH] tests --- accounts/models.py | 4 ++ accounts/tests.py | 42 ++++++++++++++++++- accounts/urls.py | 3 +- proposals/models.py | 5 ++- .../templates/proposals/speaker_list.html | 4 +- .../templates/proposals/talk_details.html | 6 +-- proposals/templates/proposals/talk_list.html | 2 +- proposals/templates/proposals/talks.html | 4 +- .../templates/proposals/user_details.html | 2 +- proposals/tests.py | 36 +++++++++++++++- proposals/views.py | 5 ++- setup.cfg | 2 +- 12 files changed, 96 insertions(+), 19 deletions(-) diff --git a/accounts/models.py b/accounts/models.py index 6d1cbf0..fd91691 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -38,6 +38,10 @@ class PonyConfSpeaker(models.Model): class Meta: unique_together = ('site', 'user') + def __str__(self): + user = self.user.user + return user.get_full_name() or user.username + def create_ponyconfuser(sender, instance, created, **kwargs): if created: diff --git a/accounts/tests.py b/accounts/tests.py index 7ce503c..62b5ec3 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -1,3 +1,43 @@ from django.test import TestCase +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse -# Create your tests here. +from .models import PonyConfSpeaker, PonyConfUser + + +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) + + # MODELS + + def test_create_ponyconfuser(self): + self.assertEqual(PonyConfUser.objects.count(), 2) + + # VIEWS + + def test_password(self): + self.client.login(username='a', password='a') + self.assertEqual(self.client.get(reverse('password')).status_code, 200) + + def test_profile(self): + # 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.ponyconfuser.biography, '') + + self.client.login(username='b', password='b') + + # He tries with an invalid address + r = self.client.post(reverse('profile'), {'email': 'bnewdomain.com', 'username': 'z', 'biography': 'tester'}) + self.assertEqual(User.objects.filter(username='z').count(), 0) + + r = self.client.post(reverse('profile'), {'email': 'b@newdomain.com', 'username': 'z', 'biography': 'tester'}) + + user = User.objects.get(username='z') + self.assertEqual(user.email, 'b@newdomain.com') + self.assertEqual(user.ponyconfuser.biography, 'tester') diff --git a/accounts/urls.py b/accounts/urls.py index 260a947..2062cfe 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -6,5 +6,6 @@ from accounts import views urlpatterns = [ url(r'^login/$', auth_views.login, {'template_name': 'accounts/login.html'}, name='login'), url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'), - url(r'^profile/$', views.profile, name='profile'), + url(r'^profile$', views.profile, name='profile'), + url(r'^password$', views.password, name='password'), ] diff --git a/proposals/models.py b/proposals/models.py index 4fc3708..e0f8cbd 100644 --- a/proposals/models.py +++ b/proposals/models.py @@ -55,4 +55,7 @@ class Speach(models.Model): ) def __str__(self): - return self.user.username + ' speaking at ' + self.talk.title + ' in position %d' % self.order + return '%s speaking at %s in position %d' % (self.user, self.talk, self.order) + + def username(self): + return self.user.user.user.username diff --git a/proposals/templates/proposals/speaker_list.html b/proposals/templates/proposals/speaker_list.html index 70c923b..1a8cdd5 100644 --- a/proposals/templates/proposals/speaker_list.html +++ b/proposals/templates/proposals/speaker_list.html @@ -8,9 +8,7 @@