Changeset - ac5d236a995a
[Not reviewed]
default
0 1 0
Thomas De Schampheleire - 10 years ago 2015-06-22 14:56:01
thomas.de.schampheleire@gmail.com
tests: improve robustness of notifications tests

The notifications tests make the assumption that there are no notifications
at the start of the test, which is explicitly asserted.

However, any other test, like the one introduced in commit 9a23b444a7fe
(pullrequests: detect invalid reviewers and raise HTTPBadRequest), could add
new notifications to the database, and thus fail these assertions.

Just like the notifications tests already cleaned all notifications at the
end of the test (tearDown), make sure to clean them at the start (setUp)
too.
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/models/test_notifications.py
Show inline comments
 
@@ -32,24 +32,27 @@ class TestNotifications(BaseTestCase):
 
        Session().commit()
 
        self.u3 = self.u3.user_id
 

	
 
        super(TestNotifications, self).__init__(methodName=methodName)
 

	
 
    def _clean_notifications(self):
 
        for n in Notification.query().all():
 
            Session().delete(n)
 

	
 
        Session().commit()
 
        self.assertEqual(Notification.query().all(), [])
 

	
 
    def setUp(self):
 
        self._clean_notifications()
 

	
 
    def tearDown(self):
 
        self._clean_notifications()
 

	
 
    def test_create_notification(self):
 
        self.assertEqual([], Notification.query().all())
 
        self.assertEqual([], UserNotification.query().all())
 

	
 
        usrs = [self.u1, self.u2]
 
        notification = NotificationModel().create(created_by=self.u1,
 
                                           subject=u'subj', body=u'hi there',
 
                                           recipients=usrs)
 
        Session().commit()
 
@@ -147,25 +150,24 @@ class TestNotifications(BaseTestCase):
 
                                    notification)\
 
                            .filter(UserNotification.user_id == self.u1)\
 
                            .scalar()
 
        self.assertNotEqual(u1notification, None)
 
        u2notification = UserNotification.query()\
 
                            .filter(UserNotification.notification ==
 
                                    notification)\
 
                            .filter(UserNotification.user_id == self.u2)\
 
                            .scalar()
 
        self.assertNotEqual(u2notification, None)
 

	
 
    def test_notification_counter(self):
 
        self._clean_notifications()
 
        self.assertEqual([], Notification.query().all())
 
        self.assertEqual([], UserNotification.query().all())
 

	
 
        NotificationModel().create(created_by=self.u1,
 
                            subject=u'title', body=u'hi there_delete',
 
                            recipients=[self.u3, self.u1])
 
        Session().commit()
 

	
 
        self.assertEqual(NotificationModel()
 
                         .get_unread_cnt_for_user(self.u1), 1)
 
        self.assertEqual(NotificationModel()
 
                         .get_unread_cnt_for_user(self.u2), 0)
0 comments (0 inline, 0 general)