예제 #1
0
 def setUp(self):
     self.note = M.SiteNotification(active=True,
                                    impressions=0,
                                    content='test',
                                    page_regex='',
                                    page_tool_type='',
                                    user_role='')
예제 #2
0
    def test_notification(self, _get_site_notification):
        user = M.User.by_username('test-admin')
        note = M.SiteNotification()
        cookie = '{}-1-False'.format(note._id)
        g.theme._get_site_notification = mock.Mock(return_value=(note, cookie))

        r = self.app.get(
            '/rest/notification?url=test_url&cookie=test_cookie&tool_name=test_tool'
        )
        g.theme._get_site_notification.assert_called_once_with(
            url='test_url',
            user=user,
            tool_name='test_tool',
            site_notification_cookie_value='test_cookie')

        assert r.status_int == 200
        assert r.json['cookie'] == cookie
        assert r.json['notification'] == note.__json__()

        g.theme._get_site_notification = mock.Mock(return_value=None)
        r = self.app.get('/rest/notification')
        assert r.json == {}