| | 1 | # coding: utf-8 |
| | 2 | |
| | 3 | from django.test import TestCase |
| | 4 | from django.contrib.auth.models import User |
| | 5 | |
| | 6 | # local test models |
| | 7 | from models import Article, Section |
| | 8 | |
| | 9 | class GenericAdminViewTest(TestCase): |
| | 10 | fixtures = ['fixtures.xml'] |
| | 11 | def setUp(self): |
| | 12 | # new_user = User.objects.create_superuser(username='super', |
| | 13 | # email='super@test.com', |
| | 14 | # password='secret') |
| | 15 | self.client.login(username='super', password='secret') |
| | 16 | |
| | 17 | def tearDown(self): |
| | 18 | self.client.logout() |
| | 19 | |
| | 20 | def testBasicAddGet(self): |
| | 21 | """ |
| | 22 | A smoke test to ensure GET on the add_view works. |
| | 23 | """ |
| | 24 | response = self.client.get('/test_admin/admin/generic_inline_admin/section/add/') |
| | 25 | self.failUnlessEqual(response.status_code, 200) |
| | 26 | |
| | 27 | def testBasicEditGet(self): |
| | 28 | """ |
| | 29 | A smoke test to ensureGET on the change_view works. |
| | 30 | """ |
| | 31 | response = self.client.get('/test_admin/admin/generic_inline_admin/section/1/') |
| | 32 | self.failUnlessEqual(response.status_code, 200) |
| | 33 | |
| | 34 | def testBasicAddPost(self): |
| | 35 | """ |
| | 36 | A smoke test to ensure POST on add_view works. |
| | 37 | """ |
| | 38 | post_data = { |
| | 39 | "name": u"Another Section", |
| | 40 | # inline data |
| | 41 | "generic_inline_admin-article-content_type-object_id-TOTAL_FORMS": u"3", |
| | 42 | "generic_inline_admin-article-content_type-object_id-INITIAL_FORMS": u"0", |
| | 43 | } |
| | 44 | response = self.client.post('/test_admin/admin/generic_inline_admin/section/add/', post_data) |
| | 45 | self.failUnlessEqual(response.status_code, 302) # redirect somewhere |
| | 46 | |
| | 47 | def testBasicEditPost(self): |
| | 48 | """ |
| | 49 | A smoke test to ensure POST on edit_view works. |
| | 50 | """ |
| | 51 | post_data = { |
| | 52 | "name": u"Test section", |
| | 53 | # inline data |
| | 54 | "generic_inline_admin-article-content_type-object_id-TOTAL_FORMS": u"3", |
| | 55 | "generic_inline_admin-article-content_type-object_id-INITIAL_FORMS": u"0", |
| | 56 | "generic_inline_admin-article-content_type-object_id-0-id": u"1", |
| | 57 | # there is no title in database, give one here or formset |
| | 58 | # will fail. |
| | 59 | "generic_inline_admin-article-content_type-object_id-0-title": u"Need a title.", |
| | 60 | "generic_inline_admin-article-content_type-object_id-0-content": u"<p>test content</p>", |
| | 61 | "generic_inline_admin-article-content_type-object_id-0-date_0": u"2008-03-18", |
| | 62 | "generic_inline_admin-article-content_type-object_id-0-date_1": u"11:54:58", |
| | 63 | "generic_inline_admin-article-content_type-object_id-1-id": u"", |
| | 64 | "generic_inline_admin-article-content_type-object_id-1-title": u"", |
| | 65 | "generic_inline_admin-article-content_type-object_id-1-content": u"", |
| | 66 | "generic_inline_admin-article-content_type-object_id-1-date_0": u"", |
| | 67 | "generic_inline_admin-article-content_type-object_id-1-date_1": u"", |
| | 68 | "generic_inline_admin-article-content_type-object_id-2-id": u"", |
| | 69 | "generic_inline_admin-article-content_type-object_id-2-title": u"", |
| | 70 | "generic_inline_admin-article-content_type-object_id-2-content": u"", |
| | 71 | "generic_inline_admin-article-content_type-object_id-2-date_0": u"", |
| | 72 | "generic_inline_admin-article-content_type-object_id-2-date_1": u"", |
| | 73 | "generic_inline_admin-article-content_type-object_id-3-id": u"", |
| | 74 | "generic_inline_admin-article-content_type-object_id-3-title": u"", |
| | 75 | "generic_inline_admin-article-content_type-object_id-3-content": u"", |
| | 76 | "generic_inline_admin-article-content_type-object_id-3-date_0": u"", |
| | 77 | "generic_inline_admin-article-content_type-object_id-3-date_1": u"", |
| | 78 | } |
| | 79 | response = self.client.post('/test_admin/admin/generic_inline_admin/section/1/', post_data) |
| | 80 | self.failUnlessEqual(response.status_code, 302) # redirect somewhere |