|
@@ -1,12 +1,9 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+import os
|
|
3
|
+import re
|
2
|
4
|
|
3
|
5
|
from nose.tools import eq_
|
4
|
6
|
from nose.tools import ok_
|
5
|
|
-from nose.tools import raises
|
6
|
|
-
|
7
|
|
-from sqlalchemy.orm.exc import NoResultFound
|
8
|
|
-
|
9
|
|
-import transaction
|
10
|
7
|
|
11
|
8
|
from tracim.config.app_cfg import CFG
|
12
|
9
|
from tracim.lib.notifications import DummyNotifier
|
|
@@ -16,7 +13,6 @@ from tracim.lib.notifications import NotifierFactory
|
16
|
13
|
from tracim.lib.notifications import RealNotifier
|
17
|
14
|
from tracim.model.auth import User
|
18
|
15
|
from tracim.model.data import Content
|
19
|
|
-
|
20
|
16
|
from tracim.tests import TestStandard
|
21
|
17
|
|
22
|
18
|
|
|
@@ -43,7 +39,7 @@ class TestDummyNotifier(TestStandard):
|
43
|
39
|
def test_email_subject_tag_list(self):
|
44
|
40
|
tags = EST.all()
|
45
|
41
|
|
46
|
|
- eq_(4,len(tags))
|
|
42
|
+ eq_(4, len(tags))
|
47
|
43
|
ok_('{website_title}' in tags)
|
48
|
44
|
ok_('{workspace_label}' in tags)
|
49
|
45
|
ok_('{content_label}' in tags)
|
|
@@ -51,6 +47,31 @@ class TestDummyNotifier(TestStandard):
|
51
|
47
|
|
52
|
48
|
|
53
|
49
|
class TestEmailNotifier(TestStandard):
|
|
50
|
+
|
|
51
|
+ def test_unit__log_notification(self):
|
|
52
|
+ log_path = CFG.get_instance().EMAIL_NOTIFICATION_LOG_FILE_PATH
|
|
53
|
+ pattern = '\|{rec}\|{subj}$\\n'
|
|
54
|
+ line_1_rec = 'user 1 <us.er@o.ne>'
|
|
55
|
+ line_1_subj = 'notification 1'
|
|
56
|
+ line_1_pattern = pattern.format(rec=line_1_rec, subj=line_1_subj)
|
|
57
|
+ line_2_rec = 'user 2 <us.er@t.wo>'
|
|
58
|
+ line_2_subj = 'notification 2'
|
|
59
|
+ line_2_pattern = pattern.format(rec=line_2_rec, subj=line_2_subj)
|
|
60
|
+ EmailNotifier._log_notification(
|
|
61
|
+ recipient=line_1_rec,
|
|
62
|
+ subject=line_1_subj,
|
|
63
|
+ )
|
|
64
|
+ EmailNotifier._log_notification(
|
|
65
|
+ recipient=line_2_rec,
|
|
66
|
+ subject=line_2_subj,
|
|
67
|
+ )
|
|
68
|
+ with open(log_path, 'rt') as log_file:
|
|
69
|
+ line_1 = log_file.readline()
|
|
70
|
+ line_2 = log_file.readline()
|
|
71
|
+ os.remove(path=log_path)
|
|
72
|
+ ok_(re.search(pattern=line_1_pattern, string=line_1))
|
|
73
|
+ ok_(re.search(pattern=line_2_pattern, string=line_2))
|
|
74
|
+
|
54
|
75
|
def test_email_notifier__build_name_with_user_id(self):
|
55
|
76
|
u = User()
|
56
|
77
|
u.user_id = 3
|
|
@@ -95,4 +116,3 @@ class TestEmailNotifier(TestStandard):
|
95
|
116
|
notifier = EmailNotifier(smtp_config=None, global_config=config)
|
96
|
117
|
email = notifier._get_sender()
|
97
|
118
|
eq_('Robot <noreply@tracim.io>', email)
|
98
|
|
-
|