1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Improved test isolation of the admin tests and assigned custom admin sites to

prevent test order dependant failures.

This involves introducing usage of `TestCase.urls` and implementing proper
admin.py modules for some of the test apps.

Thanks Florian Apolloner for finding the issue and contributing the patch.

Refs #15294 (it solves these problems so the fix for that ticket we are going
to commit doesn't introduce obscure and hard to reproduce test failures when
running the Django test suite.)

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16856 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Ramiro Morales
2011-09-20 18:16:49 +00:00
parent fc06ec0daf
commit 7b21bfc074
18 changed files with 904 additions and 630 deletions

View File

@@ -1,13 +1,14 @@
from django.db import models
from django.contrib import admin
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
class Episode(models.Model):
name = models.CharField(max_length=100)
length = models.CharField(max_length=100, blank=True)
author = models.CharField(max_length=100, blank=True)
class Media(models.Model):
"""
Media that can associated to any object.
@@ -22,15 +23,6 @@ class Media(models.Model):
def __unicode__(self):
return self.url
class MediaInline(generic.GenericTabularInline):
model = Media
class EpisodeAdmin(admin.ModelAdmin):
inlines = [
MediaInline,
]
admin.site.register(Episode, EpisodeAdmin)
#
# These models let us test the different GenericInline settings at
# different urls in the admin site.
@@ -43,34 +35,21 @@ admin.site.register(Episode, EpisodeAdmin)
class EpisodeExtra(Episode):
pass
class MediaExtraInline(generic.GenericTabularInline):
model = Media
extra = 0
admin.site.register(EpisodeExtra, inlines=[MediaExtraInline])
#
# Generic inline with extra and max_num
#
class EpisodeMaxNum(Episode):
pass
class MediaMaxNumInline(generic.GenericTabularInline):
model = Media
extra = 5
max_num = 2
admin.site.register(EpisodeMaxNum, inlines=[MediaMaxNumInline])
#
# Generic inline with unique_together
#
class Category(models.Model):
name = models.CharField(max_length=50)
class PhoneNumber(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
@@ -81,25 +60,15 @@ class PhoneNumber(models.Model):
class Meta:
unique_together = (('content_type', 'object_id', 'phone_number',),)
class Contact(models.Model):
name = models.CharField(max_length=50)
phone_numbers = generic.GenericRelation(PhoneNumber)
class PhoneNumberInline(generic.GenericTabularInline):
model = PhoneNumber
admin.site.register(Contact, inlines=[PhoneNumberInline])
admin.site.register(Category)
#
# Generic inline with can_delete=False
#
class EpisodePermanent(Episode):
pass
class MediaPermanentInline(generic.GenericTabularInline):
model = Media
can_delete = False
admin.site.register(EpisodePermanent, inlines=[MediaPermanentInline])