소스 검색

better handle email_sent param + tests for new user

Guénaël Muller 6 년 전
부모
커밋
195a0057b3

+ 51 - 2
backend/tests_configs.ini 파일 보기

@@ -70,8 +70,8 @@ depot_storage_name = test
70 70
 depot_storage_dir = /tmp/test/depot
71 71
 user.auth_token.validity = 604800
72 72
 preview_cache_dir = /tmp/test/preview_cache
73
-email.notification.activated = false
74 73
 preview.jpg.restricted_dims = True
74
+email.notification.activated = false
75 75
 
76 76
 [functional_test_no_db]
77 77
 sqlalchemy.url = sqlite://
@@ -79,5 +79,54 @@ depot_storage_name = test
79 79
 depot_storage_dir = /tmp/test/depot
80 80
 user.auth_token.validity = 604800
81 81
 preview_cache_dir = /tmp/test/preview_cache
82
+preview.jpg.restricted_dims = True
82 83
 email.notification.activated = false
83
-preview.jpg.restricted_dims = True
84
+
85
+[functional_test_with_mail_test_sync]
86
+sqlalchemy.url = sqlite:///tracim_test.sqlite
87
+depot_storage_name = test
88
+depot_storage_dir = /tmp/test/depot
89
+user.auth_token.validity = 604800
90
+preview_cache_dir = /tmp/test/preview_cache
91
+preview.jpg.restricted_dims = True
92
+email.notification.activated = true
93
+email.notification.from.email = test_user_from+{user_id}@localhost
94
+email.notification.from.default_label = Tracim Notifications
95
+email.notification.reply_to.email = test_user_reply+{content_id}@localhost
96
+email.notification.references.email = test_user_refs+{content_id}@localhost
97
+email.notification.content_update.template.html = %(here)s/tracim_backend/templates/mail/content_update_body_html.mak
98
+email.notification.content_update.template.text = %(here)s/tracim_backend/templates/mail/content_update_body_text.mak
99
+email.notification.created_account.template.html = %(here)s/tracim_backend/templates/mail/created_account_body_html.mak
100
+email.notification.created_account.template.text = %(here)s/tracim_backend/templates/mail/created_account_body_text.mak
101
+email.notification.content_update.subject = [{website_title}] [{workspace_label}] {content_label} ({content_status_label})
102
+email.notification.created_account.subject = [{website_title}] Created account
103
+email.notification.processing_mode = sync
104
+email.notification.smtp.server = 127.0.0.1
105
+email.notification.smtp.port = 1025
106
+email.notification.smtp.user = test_user
107
+email.notification.smtp.password = just_a_password
108
+
109
+
110
+[functional_test_with_mail_test_async]
111
+sqlalchemy.url = sqlite:///tracim_test.sqlite
112
+depot_storage_name = test
113
+depot_storage_dir = /tmp/test/depot
114
+user.auth_token.validity = 604800
115
+preview_cache_dir = /tmp/test/preview_cache
116
+preview.jpg.restricted_dims = True
117
+email.notification.activated = true
118
+email.notification.from.email = test_user_from+{user_id}@localhost
119
+email.notification.from.default_label = Tracim Notifications
120
+email.notification.reply_to.email = test_user_reply+{content_id}@localhost
121
+email.notification.references.email = test_user_refs+{content_id}@localhost
122
+email.notification.content_update.template.html = %(here)s/tracim_backend/templates/mail/content_update_body_html.mak
123
+email.notification.content_update.template.text = %(here)s/tracim_backend/templates/mail/content_update_body_text.mak
124
+email.notification.created_account.template.html = %(here)s/tracim_backend/templates/mail/created_account_body_html.mak
125
+email.notification.created_account.template.text = %(here)s/tracim_backend/templates/mail/created_account_body_text.mak
126
+email.notification.content_update.subject = [{website_title}] [{workspace_label}] {content_label} ({content_status_label})
127
+email.notification.created_account.subject = [{website_title}] Created account
128
+email.notification.processing_mode = async
129
+email.notification.smtp.server = 127.0.0.1
130
+email.notification.smtp.port = 1025
131
+email.notification.smtp.user = test_user
132
+email.notification.smtp.password = just_a_password

+ 84 - 1
backend/tracim_backend/tests/functional/test_workspaces.py 파일 보기

@@ -2,7 +2,7 @@
2 2
 """
3 3
 Tests for /api/v2/workspaces subpath endpoints.
4 4
 """
5
-
5
+import requests
6 6
 import transaction
7 7
 from depot.io.utils import FileIntent
8 8
 
@@ -612,6 +612,89 @@ class TestWorkspaceMembersEndpoint(FunctionalTest):
612 612
         assert user_role['workspace_id'] == 1
613 613
 
614 614
 
615
+class TestUserInvitationWithMailActivatedSync(FunctionalTest):
616
+
617
+    fixtures = [BaseFixture, ContentFixtures]
618
+    config_section = 'functional_test_with_mail_test_sync'
619
+
620
+    def test_api__create_workspace_member_role__ok_200__new_user(self):  # nopep8
621
+        """
622
+        Create workspace member role
623
+        :return:
624
+        """
625
+        requests.delete('http://127.0.0.1:8025/api/v1/messages')
626
+        self.testapp.authorization = (
627
+            'Basic',
628
+            (
629
+                'admin@admin.admin',
630
+                'admin@admin.admin'
631
+            )
632
+        )
633
+        # create workspace role
634
+        params = {
635
+            'user_id': None,
636
+            'user_email_or_public_name': 'bob@bob.bob',
637
+            'role': 'content-manager',
638
+        }
639
+        res = self.testapp.post_json(
640
+            '/api/v2/workspaces/1/members',
641
+            status=200,
642
+            params=params,
643
+        )
644
+        user_role_found = res.json_body
645
+        assert user_role_found['role'] == 'content-manager'
646
+        assert user_role_found['user_id']
647
+        user_id = user_role_found['user_id']
648
+        assert user_role_found['workspace_id'] == 1
649
+        assert user_role_found['newly_created'] is True
650
+        assert user_role_found['email_sent'] is True
651
+
652
+        # check mail received
653
+        response = requests.get('http://127.0.0.1:8025/api/v1/messages')
654
+        response = response.json()
655
+        assert len(response) == 1
656
+        headers = response[0]['Content']['Headers']
657
+        assert headers['From'][0] == 'Tracim Notifications <test_user_from+0@localhost>'  # nopep8
658
+        assert headers['To'][0] == 'bob <bob@bob.bob>'
659
+        assert headers['Subject'][0] == '[TRACIM] Created account'
660
+
661
+        # TODO - G.M - 2018-08-02 - Place cleanup outside of the test
662
+        requests.delete('http://127.0.0.1:8025/api/v1/messages')
663
+
664
+
665
+class TestUserInvitationWithMailActivatedASync(FunctionalTest):
666
+
667
+    fixtures = [BaseFixture, ContentFixtures]
668
+    config_section = 'functional_test_with_mail_test_async'
669
+
670
+    def test_api__create_workspace_member_role__ok_200__new_user(self):  # nopep8
671
+        """
672
+        Create workspace member role
673
+        :return:
674
+        """
675
+        self.testapp.authorization = (
676
+            'Basic',
677
+            (
678
+                'admin@admin.admin',
679
+                'admin@admin.admin'
680
+            )
681
+        )
682
+        # create workspace role
683
+        params = {
684
+            'user_id': None,
685
+            'user_email_or_public_name': 'bob@bob.bob',
686
+            'role': 'content-manager',
687
+        }
688
+        res = self.testapp.post_json(
689
+            '/api/v2/workspaces/1/members',
690
+            status=200,
691
+            params=params,
692
+        )
693
+        user_role_found = res.json_body
694
+        assert user_role_found['newly_created'] is True
695
+        assert user_role_found['email_sent'] is False
696
+
697
+
615 698
 class TestWorkspaceContents(FunctionalTest):
616 699
     """
617 700
     Tests for /api/v2/workspaces/{workspace_id}/contents endpoint

+ 0 - 0
backend/tracim_backend/tests/library/tests_utils.py 파일 보기


+ 1 - 1
backend/tracim_backend/views/core_api/workspace_controller.py 파일 보기

@@ -218,7 +218,7 @@ class WorkspaceController(Controller):
218 218
                 )  # nopep8
219 219
                 newly_created = True
220 220
                 if app_config.EMAIL_NOTIFICATION_ACTIVATED and \
221
-                        app_config.EMAIL_PROCESSING_MODE == 'SYNC':
221
+                        app_config.EMAIL_NOTIFICATION_PROCESSING_MODE.lower() == 'sync':
222 222
                     email_sent = True
223 223
 
224 224
             except EmailValidationFailed: