mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Added some tests to test the admin
This commit is contained in:
parent
bdb6278559
commit
0a1e7db9a6
2 changed files with 66 additions and 0 deletions
56
categories/tests/test_admin.py
Normal file
56
categories/tests/test_admin.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from categories.models import Category
|
||||
|
||||
|
||||
class TestCategoryAdmin(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.client = Client()
|
||||
|
||||
def test_adding_parent_and_child(self):
|
||||
User.objects.create_superuser('testuser', 'testuser@example.com', 'password')
|
||||
self.client.login(username='testuser', password='password')
|
||||
url = reverse('admin:categories_category_add')
|
||||
data = {
|
||||
'parent': '',
|
||||
'name': "Parent",
|
||||
'thumbnail': '',
|
||||
'filename': '',
|
||||
'active': 'on',
|
||||
'alternate_title': '',
|
||||
'alternate_url': '',
|
||||
'description': '',
|
||||
'meta_keywords': '',
|
||||
'meta_extra': '',
|
||||
'order': 0,
|
||||
'slug': 'parent',
|
||||
'_save': '_save',
|
||||
}
|
||||
resp = self.client.post(url, data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertEqual(1, Category.objects.count())
|
||||
|
||||
# update parent
|
||||
data.update({'name': 'Parent (Changed)'})
|
||||
resp = self.client.post(reverse('admin:categories_category_change', args=(1,)), data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertEqual(1, Category.objects.count())
|
||||
|
||||
# add a child
|
||||
data.update({
|
||||
'parent': '1',
|
||||
'name': 'Child',
|
||||
'slug': 'child',
|
||||
})
|
||||
resp = self.client.post(url, data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertEqual(2, Category.objects.count())
|
||||
|
||||
# update child
|
||||
data.update({'name': 'Child (Changed)'})
|
||||
resp = self.client.post(reverse('admin:categories_category_change', args=(2,)), data=data)
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertEqual(2, Category.objects.count())
|
||||
|
|
@ -71,6 +71,7 @@ MIDDLEWARE_CLASSES = (
|
|||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'urls'
|
||||
|
|
@ -82,6 +83,15 @@ TEMPLATES = [
|
|||
'DIRS': [os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates'))],
|
||||
'OPTIONS': {
|
||||
'debug': DEBUG,
|
||||
'context_processors': [
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.i18n',
|
||||
'django.template.context_processors.media',
|
||||
'django.template.context_processors.static',
|
||||
'django.template.context_processors.tz',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
],
|
||||
}
|
||||
},
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue