UPD: more test.
This commit is contained in:
@@ -11,7 +11,7 @@ class PasswordSetEmail(AbstractMail):
|
|||||||
self._password = password
|
self._password = password
|
||||||
|
|
||||||
def _get_recipients(self):
|
def _get_recipients(self):
|
||||||
r = u'{fullname} <{email}>'.format(fullname=self._user.get_full_name(),
|
r = u'"{fullname}" <{email}>'.format(fullname=self._user.get_full_name(),
|
||||||
email=self._user.email)
|
email=self._user.email)
|
||||||
return [r]
|
return [r]
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.test import SimpleTestCase
|
|
||||||
|
from dav_base.tests.generic import AppSetting, AppsTestCase
|
||||||
|
|
||||||
|
|
||||||
class AppsTestCase(SimpleTestCase):
|
class TestCase(AppsTestCase):
|
||||||
def setUp(self):
|
app_config = apps.get_app_config('dav_auth')
|
||||||
app_config = apps.get_containing_app_config(__package__)
|
|
||||||
self.settings = app_config.settings
|
|
||||||
|
|
||||||
def test_settings(self):
|
settings = (
|
||||||
setting_names = ('login_redirect_url',
|
AppSetting('login_redirect_url', basestring),
|
||||||
'logout_redirect_url')
|
AppSetting('logout_redirect_url', basestring),
|
||||||
|
)
|
||||||
for s in setting_names:
|
|
||||||
self.assertTrue(hasattr(self.settings, s), 'Settings do not contain {}'.format(s))
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class EmailsTestCase(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(len(django_mail.outbox), 1)
|
self.assertEqual(len(django_mail.outbox), 1)
|
||||||
mail = django_mail.outbox[0]
|
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()
|
recipients = mail.recipients()
|
||||||
self.assertIn(recipient, recipients)
|
self.assertIn(recipient, recipients)
|
||||||
self.assertEqual(len(recipients), 1)
|
self.assertEqual(len(recipients), 1)
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class ViewsTestCase(TestCase):
|
|||||||
'send_password_mail': True})
|
'send_password_mail': True})
|
||||||
self.assertEqual(len(django_mail.outbox), 1)
|
self.assertEqual(len(django_mail.outbox), 1)
|
||||||
mail = django_mail.outbox[0]
|
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()
|
recipients = mail.recipients()
|
||||||
self.assertIn(recipient, recipients)
|
self.assertIn(recipient, recipients)
|
||||||
self.assertEqual(len(recipients), 1)
|
self.assertEqual(len(recipients), 1)
|
||||||
@@ -202,7 +202,7 @@ class ViewsTestCase(TestCase):
|
|||||||
|
|
||||||
self.assertEqual(len(django_mail.outbox), 1)
|
self.assertEqual(len(django_mail.outbox), 1)
|
||||||
mail = django_mail.outbox[0]
|
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()
|
recipients = mail.recipients()
|
||||||
self.assertIn(recipient, recipients)
|
self.assertIn(recipient, recipients)
|
||||||
self.assertEqual(len(recipients), 1)
|
self.assertEqual(len(recipients), 1)
|
||||||
|
|||||||
@@ -18,6 +18,34 @@ def skip_unless_tag_option():
|
|||||||
return skip('Skipped unless --tag option is used')
|
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):
|
class Url(object):
|
||||||
def __init__(self, location, name=None, func=None, **kwargs):
|
def __init__(self, location, name=None, func=None, **kwargs):
|
||||||
self.location = location
|
self.location = location
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.test import SimpleTestCase
|
|
||||||
|
from .generic import AppSetting, AppsTestCase
|
||||||
|
|
||||||
|
|
||||||
class AppsTestCase(SimpleTestCase):
|
class TestCase(AppsTestCase):
|
||||||
def setUp(self):
|
app_config = apps.get_app_config('dav_base')
|
||||||
app_config = apps.get_containing_app_config(__package__)
|
|
||||||
self.settings = app_config.settings
|
|
||||||
|
|
||||||
def test_settings(self):
|
settings = (
|
||||||
setting_names = ('email_sender',
|
AppSetting('email_sender', basestring),
|
||||||
'email_base_url',
|
AppSetting('email_base_url', basestring),
|
||||||
'email_subject_prefix')
|
AppSetting('email_subject_prefix', basestring),
|
||||||
|
)
|
||||||
for s in setting_names:
|
|
||||||
self.assertTrue(hasattr(self.settings, s), 'Settings do not contain {}'.format(s))
|
|
||||||
|
|||||||
0
dav_events/tests/__init__.py
Normal file
0
dav_events/tests/__init__.py
Normal file
27
dav_events/tests/test_apps.py
Normal file
27
dav_events/tests/test_apps.py
Normal file
@@ -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),
|
||||||
|
)
|
||||||
80
dav_events/tests/test_emails.py
Normal file
80
dav_events/tests/test_emails.py
Normal file
@@ -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
|
||||||
14
dav_events/tests/test_urls.py
Normal file
14
dav_events/tests/test_urls.py
Normal file
@@ -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()),
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user