28 |
25 |
29 |
26 |
30 class SupervisingTC(CubicWebTC): |
27 class SupervisingTC(CubicWebTC): |
31 |
28 |
32 def setup_database(self): |
29 def setup_database(self): |
33 req = self.request() |
30 with self.admin_access.client_cnx() as cnx: |
34 req.create_entity('Card', title=u"une news !", content=u"cubicweb c'est beau") |
31 cnx.create_entity('Card', title=u"une news !", content=u"cubicweb c'est beau") |
35 req.create_entity('Card', title=u"une autre news !", content=u"cubicweb c'est beau") |
32 cnx.create_entity('Card', title=u"une autre news !", content=u"cubicweb c'est beau") |
36 req.create_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
33 cnx.create_entity('Bookmark', title=u"un signet !", path=u"view?vid=index") |
37 req.create_entity('Comment', content=u"Yo !") |
34 cnx.create_entity('Comment', content=u"Yo !") |
38 self.execute('SET C comments B WHERE B title "une autre news !", C content "Yo !"') |
35 cnx.execute('SET C comments B WHERE B title "une autre news !", C content "Yo !"') |
|
36 cnx.commit() |
39 self.vreg.config.global_set_option('supervising-addrs', 'test@logilab.fr') |
37 self.vreg.config.global_set_option('supervising-addrs', 'test@logilab.fr') |
40 |
38 |
41 |
39 |
42 def test_supervision(self): |
40 def test_supervision(self): |
43 # do some modification |
41 # do some modification |
44 user = self.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G ' |
42 with self.admin_access.repo_cnx() as cnx: |
45 'WHERE G name "users"').get_entity(0, 0) |
43 user = cnx.execute('INSERT CWUser X: X login "toto", X upassword "sosafe", X in_group G ' |
46 self.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': user.eid}) |
44 'WHERE G name "users"').get_entity(0, 0) |
47 self.execute('DELETE Card B WHERE B title "une news !"') |
45 cnx.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': user.eid}) |
48 self.execute('SET X bookmarked_by U WHERE X is Bookmark, U eid %(x)s', {'x': user.eid}) |
46 cnx.execute('DELETE Card B WHERE B title "une news !"') |
49 self.execute('SET X content "duh?" WHERE X is Comment') |
47 cnx.execute('SET X bookmarked_by U WHERE X is Bookmark, U eid %(x)s', {'x': user.eid}) |
50 self.execute('DELETE Comment C WHERE C comments Y, Y is Card, Y title "une autre news !"') |
48 cnx.execute('SET X content "duh?" WHERE X is Comment') |
51 # check only one supervision email operation |
49 cnx.execute('DELETE Comment C WHERE C comments Y, Y is Card, Y title "une autre news !"') |
52 session = self.session |
50 # check only one supervision email operation |
53 sentops = [op for op in session.pending_operations |
51 sentops = [op for op in cnx.pending_operations |
54 if isinstance(op, SupervisionMailOp)] |
52 if isinstance(op, SupervisionMailOp)] |
55 self.assertEqual(len(sentops), 1) |
53 self.assertEqual(len(sentops), 1) |
56 # check view content |
54 # check view content |
57 op = sentops[0] |
55 op = sentops[0] |
58 view = sentops[0]._get_view() |
56 view = sentops[0]._get_view() |
59 self.assertEqual(view.recipients(), ['test@logilab.fr']) |
57 self.assertEqual(view.recipients(), ['test@logilab.fr']) |
60 self.assertEqual(view.subject(), '[data supervision] changes summary') |
58 self.assertEqual(view.subject(), '[data supervision] changes summary') |
61 data = view.render(changes=session.transaction_data.get('pendingchanges')).strip() |
59 data = view.render(changes=cnx.transaction_data.get('pendingchanges')).strip() |
62 data = re.sub('#\d+', '#EID', data) |
60 data = re.sub('#\d+', '#EID', data) |
63 data = re.sub('/\d+', '/EID', data) |
61 data = re.sub('/\d+', '/EID', data) |
64 self.assertMultiLineEqual('''user admin has made the following change(s): |
62 self.assertMultiLineEqual('''user admin has made the following change(s): |
65 |
63 |
66 * added cwuser #EID (toto) |
64 * added cwuser #EID (toto) |
67 http://testing.fr/cubicweb/cwuser/toto |
65 http://testing.fr/cubicweb/cwuser/toto |
68 |
66 |
69 * added relation in_group from cwuser #EID to cwgroup #EID |
67 * added relation in_group from cwuser #EID to cwgroup #EID |
75 * updated comment #EID (duh?) |
73 * updated comment #EID (duh?) |
76 http://testing.fr/cubicweb/comment/EID |
74 http://testing.fr/cubicweb/comment/EID |
77 |
75 |
78 * deleted comment #EID (duh?)''', |
76 * deleted comment #EID (duh?)''', |
79 data) |
77 data) |
80 # check prepared email |
78 # check prepared email |
81 op._prepare_email() |
79 op._prepare_email() |
82 self.assertEqual(len(op.to_send), 1) |
80 self.assertEqual(len(op.to_send), 1) |
83 self.assert_(op.to_send[0][0]) |
81 self.assert_(op.to_send[0][0]) |
84 self.assertEqual(op.to_send[0][1], ['test@logilab.fr']) |
82 self.assertEqual(op.to_send[0][1], ['test@logilab.fr']) |
85 self.commit() |
83 cnx.commit() |
86 # some other changes ####### |
84 # some other changes ####### |
87 user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
85 user.cw_adapt_to('IWorkflowable').fire_transition('deactivate') |
88 sentops = [op for op in session.pending_operations |
86 sentops = [op for op in cnx.pending_operations |
89 if isinstance(op, SupervisionMailOp)] |
87 if isinstance(op, SupervisionMailOp)] |
90 self.assertEqual(len(sentops), 1) |
88 self.assertEqual(len(sentops), 1) |
91 # check view content |
89 # check view content |
92 op = sentops[0] |
90 op = sentops[0] |
93 view = sentops[0]._get_view() |
91 view = sentops[0]._get_view() |
94 data = view.render(changes=session.transaction_data.get('pendingchanges')).strip() |
92 data = view.render(changes=cnx.transaction_data.get('pendingchanges')).strip() |
95 data = re.sub('#\d+', '#EID', data) |
93 data = re.sub('#\d+', '#EID', data) |
96 data = re.sub('/\d+', '/EID', data) |
94 data = re.sub('/\d+', '/EID', data) |
97 self.assertMultiLineEqual('''user admin has made the following change(s): |
95 self.assertMultiLineEqual('''user admin has made the following change(s): |
98 |
96 |
99 * changed state of cwuser #EID (toto) |
97 * changed state of cwuser #EID (toto) |
100 from state activated to state deactivated |
98 from state activated to state deactivated |
101 http://testing.fr/cubicweb/cwuser/toto''', |
99 http://testing.fr/cubicweb/cwuser/toto''', |
102 data) |
100 data) |
103 |
101 |
104 def test_nonregr1(self): |
102 def test_nonregr1(self): |
105 session = self.session |
103 with self.admin_access.repo_cnx() as cnx: |
106 # do some unlogged modification |
104 # do some unlogged modification |
107 self.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': session.user.eid}) |
105 cnx.execute('SET X last_login_time NOW WHERE X eid %(x)s', {'x': cnx.user.eid}) |
108 self.commit() # no crash |
106 cnx.commit() # no crash |
109 |
107 |
110 |
108 |
111 if __name__ == '__main__': |
109 if __name__ == '__main__': |
112 unittest_main() |
110 unittest_main() |