Skip to content

Commit

Permalink
Added some tests to test the admin
Browse files Browse the repository at this point in the history
  • Loading branch information
epicserve committed Mar 6, 2016
1 parent bdb6278 commit 0a1e7db
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
56 changes: 56 additions & 0 deletions categories/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -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())
10 changes: 10 additions & 0 deletions example/settings-testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
)

ROOT_URLCONF = 'urls'
Expand All @@ -82,6 +83,15 @@
'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',
],
}
},
]
Expand Down

0 comments on commit 0a1e7db

Please sign in to comment.