Ticket #9498: generic_inline_tests.diff

File generic_inline_tests.diff, 6.1 KB (added by Daniel Roseman, 16 years ago)
  • tests/regressiontests/generic_inline_admin/tests.py

     
     1# coding: utf-8
     2
     3from django.test import TestCase
     4from django.contrib.auth.models import User
     5
     6# local test models
     7from models import Article, Section
     8
     9class 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
  • tests/regressiontests/generic_inline_admin/models.py

     
     1from django.db import models
     2from django.contrib import admin
     3from django.contrib.contenttypes import generic
     4from django.contrib.contenttypes.models import ContentType
     5
     6class Section(models.Model):
     7    """
     8    A simple section that links to articles, to test linking to related items
     9    in admin views.
     10    """
     11    name = models.CharField(max_length=100)
     12
     13class Article(models.Model):
     14    """
     15    A simple article to test admin views. Test backwards compatibility.
     16    """
     17    title = models.CharField(max_length=100)
     18    content = models.TextField()
     19    date = models.DateTimeField()
     20    content_type = models.ForeignKey(ContentType)
     21    object_id = models.PositiveIntegerField()
     22    content_object = generic.GenericForeignKey()
     23
     24    def __unicode__(self):
     25        return self.title
     26
     27class ArticleInline(generic.GenericTabularInline):
     28    model = Article
     29   
     30class SectionAdmin(admin.ModelAdmin):
     31    inlines=[ArticleInline]
     32
     33admin.site.register(Section, SectionAdmin)
  • tests/regressiontests/generic_inline_admin/urls.py

     
     1from django.conf.urls.defaults import *
     2from django.contrib import admin
     3
     4urlpatterns = patterns('',
     5    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
     6    (r'^admin/(.*)', admin.site.root),
     7)
Back to Top