view rhodecode/tests/functional/test_admin_notifications.py @ 3651:659bd922520e beta

config: rename options to show_revision_number and show_sha_length 'sha_show_numeric_rev' had nothing to do with the sha value. The revision numbers are kind of native to Mercurial and there they are known as 'revision numbers'. 'sha_len' was very short and didn't clarify that it only controlled what was shown. These settings are currently only used in the changelog, but they should be used everywhere.
author Mads Kiilerich <madski@unity3d.com>
date Wed, 03 Apr 2013 15:56:12 +0200
parents 63e49418a4cc
children d7488551578e
line wrap: on
line source

from rhodecode.tests import *
from rhodecode.model.db import Notification, User

from rhodecode.model.user import UserModel
from rhodecode.model.notification import NotificationModel


class TestNotificationsController(TestController):

    def tearDown(self):
        for n in Notification.query().all():
            inst = Notification.get(n.notification_id)
            self.Session().delete(inst)
        self.Session().commit()

    def test_index(self):
        self.log_user()

        u1 = UserModel().create_or_update(username='u1', password='qweqwe',
                                               email='u1@rhodecode.org',
                                               firstname='u1', lastname='u1')
        u1 = u1.user_id

        response = self.app.get(url('notifications'))
        response.mustcontain('<div class="table">No notifications here yet</div>')

        cur_user = self._get_logged_user()

        NotificationModel().create(created_by=u1, subject=u'test_notification_1',
                                   body=u'notification_1',
                                   recipients=[cur_user])
        self.Session().commit()
        response = self.app.get(url('notifications'))
        response.mustcontain(u'test_notification_1')

#    def test_index_as_xml(self):
#        response = self.app.get(url('formatted_notifications', format='xml'))
#
#    def test_create(self):
#        response = self.app.post(url('notifications'))
#
#    def test_new(self):
#        response = self.app.get(url('new_notification'))
#
#    def test_new_as_xml(self):
#        response = self.app.get(url('formatted_new_notification', format='xml'))
#
#    def test_update(self):
#        response = self.app.put(url('notification', notification_id=1))
#
#    def test_update_browser_fakeout(self):
#        response = self.app.post(url('notification', notification_id=1), params=dict(_method='put'))

    def test_delete(self):
        self.log_user()
        cur_user = self._get_logged_user()

        u1 = UserModel().create_or_update(username='u1', password='qweqwe',
                                               email='u1@rhodecode.org',
                                               firstname='u1', lastname='u1')
        u2 = UserModel().create_or_update(username='u2', password='qweqwe',
                                               email='u2@rhodecode.org',
                                               firstname='u2', lastname='u2')

        # make notifications
        notification = NotificationModel().create(created_by=cur_user,
                                                  subject=u'test',
                                                  body=u'hi there',
                                                  recipients=[cur_user, u1, u2])
        self.Session().commit()
        u1 = User.get(u1.user_id)
        u2 = User.get(u2.user_id)

        # check DB
        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=
                                       notification.notification_id))
        self.assertEqual(response.body, 'ok')

        cur_user = User.get(cur_usr_id)
        self.assertEqual(cur_user.notifications, [])

    def test_show(self):
        self.log_user()
        cur_user = self._get_logged_user()
        u1 = UserModel().create_or_update(username='u1', password='qweqwe',
                                               email='u1@rhodecode.org',
                                               firstname='u1', lastname='u1')
        u2 = UserModel().create_or_update(username='u2', password='qweqwe',
                                               email='u2@rhodecode.org',
                                               firstname='u2', lastname='u2')

        notification = NotificationModel().create(created_by=cur_user,
                                                  subject=u'test',
                                                  body=u'hi there',
                                                  recipients=[cur_user, u1, u2])

        response = self.app.get(url('notification',
                                    notification_id=notification.notification_id))