diff rhodecode/tests/functional/test_admin_notifications.py @ 1713:54687aa00724 beta

Tests updates, Session refactoring
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 23 Nov 2011 15:36:57 +0200
parents cac5109ac3b6
children 64e91067b996
line wrap: on
line diff
--- a/rhodecode/tests/functional/test_admin_notifications.py	Wed Nov 23 00:55:05 2011 +0200
+++ b/rhodecode/tests/functional/test_admin_notifications.py	Wed Nov 23 15:36:57 2011 +0200
@@ -3,19 +3,23 @@
 
 from rhodecode.model.user import UserModel
 from rhodecode.model.notification import NotificationModel
+from rhodecode.model.meta import Session
 
 class TestNotificationsController(TestController):
 
+
+    def tearDown(self):
+        for n in Notification.query().all():
+            inst = Notification.get(n.notification_id)
+            Session().delete(inst)
+        Session().commit()
+
     def test_index(self):
         self.log_user()
 
-
         u1 = UserModel().create_or_update(username='u1', password='qweqwe',
                                                email='u1@rhodecode.org',
                                                name='u1', lastname='u1').user_id
-        u2 = UserModel().create_or_update(username='u2', password='qweqwe',
-                                               email='u2@rhodecode.org',
-                                               name='u2', lastname='u2').user_id
 
         response = self.app.get(url('notifications'))
         self.assertTrue('''<div class="table">No notifications here yet</div>'''
@@ -23,15 +27,12 @@
 
         cur_user = self._get_logged_user()
 
-        NotificationModel().create(created_by=u1, subject=u'test',
+        NotificationModel().create(created_by=u1, subject=u'test_notification_1',
                                    body=u'notification_1',
                                    recipients=[cur_user])
+        Session().commit()
         response = self.app.get(url('notifications'))
-
-        self.assertTrue(u'notification_1' in response.body)
-
-        User.delete(u1)
-        User.delete(u2)
+        self.assertTrue(u'test_notification_1' in response.body)
 
 #    def test_index_as_xml(self):
 #        response = self.app.get(url('formatted_notifications', format='xml'))
@@ -62,27 +63,29 @@
                                                email='u2@rhodecode.org',
                                                name='u2', lastname='u2')
 
-        # make two notifications 
+        # make notifications
         notification = NotificationModel().create(created_by=cur_user,
                                                   subject=u'test',
                                                   body=u'hi there',
                                                   recipients=[cur_user, u1, u2])
-
+        Session().commit()
         u1 = User.get(u1.user_id)
         u2 = User.get(u2.user_id)
 
         # check DB
-        self.assertEqual(u1.notifications, [notification])
-        self.assertEqual(u2.notifications, [notification])
+        get_notif = lambda un:[x.notification for x in un]
+        self.assertEqual(get_notif(cur_user.notifications), [notification])
+        self.assertEqual(get_notif(u1.notifications), [notification])
+        self.assertEqual(get_notif(u2.notifications), [notification])
         cur_usr_id = cur_user.user_id
-        response = self.app.delete(url('notification',
-                                       notification_id=cur_usr_id))
+
 
-        cur_user = self._get_logged_user()
-        self.assertEqual(cur_user.notifications, [])
+        response = self.app.delete(url('notification',
+                                       notification_id=
+                                       notification.notification_id))
 
-        User.delete(u1.user_id)
-        User.delete(u2.user_id)
+        cur_user = User.get(cur_usr_id)
+        self.assertEqual(cur_user.notifications, [])
 
 
 #    def test_delete_browser_fakeout(self):
@@ -100,7 +103,7 @@
 
         notification = NotificationModel().create(created_by=cur_user,
                                                   subject='test',
-                                                  body='hi there',
+                                                  body=u'hi there',
                                                   recipients=[cur_user, u1, u2])
 
         response = self.app.get(url('notification',
@@ -114,4 +117,3 @@
 #
 #    def test_edit_as_xml(self):
 #        response = self.app.get(url('formatted_edit_notification', notification_id=1, format='xml'))
-