Parcourir la source

Reword notification → admin notification

Pave the way for contributor notification
Jocelyn Delalande il y a 7 ans
Parent
commit
e6f56da843

wifiwithme/apps/contribmap/templates/contribmap/mails/new_contrib_notice.subject → wifiwithme/apps/contribmap/templates/contribmap/mails/new_contrib_moderator_notice.subject


wifiwithme/apps/contribmap/templates/contribmap/mails/new_contrib_notice.txt → wifiwithme/apps/contribmap/templates/contribmap/mails/new_contrib_moderator_notice.txt


+ 25 - 25
wifiwithme/apps/contribmap/tests.py

@@ -84,6 +84,26 @@ class TestContribPrivacy(TestCase):
 
 
 class TestViews(APITestCase):
+    def mk_contrib_post_data(self, *args, **kwargs):
+        post_data = {
+            'roof': True,
+            'privacy_place_details': True,
+            'privacy_coordinates': True,
+            'phone': '0202020202',
+            'orientations': ('N', 'NO', 'O', 'SO', 'S', 'SE', 'E', 'NE'),
+            'orientation': 'all',
+            'name': 'JohnCleese',
+            'longitude': -1.553621,
+            'latitude': 47.218371,
+            'floor_total': '2',
+            'floor': 1,
+            'email': 'coucou@example.com',
+            'contrib_type': 'connect',
+            'connect_local': 'on',
+        }
+        post_data.update(kwargs)
+        return post_data
+
     def test_public_json(self):
         response = self.client.json_get('/map/public.json')
         self.assertEqual(response.status_code, 200)
@@ -115,37 +135,17 @@ class TestViews(APITestCase):
         self.assertEqual(response.status_code, 200)
 
     @override_settings(NOTIFICATION_EMAILS=['foo@example.com'])
-    def test_add_contrib_sends_email(self):
-        response = self.client.post('/map/contribute', {
-            'roof': True,
-            'privacy_place_details': True,
-            'privacy_coordinates': True,
-            'phone': '0202020202',
-            'orientations': 'N',
-            'orientations': 'NO',
-            'orientations': 'O',
-            'orientations': 'SO',
-            'orientations': 'S',
-            'orientations': 'SE',
-            'orientations': 'E',
-            'orientations': 'NE',
-            'orientation': 'all',
-            'name': 'JohnCleese',
-            'longitude': -1.553621,
-            'latitude': 47.218371,
-            'floor_total': '2',
-            'floor': 1,
-            'email': 'coucou@example.com',
-            'contrib_type': 'connect',
-            'connect_local': 'on',
-        })
+    def test_add_contrib_sends_moderator_email(self):
+        post_data = self.mk_contrib_post_data({'name': 'JohnCleese'})
+        del post_data['email']
+
+        response = self.client.post('/map/contribute', post_data)
         self.assertEqual(response.status_code, 302)
 
         self.assertEqual(len(mail.outbox), 1)
         self.assertIn('JohnCleese', mail.outbox[0].subject)
         self.assertIn('JohnCleese', mail.outbox[0].body)
 
-<<<<<<< HEAD
 class TestForms(TestCase):
     valid_data = {
         'roof': True,

+ 7 - 6
wifiwithme/apps/contribmap/views.py

@@ -21,19 +21,20 @@ def add_contrib(request):
 
         if form.is_valid():
             contrib = form.save()
-            # Send notification email
+            # Send notification email to site administrator
             if len(settings.NOTIFICATION_EMAILS) > 0:
                 context = {
                     'contrib_url': settings.SITE_URL + reverse('display_map') + '#{}'.format(contrib.id),
                     'contrib': contrib,
                 }
                 subject = get_template(
-                    'contribmap/mails/new_contrib_notice.subject')
-                body = get_template(
-                    'contribmap/mails/new_contrib_notice.txt')
+                admin_subject = get_template(
+                    'contribmap/mails/new_contrib_moderator_notice.subject')
+                admin_body = get_template(
+                    'contribmap/mails/new_contrib_moderator_notice.txt')
                 send_mail(
-                    subject.render(context),
-                    body.render(context),
+                    admin_subject.render(context),
+                    admin_body.render(context),
                     settings.DEFAULT_FROM_EMAIL,
                     settings.NOTIFICATION_EMAILS,
                 )