From 607e44e86181a760d555e9d61e4d43e514486c62 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sun, 12 Jun 2016 21:09:52 +0200 Subject: [PATCH] topics, tests --- accounts/models.py | 12 +++++++++++- accounts/tests.py | 17 ++++++++++------- proposals/forms.py | 2 +- proposals/models.py | 2 +- .../speaker_list.html} | 4 ++-- proposals/templates/proposals/talk_detail.html | 2 +- proposals/templates/proposals/talk_list.html | 6 +++--- proposals/templates/proposals/talks.html | 6 +++--- proposals/tests.py | 13 ++++++++++--- proposals/urls.py | 2 +- proposals/views.py | 6 ++++-- 11 files changed, 47 insertions(+), 25 deletions(-) rename proposals/templates/{auth/user_list.html => proposals/speaker_list.html} (62%) diff --git a/accounts/models.py b/accounts/models.py index 29c9598..804d9bc 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -3,6 +3,7 @@ from enum import IntEnum from django.contrib.auth.models import User from django.contrib.sites.managers import CurrentSiteManager from django.contrib.sites.models import Site +from django.core.urlresolvers import reverse from django.db import models __all__ = ['Profile', 'Speaker'] @@ -17,6 +18,12 @@ class Profile(models.Model): user = models.OneToOneField(User) biography = models.TextField(blank=True, verbose_name='Biography') + def __str__(self): + return self.user.get_full_name() or self.user.username + + def get_absolute_url(self): + return reverse('profile') + class Speaker(models.Model): @@ -39,7 +46,10 @@ class Speaker(models.Model): unique_together = ('site', 'user') def __str__(self): - return self.user.get_full_name() or self.user.username + return str(self.user.profile) + + def get_absolute_url(self): + return reverse('show-speaker', kwargs={'username': self.user.username}) def create_profile(sender, instance, created, **kwargs): diff --git a/accounts/tests.py b/accounts/tests.py index 526e930..6c8293f 100644 --- a/accounts/tests.py +++ b/accounts/tests.py @@ -1,8 +1,9 @@ from django.contrib.auth.models import User +from django.contrib.sites.models import Site from django.core.urlresolvers import reverse from django.test import TestCase -from .models import Profile +from .models import Profile, Speaker ROOT_URL = 'accounts' @@ -11,15 +12,17 @@ class AccountTests(TestCase): def setUp(self): for guy in 'ab': User.objects.create_user(guy, email='%s@example.org' % guy, password=guy) + Speaker.objects.create(user=User.objects.first(), site=Site.objects.first()) - # MODELS - - def test_create_profile(self): + def test_models(self): self.assertEqual(Profile.objects.count(), 2) + self.client.login(username='b', password='b') + for model in [Profile, Speaker]: + item = model.objects.first() + self.assertEqual(self.client.get(item.get_absolute_url()).status_code, 200) + self.assertTrue(str(item)) - # VIEWS - - def test_profile(self): + def test_views(self): # User b wants to update its username, email and biography user = User.objects.get(username='b') self.assertEqual(user.email, 'b@example.org') diff --git a/proposals/forms.py b/proposals/forms.py index 11801b1..07eeacd 100644 --- a/proposals/forms.py +++ b/proposals/forms.py @@ -5,4 +5,4 @@ from proposals.models import Talk __all__ = ['TalkForm'] -TalkForm = modelform_factory(Talk, fields=['title', 'description']) +TalkForm = modelform_factory(Talk, fields=['title', 'description', 'topics']) diff --git a/proposals/models.py b/proposals/models.py index cab911b..634e078 100644 --- a/proposals/models.py +++ b/proposals/models.py @@ -18,7 +18,7 @@ class Topic(models.Model): return self.name def get_absolute_url(self): - return reverse('list-talks-by-topic', kwargs={'slug': self.slug}) + return reverse('list-talks-by-topic', kwargs={'topic': self.slug}) class Talk(models.Model): diff --git a/proposals/templates/auth/user_list.html b/proposals/templates/proposals/speaker_list.html similarity index 62% rename from proposals/templates/auth/user_list.html rename to proposals/templates/proposals/speaker_list.html index 1a8cdd5..698b260 100644 --- a/proposals/templates/auth/user_list.html +++ b/proposals/templates/proposals/speaker_list.html @@ -7,8 +7,8 @@

Speakers: