Browse Source

improve test coverage

Damien ACCORSI 10 years ago
parent
commit
ba18c9b243
1 changed files with 30 additions and 47 deletions
  1. 30 47
      tracim/tracim/tests/library/test_notification.py

+ 30 - 47
tracim/tracim/tests/library/test_notification.py View File

@@ -8,59 +8,42 @@ from sqlalchemy.orm.exc import NoResultFound
8 8
 
9 9
 import transaction
10 10
 
11
-from tracim.lib.user import UserApi
12
-from tracim.tests import TestStandard
13
-
14
-
15
-
16
-class TestUserApi(TestStandard):
11
+from tracim.config.app_cfg import CFG
12
+from tracim.lib.notifications import DummyNotifier
13
+from tracim.lib.notifications import EST
14
+from tracim.lib.notifications import NotifierFactory
15
+from tracim.lib.notifications import RealNotifier
16
+from tracim.model.auth import User
17
+from tracim.model.data import Content
17 18
 
18
-    def test_create_and_update_user(self):
19
-        api = UserApi(None)
20
-        u = api.create_user()
21
-        api.update(u, 'bob', 'bob@bob', True)
22
-
23
-        nu = api.get_one_by_email('bob@bob')
24
-        ok_(nu!=None)
25
-        eq_('bob@bob', nu.email)
26
-        eq_('bob', nu.display_name)
27
-
28
-
29
-    def test_user_with_email_exists(self):
30
-        api = UserApi(None)
31
-        u = api.create_user()
32
-        api.update(u, 'bibi', 'bibi@bibi', True)
33
-        transaction.commit()
19
+from tracim.tests import TestStandard
34 20
 
35
-        eq_(True, api.user_with_email_exists('bibi@bibi'))
36
-        eq_(False, api.user_with_email_exists('unknown'))
37 21
 
22
+class TestDummyNotifier(TestStandard):
38 23
 
39
-    def test_get_one_by_email(self):
40
-        api = UserApi(None)
41
-        u = api.create_user()
42
-        api.update(u, 'bibi', 'bibi@bibi', True)
43
-        uid = u.user_id
44
-        transaction.commit()
24
+    def test_dummy_notifier__notify_content_update(self):
25
+        c = Content()
26
+        notifier = DummyNotifier()
27
+        notifier.notify_content_update(c)
28
+        # INFO - D.A. - 2014-12-09 - Old notification_content_update raised an exception
45 29
 
46
-        eq_(uid, api.get_one_by_email('bibi@bibi').user_id)
30
+    def test_notifier_factory_method(self):
31
+        u = User()
47 32
 
48
-    @raises(NoResultFound)
49
-    def test_get_one_by_email_exception(self):
50
-        api = UserApi(None)
51
-        api.get_one_by_email('unknown')
33
+        cfg = CFG.get_instance()
34
+        cfg.EMAIL_NOTIFICATION_ACTIVATED = True
35
+        notifier = NotifierFactory.create(u)
36
+        eq_(RealNotifier, notifier.__class__)
52 37
 
53
-    def test_get_all(self):
54
-        api = UserApi(None)
55
-        # u1 = api.create_user(True)
56
-        # u2 = api.create_user(True)
38
+        cfg.EMAIL_NOTIFICATION_ACTIVATED = False
39
+        notifier = NotifierFactory.create(u)
40
+        eq_(DummyNotifier, notifier.__class__)
57 41
 
58
-        # users = api.get_all()
59
-        # ok_(2==len(users))
42
+    def test_email_subject_tag_list(self):
43
+        tags = EST.all()
60 44
 
61
-    def test_get_one(self):
62
-        api = UserApi(None)
63
-        u = api.create_user()
64
-        api.update(u, 'titi', 'titi@titi', True)
65
-        one = api.get_one(u.user_id)
66
-        eq_(u.user_id, one.user_id)
45
+        eq_(4,len(tags))
46
+        ok_('{website_title}' in tags)
47
+        ok_('{workspace_label}' in tags)
48
+        ok_('{content_label}' in tags)
49
+        ok_('{content_status_label}' in tags)