From 2dce52cb25a4d09f274bf22b0cf141618712eaa3 Mon Sep 17 00:00:00 2001 From: Jens Kleineheismann Date: Thu, 14 Mar 2019 15:36:09 +0100 Subject: [PATCH] UPD: more test. --- dav_auth/emails.py | 4 +- dav_auth/tests/test_apps.py | 19 ++++---- dav_auth/tests/test_emails.py | 2 +- dav_auth/tests/test_views.py | 4 +- dav_base/tests/generic.py | 28 ++++++++++++ dav_base/tests/test_apps.py | 21 ++++----- dav_events/tests/__init__.py | 0 dav_events/tests/test_apps.py | 27 +++++++++++ dav_events/tests/test_emails.py | 80 +++++++++++++++++++++++++++++++++ dav_events/tests/test_urls.py | 14 ++++++ 10 files changed, 171 insertions(+), 28 deletions(-) create mode 100644 dav_events/tests/__init__.py create mode 100644 dav_events/tests/test_apps.py create mode 100644 dav_events/tests/test_emails.py create mode 100644 dav_events/tests/test_urls.py diff --git a/dav_auth/emails.py b/dav_auth/emails.py index 8448725..3ea4ad5 100644 --- a/dav_auth/emails.py +++ b/dav_auth/emails.py @@ -11,8 +11,8 @@ class PasswordSetEmail(AbstractMail): self._password = password def _get_recipients(self): - r = u'{fullname} <{email}>'.format(fullname=self._user.get_full_name(), - email=self._user.email) + r = u'"{fullname}" <{email}>'.format(fullname=self._user.get_full_name(), + email=self._user.email) return [r] def _get_context_data(self, extra_context=None): diff --git a/dav_auth/tests/test_apps.py b/dav_auth/tests/test_apps.py index 3fcdda2..533c63a 100644 --- a/dav_auth/tests/test_apps.py +++ b/dav_auth/tests/test_apps.py @@ -1,15 +1,12 @@ from django.apps import apps -from django.test import SimpleTestCase + +from dav_base.tests.generic import AppSetting, AppsTestCase -class AppsTestCase(SimpleTestCase): - def setUp(self): - app_config = apps.get_containing_app_config(__package__) - self.settings = app_config.settings +class TestCase(AppsTestCase): + app_config = apps.get_app_config('dav_auth') - def test_settings(self): - setting_names = ('login_redirect_url', - 'logout_redirect_url') - - for s in setting_names: - self.assertTrue(hasattr(self.settings, s), 'Settings do not contain {}'.format(s)) + settings = ( + AppSetting('login_redirect_url', basestring), + AppSetting('logout_redirect_url', basestring), + ) diff --git a/dav_auth/tests/test_emails.py b/dav_auth/tests/test_emails.py index 7432f05..d343f2a 100644 --- a/dav_auth/tests/test_emails.py +++ b/dav_auth/tests/test_emails.py @@ -24,7 +24,7 @@ class EmailsTestCase(TestCase): self.assertEqual(len(django_mail.outbox), 1) mail = django_mail.outbox[0] - recipient = '%s <%s>' % (self.user.get_full_name(), self.user.email) + recipient = u'"%s" <%s>' % (self.user.get_full_name(), self.user.email) recipients = mail.recipients() self.assertIn(recipient, recipients) self.assertEqual(len(recipients), 1) diff --git a/dav_auth/tests/test_views.py b/dav_auth/tests/test_views.py index 468fa26..1a0594a 100644 --- a/dav_auth/tests/test_views.py +++ b/dav_auth/tests/test_views.py @@ -166,7 +166,7 @@ class ViewsTestCase(TestCase): 'send_password_mail': True}) self.assertEqual(len(django_mail.outbox), 1) mail = django_mail.outbox[0] - recipient = '%s <%s>' % (self.user.get_full_name(), self.user.email) + recipient = u'"%s" <%s>' % (self.user.get_full_name(), self.user.email) recipients = mail.recipients() self.assertIn(recipient, recipients) self.assertEqual(len(recipients), 1) @@ -202,7 +202,7 @@ class ViewsTestCase(TestCase): self.assertEqual(len(django_mail.outbox), 1) mail = django_mail.outbox[0] - recipient = '%s <%s>' % (self.user.get_full_name(), self.user.email) + recipient = u'"%s" <%s>' % (self.user.get_full_name(), self.user.email) recipients = mail.recipients() self.assertIn(recipient, recipients) self.assertEqual(len(recipients), 1) diff --git a/dav_base/tests/generic.py b/dav_base/tests/generic.py index 2558eb9..6b767d4 100644 --- a/dav_base/tests/generic.py +++ b/dav_base/tests/generic.py @@ -18,6 +18,34 @@ def skip_unless_tag_option(): return skip('Skipped unless --tag option is used') +class AppSetting(object): + def __init__(self, name, of=None): + self.name = name + self.of = of + + +class AppsTestCase(SimpleTestCase): + app_config = None + settings = () + + def setUp(self): + super(AppsTestCase, self).setUp() + if self.app_config: + self.configured_settings = self.app_config.settings + else: + self.configured_settings = None + + def test_settings(self): + config = self.configured_settings + for setting in self.settings: + name = setting.name + self.assertTrue(hasattr(config, name), 'Settings do not contain {}'.format(name)) + value = getattr(config, name) + of = setting.of + if of is not None: + self.assertIsInstance(value, of) + + class Url(object): def __init__(self, location, name=None, func=None, **kwargs): self.location = location diff --git a/dav_base/tests/test_apps.py b/dav_base/tests/test_apps.py index 740b3f7..589b3a2 100644 --- a/dav_base/tests/test_apps.py +++ b/dav_base/tests/test_apps.py @@ -1,16 +1,13 @@ from django.apps import apps -from django.test import SimpleTestCase + +from .generic import AppSetting, AppsTestCase -class AppsTestCase(SimpleTestCase): - def setUp(self): - app_config = apps.get_containing_app_config(__package__) - self.settings = app_config.settings +class TestCase(AppsTestCase): + app_config = apps.get_app_config('dav_base') - def test_settings(self): - setting_names = ('email_sender', - 'email_base_url', - 'email_subject_prefix') - - for s in setting_names: - self.assertTrue(hasattr(self.settings, s), 'Settings do not contain {}'.format(s)) + settings = ( + AppSetting('email_sender', basestring), + AppSetting('email_base_url', basestring), + AppSetting('email_subject_prefix', basestring), + ) diff --git a/dav_events/tests/__init__.py b/dav_events/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dav_events/tests/test_apps.py b/dav_events/tests/test_apps.py new file mode 100644 index 0000000..80180f5 --- /dev/null +++ b/dav_events/tests/test_apps.py @@ -0,0 +1,27 @@ +from django.apps import apps + +from dav_base.tests.generic import AppSetting, AppsTestCase + + +class TestCase(AppsTestCase): + app_config = apps.get_app_config('dav_events') + + settings = ( + AppSetting('enable_email_on_status_update', bool), + AppSetting('enable_email_on_update', bool), + AppSetting('groups_manager_super', list), + AppSetting('groups_manager_w', list), + AppSetting('groups_manager_s', list), + AppSetting('groups_manager_m', list), + AppSetting('groups_manager_k', list), + AppSetting('groups_manager_b', list), + AppSetting('groups_publisher_print', list), + AppSetting('groups_publisher_web', list), + AppSetting('groups_publisher_facebook', list), + AppSetting('forms_development_init', bool), + AppSetting('form_initials', dict), + AppSetting('matrix_config', dict), + AppSetting('publish_before_begin_days', int), + AppSetting('publish_before_deadline_days', int), + AppSetting('publish_issues', list), + ) diff --git a/dav_events/tests/test_emails.py b/dav_events/tests/test_emails.py new file mode 100644 index 0000000..d4496cd --- /dev/null +++ b/dav_events/tests/test_emails.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- +from django.contrib.auth import get_user_model +from django.core import mail as django_mail +from django.test import TestCase +from django.utils import timezone + +from ..models.event import Event +from .. import emails + + +class EmailsTestCase(TestCase): + def setUp(self): + model = get_user_model() + self.recipient = model.objects.create_user(username='recipient@example.com', + email='recipient@example.com', + password=u'mellon12', + first_name=u'Re Ö.', + last_name=u'Cipient', + ) + self.editor = model.objects.create_user(username='editor@example.com', + email='editor@example.com', + password=u'mellon12', + first_name=u'Ed Ü.', + last_name=u'Itor', + ) + event_data = { + 'title': u'Täst', + 'description': u'Teßt', + 'mode': 'joint', + 'sport': 'W', + 'level': 'beginner', + 'first_day': timezone.now(), + 'country': 'DE', + 'owner': self.editor, + } + self.event = Event(**event_data) + self.event.save() + self.diff = u"""--- ++++ +@@ -1,3 +1,3 @@ + Line 1 ä +-Line2 ++Line 2 +Line 3 END""" + + def test_event_updated_mail(self): + email = emails.EventUpdatedMail(recipient=self.recipient, event=self.event, editor=self.editor, + diff=self.diff) + email.send() + + self.assertEqual(len(django_mail.outbox), 1) + mail = django_mail.outbox[0] + recipient = u'"%s" <%s>' % (self.recipient.get_full_name(), self.recipient.email) + recipients = mail.recipients() + self.assertIn(recipient, recipients) + self.assertEqual(len(recipients), 1) + self.assertIn(self.recipient.first_name, mail.body) + self.assertIn(self.editor.get_full_name(), mail.body) + self.assertIn(unicode(self.event), mail.body) + self.assertIn(self.diff, mail.body) + + def test_event_submitted_mail(self): + # TODO + pass + + def test_event_to_accept_mail(self): + # TODO + pass + + def test_accepted_mail(self): + # TODO + pass + + def test_event_to_publish_web_mail(self): + # TODO + pass + + def test_event_to_publish_facebook_mail(self): + # TODO + pass \ No newline at end of file diff --git a/dav_events/tests/test_urls.py b/dav_events/tests/test_urls.py new file mode 100644 index 0000000..96bc306 --- /dev/null +++ b/dav_events/tests/test_urls.py @@ -0,0 +1,14 @@ +from dav_base.tests.generic import Url, UrlsTestCase + +from .. import views + + +class TestCase(UrlsTestCase): + urls = ( + Url('/events/home', 'dav_events:root', views.base.HomeView.as_view()), + Url('/events/', 'dav_events:list', views.events.EventListView.as_view(), + redirect='/auth/login?next=/events/'), + Url('/events/export', 'dav_events:list_export', views.events.EventListExportView.as_view(), + redirect='/auth/login?next=/events/export'), + Url('/events/create', 'dav_events:create', views.events.EventCreateView.as_view()), + )