mirror of
https://github.com/haiwen/seahub.git
synced 2025-04-27 19:05:16 +00:00
Add notification unit tests
This commit is contained in:
parent
12da94589d
commit
a14c1d0c48
@ -1,23 +1,97 @@
|
||||
"""
|
||||
This file demonstrates writing tests using the unittest module. These will pass
|
||||
when you run "manage.py test".
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import TestCase, Client
|
||||
|
||||
Replace this with more appropriate tests for your application.
|
||||
"""
|
||||
from models import Notification
|
||||
from base.accounts import User
|
||||
|
||||
# from django.test import TestCase
|
||||
class NotificationTestCase(TestCase):
|
||||
"""
|
||||
Helper base class for all the follow test cases.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.new_notification = 'This is a new notification!'
|
||||
self.user = User.objects.create_superuser('admin@admin.com', 'testpassword')
|
||||
|
||||
def tearDown(self):
|
||||
self.user.delete()
|
||||
|
||||
# class SimpleTest(TestCase):
|
||||
# def test_basic_addition(self):
|
||||
# """
|
||||
# Tests that 1 + 1 always equals 2.
|
||||
# """
|
||||
# self.assertEqual(1 + 1, 2)
|
||||
class NotificationTest(NotificationTestCase):
|
||||
|
||||
def login(self):
|
||||
response = self.client.post('/accounts/login/', {
|
||||
'username': 'admin@admin.com',
|
||||
'password': 'testpassword',
|
||||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
from django.utils import unittest
|
||||
def test_add_new_notification(self):
|
||||
self.login()
|
||||
r = self.client.get('/sys/notificationadmin/')
|
||||
# Check that response is 200 OK
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
# now there are no notifications
|
||||
self.assertEqual(len(r.context['notes']), 0)
|
||||
|
||||
# try add one notification
|
||||
r = self.client.post('/notification/add/', {
|
||||
'message': self.new_notification,
|
||||
})
|
||||
# Redirect only if it worked
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
# look up in database
|
||||
notifications = Notification.objects.all()
|
||||
self.assertEqual(notifications.count(), 1)
|
||||
|
||||
# check this notification is not set primary, thus will not showed
|
||||
# in top bar
|
||||
n = Notification.objects.all()[0]
|
||||
self.assertFalse(n.primary)
|
||||
|
||||
def test_set_primary(self):
|
||||
n = Notification()
|
||||
n.message = self.new_notification
|
||||
n.primary = False
|
||||
n.save()
|
||||
|
||||
# set primary
|
||||
self.login()
|
||||
r = self.client.get(reverse('set_primary', args=[n.id]), {})
|
||||
# Redirect only if it worked
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
# now check it's primary
|
||||
n = Notification.objects.all()[0]
|
||||
self.assertTrue(n.primary)
|
||||
|
||||
# check it's showed in top bar
|
||||
r = self.client.get('/sys/notificationadmin/')
|
||||
self.assert_('This is a new notification!' in str(r))
|
||||
|
||||
# and it's still there when reach other pages
|
||||
r = self.client.get('/home/my/')
|
||||
self.assert_('This is a new notification!' in str(r))
|
||||
|
||||
def test_close_notification(self):
|
||||
n = Notification()
|
||||
n.message = self.new_notification
|
||||
n.primary = True
|
||||
n.save()
|
||||
|
||||
self.login()
|
||||
r = self.client.get('/home/my/')
|
||||
self.assert_('This is a new notification!' in str(r))
|
||||
|
||||
# now close notification
|
||||
r = self.client.get(reverse('notification_close', args=[1]), {})
|
||||
# Redirect only if it worked
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
# it's gone
|
||||
self.assert_('This is a new notification!' not in str(r))
|
||||
|
||||
# and it's gone when reach other pages
|
||||
r = self.client.get('/home/my/')
|
||||
self.assert_('This is a new notification!' not in str(r))
|
||||
|
||||
class SimpleTestCase(unittest.TestCase):
|
||||
def test_base_addition(self):
|
||||
self.assertEqual(1 + 1, 2)
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
. setenv.sh
|
||||
|
||||
./manage.py test base avatar group -v 2
|
||||
./manage.py test base avatar group notifications
|
||||
|
||||
echo $?
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user