Mercurial > kallithea
annotate rhodecode/tests/models/test_notifications.py @ 3169:a649599ad8b7 beta
added my gist script for another detailed installation instructions
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 18 Jan 2013 01:11:28 +0100 |
parents | d5e42c00f3c1 |
children | 5067d6e826a5 |
rev | line source |
---|---|
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
1 import os |
1373
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
2 import unittest |
66f03a87141c
Fixes issue #201
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
3 from rhodecode.tests import * |
1538
27be8f94c207
implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents:
1373
diff
changeset
|
4 |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
5 from rhodecode.model.db import User, Notification, UserNotification |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
6 from rhodecode.model.user import UserModel |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
7 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
8 from rhodecode.model.meta import Session |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
9 from rhodecode.model.notification import NotificationModel |
2329
20e307d5250f
Added email-map for alternative email addresses for users
Marcin Kuzminski <marcin@python-works.com>
parents:
2255
diff
changeset
|
10 |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1538
diff
changeset
|
11 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
12 class TestNotifications(unittest.TestCase): |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
13 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
14 def __init__(self, methodName='runTest'): |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
15 Session.remove() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
16 self.u1 = UserModel().create_or_update(username=u'u1', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
17 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
18 email=u'u1@rhodecode.org', |
2513
388843a3a3c0
Updated create_or_update method to not change API key when password is not updated
Marcin Kuzminski <marcin@python-works.com>
parents:
2462
diff
changeset
|
19 firstname=u'u1', lastname=u'u1') |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
20 Session().commit() |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
21 self.u1 = self.u1.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
22 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
23 self.u2 = UserModel().create_or_update(username=u'u2', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
24 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
25 email=u'u2@rhodecode.org', |
2515
623e1d68a2e0
fixed few test failures
Marcin Kuzminski <marcin@python-works.com>
parents:
2513
diff
changeset
|
26 firstname=u'u2', lastname=u'u3') |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
27 Session().commit() |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
28 self.u2 = self.u2.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
29 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
30 self.u3 = UserModel().create_or_update(username=u'u3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
31 password=u'qweqwe', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
32 email=u'u3@rhodecode.org', |
2515
623e1d68a2e0
fixed few test failures
Marcin Kuzminski <marcin@python-works.com>
parents:
2513
diff
changeset
|
33 firstname=u'u3', lastname=u'u3') |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
34 Session().commit() |
1734
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
35 self.u3 = self.u3.user_id |
48d4fcf04a29
another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents:
1733
diff
changeset
|
36 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
37 super(TestNotifications, self).__init__(methodName=methodName) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
38 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
39 def _clean_notifications(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
40 for n in Notification.query().all(): |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
41 Session().delete(n) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
42 |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
43 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
44 self.assertEqual(Notification.query().all(), []) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
45 |
1758
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
46 def tearDown(self): |
a87aa385f21c
fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
47 self._clean_notifications() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
48 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
49 def test_create_notification(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
50 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
51 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
52 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
53 usrs = [self.u1, self.u2] |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
54 notification = NotificationModel().create(created_by=self.u1, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
55 subject=u'subj', body=u'hi there', |
1709 | 56 recipients=usrs) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
57 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
58 u1 = User.get(self.u1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
59 u2 = User.get(self.u2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
60 u3 = User.get(self.u3) |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
61 notifications = Notification.query().all() |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
62 self.assertEqual(len(notifications), 1) |
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
63 |
2589
146480218785
small test fix to fix rare travis build issues
Marcin Kuzminski <marcin@python-works.com>
parents:
2527
diff
changeset
|
64 self.assertEqual(notifications[0].recipients, [u1, u2]) |
146480218785
small test fix to fix rare travis build issues
Marcin Kuzminski <marcin@python-works.com>
parents:
2527
diff
changeset
|
65 self.assertEqual(notification.notification_id, |
146480218785
small test fix to fix rare travis build issues
Marcin Kuzminski <marcin@python-works.com>
parents:
2527
diff
changeset
|
66 notifications[0].notification_id) |
146480218785
small test fix to fix rare travis build issues
Marcin Kuzminski <marcin@python-works.com>
parents:
2527
diff
changeset
|
67 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
68 unotification = UserNotification.query()\ |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
69 .filter(UserNotification.notification == notification).all() |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
70 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
71 self.assertEqual(len(unotification), len(usrs)) |
2589
146480218785
small test fix to fix rare travis build issues
Marcin Kuzminski <marcin@python-works.com>
parents:
2527
diff
changeset
|
72 self.assertEqual(set([x.user.user_id for x in unotification]), |
146480218785
small test fix to fix rare travis build issues
Marcin Kuzminski <marcin@python-works.com>
parents:
2527
diff
changeset
|
73 set(usrs)) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
74 |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
75 def test_user_notifications(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
76 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
77 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
78 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
79 notification1 = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
80 subject=u'subj', body=u'hi there1', |
1709 | 81 recipients=[self.u3]) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
82 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
83 notification2 = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
84 subject=u'subj', body=u'hi there2', |
1709 | 85 recipients=[self.u3]) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
86 Session().commit() |
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
87 u3 = Session().query(User).get(self.u3) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
88 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
89 self.assertEqual(sorted([x.notification for x in u3.notifications]), |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
90 sorted([notification2, notification1])) |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
91 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
92 def test_delete_notifications(self): |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
93 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
94 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
95 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
96 notification = NotificationModel().create(created_by=self.u1, |
1712
cac5109ac3b6
Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents:
1709
diff
changeset
|
97 subject=u'title', body=u'hi there3', |
1709 | 98 recipients=[self.u3, self.u1, self.u2]) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
99 Session().commit() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
100 notifications = Notification.query().all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
101 self.assertTrue(notification in notifications) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
102 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
103 Notification.delete(notification.notification_id) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
104 Session().commit() |
1702
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
105 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
106 notifications = Notification.query().all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
107 self.assertFalse(notification in notifications) |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
108 |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
109 un = UserNotification.query().filter(UserNotification.notification |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
110 == notification).all() |
8cb7f5c4d494
#302 - basic notification system, models+tests
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
111 self.assertEqual(un, []) |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
112 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
113 def test_delete_association(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
114 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
115 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
116 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
117 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
118 notification = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
119 subject=u'title', body=u'hi there3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
120 recipients=[self.u3, self.u1, self.u2]) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
121 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
122 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
123 unotification = UserNotification.query()\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
124 .filter(UserNotification.notification == |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
125 notification)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
126 .filter(UserNotification.user_id == self.u3)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
127 .scalar() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
128 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
129 self.assertEqual(unotification.user_id, self.u3) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
130 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
131 NotificationModel().delete(self.u3, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
132 notification.notification_id) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
133 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
134 |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
135 u3notification = UserNotification.query()\ |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
136 .filter(UserNotification.notification == |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
137 notification)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
138 .filter(UserNotification.user_id == self.u3)\ |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
139 .scalar() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
140 |
1733
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
141 self.assertEqual(u3notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
142 |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
143 # notification object is still there |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
144 self.assertEqual(Notification.query().all(), [notification]) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
145 |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
146 #u1 and u2 still have assignments |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
147 u1notification = UserNotification.query()\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
148 .filter(UserNotification.notification == |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
149 notification)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
150 .filter(UserNotification.user_id == self.u1)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
151 .scalar() |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
152 self.assertNotEqual(u1notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
153 u2notification = UserNotification.query()\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
154 .filter(UserNotification.notification == |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
155 notification)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
156 .filter(UserNotification.user_id == self.u2)\ |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
157 .scalar() |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
158 self.assertNotEqual(u2notification, None) |
ac54aa4200e8
fixed bug with eager deletes in notifications
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
159 |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
160 def test_notification_counter(self): |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
161 self._clean_notifications() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
162 self.assertEqual([], Notification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
163 self.assertEqual([], UserNotification.query().all()) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
164 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
165 NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
166 subject=u'title', body=u'hi there_delete', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
167 recipients=[self.u3, self.u1]) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
168 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
169 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
170 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
171 .get_unread_cnt_for_user(self.u1), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
172 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
173 .get_unread_cnt_for_user(self.u2), 0) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
174 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
175 .get_unread_cnt_for_user(self.u3), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
176 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
177 notification = NotificationModel().create(created_by=self.u1, |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
178 subject=u'title', body=u'hi there3', |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
179 recipients=[self.u3, self.u1, self.u2]) |
2527
95624ce4465f
orginized test module
Marcin Kuzminski <marcin@python-works.com>
parents:
2515
diff
changeset
|
180 Session().commit() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
181 |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
182 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
183 .get_unread_cnt_for_user(self.u1), 2) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
184 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
185 .get_unread_cnt_for_user(self.u2), 1) |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
186 self.assertEqual(NotificationModel() |
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1712
diff
changeset
|
187 .get_unread_cnt_for_user(self.u3), 2) |