From e4f413adcc17d44adb5caa5792ea6aa77c7c94ac Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 13 Jun 2016 02:00:30 +0200 Subject: [PATCH] conversations quick tests --- accounts/signals.py | 2 +- accounts/urls.py | 2 +- conversations/admin.py | 1 - conversations/models.py | 6 ++++- conversations/signals.py | 9 ++++--- .../templates/conversations/message.html | 13 ++++++++++ conversations/tests.py | 24 ++++++++++++++++++- conversations/urls.py | 1 - conversations/utils.py | 4 ++-- conversations/views.py | 4 ++-- ponyconf/settings.py | 1 + proposals/tests.py | 3 ++- setup.cfg | 2 +- 13 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 conversations/templates/conversations/message.html diff --git a/accounts/signals.py b/accounts/signals.py index 05f1b67..5001fd2 100644 --- a/accounts/signals.py +++ b/accounts/signals.py @@ -1,6 +1,6 @@ +from django.contrib import messages from django.contrib.auth.signals import user_logged_in, user_logged_out from django.dispatch import receiver -from django.contrib import messages @receiver(user_logged_in) diff --git a/accounts/urls.py b/accounts/urls.py index 86f7beb..f276a46 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -1,8 +1,8 @@ +from django.conf import settings from django.conf.urls import include, url from django.contrib.auth import views as auth_views from .views import profile -from django.conf import settings urlpatterns = [ url(r'^profile$', profile, name='profile'), diff --git a/conversations/admin.py b/conversations/admin.py index d12718a..46913f3 100644 --- a/conversations/admin.py +++ b/conversations/admin.py @@ -2,6 +2,5 @@ from django.contrib import admin from .models import Conversation, Message - admin.site.register(Conversation) admin.site.register(Message) diff --git a/conversations/models.py b/conversations/models.py index 1ee2f04..c0ea7e9 100644 --- a/conversations/models.py +++ b/conversations/models.py @@ -1,5 +1,6 @@ -from django.db import models from django.contrib.auth.models import User +from django.core.urlresolvers import reverse +from django.db import models from accounts.models import Speaker @@ -12,6 +13,9 @@ class Conversation(models.Model): def __str__(self): return "Conversation with %s" % self.speaker + def get_absolute_url(self): + return reverse('show-conversation', kwargs={'conversation': self.pk}) + class Message(models.Model): diff --git a/conversations/signals.py b/conversations/signals.py index 724b096..6522fb0 100644 --- a/conversations/signals.py +++ b/conversations/signals.py @@ -1,11 +1,10 @@ -from django.db.models.signals import post_save -from django.dispatch import receiver from django.conf import settings -from django.core.urlresolvers import reverse -from django.template.loader import render_to_string from django.core import mail from django.core.mail import EmailMultiAlternatives - +from django.core.urlresolvers import reverse +from django.db.models.signals import post_save +from django.dispatch import receiver +from django.template.loader import render_to_string from .models import Message from .utils import get_reply_addr diff --git a/conversations/templates/conversations/message.html b/conversations/templates/conversations/message.html new file mode 100644 index 0000000..fe3ba20 --- /dev/null +++ b/conversations/templates/conversations/message.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} + +{% block content %} + +
{{ conversation }}
+ +{# for message in conversation.messages %} +

{{ message }}

+{% endfor #} + + + +{% endblock %} diff --git a/conversations/tests.py b/conversations/tests.py index 4972db2..d76175b 100644 --- a/conversations/tests.py +++ b/conversations/tests.py @@ -1,5 +1,27 @@ +from django.contrib.auth.models import User +from django.contrib.sites.models import Site from django.test import TestCase +from accounts.models import Speaker + +from .models import Conversation, Message +from .utils import get_reply_addr + class ConversationTests(TestCase): - pass + def setUp(self): + a, b = (User.objects.create_user(guy, email='%s@example.org' % guy, password=guy) for guy in 'ab') + speaker = Speaker.objects.create(user=a, site=Site.objects.first()) + conversation = Conversation.objects.create(speaker=speaker) + Message.objects.create(token='pipo', conversation=conversation, author=a, content='allo') + + def test_models(self): + self.assertEqual(str(Conversation.objects.first()), 'Conversation with a') + self.assertEqual(str(Message.objects.first()), 'Message from a') + + def test_views(self): + self.assertEqual(self.client.get(Conversation.objects.first().get_absolute_url()).status_code, 200) + + def test_utils(self): + ret = ['pipo+ 11183704aabfddb3d694ff4f24c0daadfa2d8d2193336e345f92a6fd3ffb6a19e7@example.org'] + self.assertEqual(get_reply_addr(1, User.objects.first()), ret) diff --git a/conversations/urls.py b/conversations/urls.py index a6ca3d3..89999ba 100644 --- a/conversations/urls.py +++ b/conversations/urls.py @@ -2,7 +2,6 @@ from django.conf.urls import url from conversations import views - urlpatterns = [ url(r'^(?P[0-9]+)$', views.conversation_details, name='show-conversation'), ] diff --git a/conversations/utils.py b/conversations/utils.py index e00ba87..10afbb1 100644 --- a/conversations/utils.py +++ b/conversations/utils.py @@ -1,7 +1,7 @@ -from django.conf import settings - import hashlib +from django.conf import settings + def hexdigest_sha256(*args): diff --git a/conversations/views.py b/conversations/views.py index c76f632..ac35d6f 100644 --- a/conversations/views.py +++ b/conversations/views.py @@ -1,5 +1,5 @@ -from django.shortcuts import get_object_or_404, render from django.contrib.sites.shortcuts import get_current_site +from django.shortcuts import get_object_or_404, render from .models import Conversation @@ -7,5 +7,5 @@ from .models import Conversation def conversation_details(request, conversation): conversation = get_object_or_404(Conversation, id=conversation, speaker__site=get_current_site(request)) return render(request, 'conversations/message.html', { - 'messages': conversation.messages, + 'conversation': conversation, }) diff --git a/ponyconf/settings.py b/ponyconf/settings.py index 9a8b33c..17cd7ab 100644 --- a/ponyconf/settings.py +++ b/ponyconf/settings.py @@ -178,3 +178,4 @@ BOOTSTRAP3 = { AUTHENTICATION_BACKENDS = ['yeouia.backends.YummyEmailOrUsernameInsensitiveAuth'] LOGOUT_REDIRECT_URL = 'home' +REPLY_EMAIL = 'pipo@example.org' diff --git a/proposals/tests.py b/proposals/tests.py index 3af5e6d..bcc5e12 100644 --- a/proposals/tests.py +++ b/proposals/tests.py @@ -2,7 +2,7 @@ from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test import TestCase -from .models import Talk, Topic, Speech +from .models import Speech, Talk, Topic class ProposalsTests(TestCase): @@ -40,3 +40,4 @@ class ProposalsTests(TestCase): item = model.objects.first() self.assertEqual(self.client.get(item.get_absolute_url()).status_code, 200) self.assertTrue(str(item)) + self.assertEqual(Speech.objects.first().username(), 'a') diff --git a/setup.cfg b/setup.cfg index b7110f4..ac5299e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [coverage:run] -source = accounts, ponyconf, proposals +source = accounts, ponyconf, proposals, conversations omit = */migrations/*, */apps.py, ponyconf/wsgi.py [flake8]