summaryrefslogtreecommitdiff
path: root/parts/django/tests/regressiontests/admin_validation
diff options
context:
space:
mode:
authorNishanth Amuluru2011-01-08 11:20:57 +0530
committerNishanth Amuluru2011-01-08 11:20:57 +0530
commit65411d01d448ff0cd4abd14eee14cf60b5f8fc20 (patch)
treeb4c404363c4c63a61d6e2f8bd26c5b057c1fb09d /parts/django/tests/regressiontests/admin_validation
parent2e35094d43b4cc6974172e1febf76abb50f086ec (diff)
downloadpytask-65411d01d448ff0cd4abd14eee14cf60b5f8fc20.tar.gz
pytask-65411d01d448ff0cd4abd14eee14cf60b5f8fc20.tar.bz2
pytask-65411d01d448ff0cd4abd14eee14cf60b5f8fc20.zip
Added buildout stuff and made changes accordingly
--HG-- rename : profile/management/__init__.py => eggs/djangorecipe-0.20-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/djangorecipe-0.20-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/infrae.subversion-1.4.5-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/infrae.subversion-1.4.5-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/mercurial-1.7.3-py2.6-linux-x86_64.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/mercurial-1.7.3-py2.6-linux-x86_64.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/py-1.4.0-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/py-1.4.0-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/zc.buildout-1.5.2-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/zc.buildout-1.5.2-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => eggs/zc.recipe.egg-1.3.2-py2.6.egg/EGG-INFO/dependency_links.txt rename : profile/management/__init__.py => eggs/zc.recipe.egg-1.3.2-py2.6.egg/EGG-INFO/not-zip-safe rename : profile/management/__init__.py => parts/django/Django.egg-info/dependency_links.txt rename : taskapp/models.py => parts/django/django/conf/app_template/models.py rename : taskapp/tests.py => parts/django/django/conf/app_template/tests.py rename : taskapp/views.py => parts/django/django/conf/app_template/views.py rename : taskapp/views.py => parts/django/django/contrib/gis/tests/geo3d/views.py rename : profile/management/__init__.py => parts/django/tests/modeltests/delete/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/files/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/invalid_models/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/m2m_signals/__init__.py rename : profile/management/__init__.py => parts/django/tests/modeltests/model_package/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/management/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/management/commands/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/bash_completion/models.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/delete_regress/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/file_storage/__init__.py rename : profile/management/__init__.py => parts/django/tests/regressiontests/max_lengths/__init__.py rename : profile/forms.py => pytask/profile/forms.py rename : profile/management/__init__.py => pytask/profile/management/__init__.py rename : profile/management/commands/seed_db.py => pytask/profile/management/commands/seed_db.py rename : profile/models.py => pytask/profile/models.py rename : profile/templatetags/user_tags.py => pytask/profile/templatetags/user_tags.py rename : taskapp/tests.py => pytask/profile/tests.py rename : profile/urls.py => pytask/profile/urls.py rename : profile/utils.py => pytask/profile/utils.py rename : profile/views.py => pytask/profile/views.py rename : static/css/base.css => pytask/static/css/base.css rename : taskapp/tests.py => pytask/taskapp/tests.py rename : taskapp/views.py => pytask/taskapp/views.py rename : templates/base.html => pytask/templates/base.html rename : templates/profile/browse_notifications.html => pytask/templates/profile/browse_notifications.html rename : templates/profile/edit.html => pytask/templates/profile/edit.html rename : templates/profile/view.html => pytask/templates/profile/view.html rename : templates/profile/view_notification.html => pytask/templates/profile/view_notification.html rename : templates/registration/activate.html => pytask/templates/registration/activate.html rename : templates/registration/activation_email.txt => pytask/templates/registration/activation_email.txt rename : templates/registration/activation_email_subject.txt => pytask/templates/registration/activation_email_subject.txt rename : templates/registration/logged_out.html => pytask/templates/registration/logged_out.html rename : templates/registration/login.html => pytask/templates/registration/login.html rename : templates/registration/logout.html => pytask/templates/registration/logout.html rename : templates/registration/password_change_done.html => pytask/templates/registration/password_change_done.html rename : templates/registration/password_change_form.html => pytask/templates/registration/password_change_form.html rename : templates/registration/password_reset_complete.html => pytask/templates/registration/password_reset_complete.html rename : templates/registration/password_reset_confirm.html => pytask/templates/registration/password_reset_confirm.html rename : templates/registration/password_reset_done.html => pytask/templates/registration/password_reset_done.html rename : templates/registration/password_reset_email.html => pytask/templates/registration/password_reset_email.html rename : templates/registration/password_reset_form.html => pytask/templates/registration/password_reset_form.html rename : templates/registration/registration_complete.html => pytask/templates/registration/registration_complete.html rename : templates/registration/registration_form.html => pytask/templates/registration/registration_form.html rename : utils.py => pytask/utils.py
Diffstat (limited to 'parts/django/tests/regressiontests/admin_validation')
-rw-r--r--parts/django/tests/regressiontests/admin_validation/__init__.py0
-rw-r--r--parts/django/tests/regressiontests/admin_validation/models.py47
-rw-r--r--parts/django/tests/regressiontests/admin_validation/tests.py247
3 files changed, 294 insertions, 0 deletions
diff --git a/parts/django/tests/regressiontests/admin_validation/__init__.py b/parts/django/tests/regressiontests/admin_validation/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/parts/django/tests/regressiontests/admin_validation/__init__.py
diff --git a/parts/django/tests/regressiontests/admin_validation/models.py b/parts/django/tests/regressiontests/admin_validation/models.py
new file mode 100644
index 0000000..24387cc
--- /dev/null
+++ b/parts/django/tests/regressiontests/admin_validation/models.py
@@ -0,0 +1,47 @@
+"""
+Tests of ModelAdmin validation logic.
+"""
+
+from django.db import models
+
+
+class Album(models.Model):
+ title = models.CharField(max_length=150)
+
+
+class Song(models.Model):
+ title = models.CharField(max_length=150)
+ album = models.ForeignKey(Album)
+ original_release = models.DateField(editable=False)
+
+ class Meta:
+ ordering = ('title',)
+
+ def __unicode__(self):
+ return self.title
+
+ def readonly_method_on_model(self):
+ # does nothing
+ pass
+
+
+class TwoAlbumFKAndAnE(models.Model):
+ album1 = models.ForeignKey(Album, related_name="album1_set")
+ album2 = models.ForeignKey(Album, related_name="album2_set")
+ e = models.CharField(max_length=1)
+
+
+class Author(models.Model):
+ name = models.CharField(max_length=100)
+
+
+class Book(models.Model):
+ name = models.CharField(max_length=100)
+ subtitle = models.CharField(max_length=100)
+ price = models.FloatField()
+ authors = models.ManyToManyField(Author, through='AuthorsBooks')
+
+
+class AuthorsBooks(models.Model):
+ author = models.ForeignKey(Author)
+ book = models.ForeignKey(Book)
diff --git a/parts/django/tests/regressiontests/admin_validation/tests.py b/parts/django/tests/regressiontests/admin_validation/tests.py
new file mode 100644
index 0000000..1872ca5
--- /dev/null
+++ b/parts/django/tests/regressiontests/admin_validation/tests.py
@@ -0,0 +1,247 @@
+from django.contrib import admin
+from django import forms
+from django.contrib.admin.validation import validate, validate_inline, \
+ ImproperlyConfigured
+from django.test import TestCase
+
+from models import Song, Book, Album, TwoAlbumFKAndAnE
+
+class SongForm(forms.ModelForm):
+ pass
+
+class ValidFields(admin.ModelAdmin):
+ form = SongForm
+ fields = ['title']
+
+class InvalidFields(admin.ModelAdmin):
+ form = SongForm
+ fields = ['spam']
+
+class ValidationTestCase(TestCase):
+ def assertRaisesMessage(self, exc, msg, func, *args, **kwargs):
+ try:
+ func(*args, **kwargs)
+ except Exception, e:
+ self.assertEqual(msg, str(e))
+ self.assertTrue(isinstance(e, exc), "Expected %s, got %s" % (exc, type(e)))
+
+ def test_readonly_and_editable(self):
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = ["original_release"]
+ fieldsets = [
+ (None, {
+ "fields": ["title", "original_release"],
+ }),
+ ]
+ validate(SongAdmin, Song)
+
+ def test_custom_modelforms_with_fields_fieldsets(self):
+ """
+ # Regression test for #8027: custom ModelForms with fields/fieldsets
+ """
+ validate(ValidFields, Song)
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "'InvalidFields.fields' refers to field 'spam' that is missing from the form.",
+ validate,
+ InvalidFields, Song)
+
+ def test_exclude_values(self):
+ """
+ Tests for basic validation of 'exclude' option values (#12689)
+ """
+ class ExcludedFields1(admin.ModelAdmin):
+ exclude = ('foo')
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "'ExcludedFields1.exclude' must be a list or tuple.",
+ validate,
+ ExcludedFields1, Book)
+
+ def test_exclude_duplicate_values(self):
+ class ExcludedFields2(admin.ModelAdmin):
+ exclude = ('name', 'name')
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "There are duplicate field(s) in ExcludedFields2.exclude",
+ validate,
+ ExcludedFields2, Book)
+
+ def test_exclude_in_inline(self):
+ class ExcludedFieldsInline(admin.TabularInline):
+ model = Song
+ exclude = ('foo')
+
+ class ExcludedFieldsAlbumAdmin(admin.ModelAdmin):
+ model = Album
+ inlines = [ExcludedFieldsInline]
+
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "'ExcludedFieldsInline.exclude' must be a list or tuple.",
+ validate,
+ ExcludedFieldsAlbumAdmin, Album)
+
+ def test_exclude_inline_model_admin(self):
+ """
+ # Regression test for #9932 - exclude in InlineModelAdmin
+ # should not contain the ForeignKey field used in ModelAdmin.model
+ """
+ class SongInline(admin.StackedInline):
+ model = Song
+ exclude = ['album']
+
+ class AlbumAdmin(admin.ModelAdmin):
+ model = Album
+ inlines = [SongInline]
+
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "SongInline cannot exclude the field 'album' - this is the foreign key to the parent model Album.",
+ validate,
+ AlbumAdmin, Album)
+
+ def test_fk_exclusion(self):
+ """
+ Regression test for #11709 - when testing for fk excluding (when exclude is
+ given) make sure fk_name is honored or things blow up when there is more
+ than one fk to the parent model.
+ """
+ class TwoAlbumFKAndAnEInline(admin.TabularInline):
+ model = TwoAlbumFKAndAnE
+ exclude = ("e",)
+ fk_name = "album1"
+ validate_inline(TwoAlbumFKAndAnEInline, None, Album)
+
+ def test_inline_self_validation(self):
+ class TwoAlbumFKAndAnEInline(admin.TabularInline):
+ model = TwoAlbumFKAndAnE
+
+ self.assertRaisesMessage(Exception,
+ "<class 'regressiontests.admin_validation.models.TwoAlbumFKAndAnE'> has more than 1 ForeignKey to <class 'regressiontests.admin_validation.models.Album'>",
+ validate_inline,
+ TwoAlbumFKAndAnEInline, None, Album)
+
+ def test_inline_with_specified(self):
+ class TwoAlbumFKAndAnEInline(admin.TabularInline):
+ model = TwoAlbumFKAndAnE
+ fk_name = "album1"
+ validate_inline(TwoAlbumFKAndAnEInline, None, Album)
+
+ def test_readonly(self):
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = ("title",)
+
+ validate(SongAdmin, Song)
+
+ def test_readonly_on_method(self):
+ def my_function(obj):
+ pass
+
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = (my_function,)
+
+ validate(SongAdmin, Song)
+
+ def test_readonly_on_modeladmin(self):
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = ("readonly_method_on_modeladmin",)
+
+ def readonly_method_on_modeladmin(self, obj):
+ pass
+
+ validate(SongAdmin, Song)
+
+ def test_readonly_method_on_model(self):
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = ("readonly_method_on_model",)
+
+ validate(SongAdmin, Song)
+
+ def test_nonexistant_field(self):
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = ("title", "nonexistant")
+
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "SongAdmin.readonly_fields[1], 'nonexistant' is not a callable or an attribute of 'SongAdmin' or found in the model 'Song'.",
+ validate,
+ SongAdmin, Song)
+
+ def test_extra(self):
+ class SongAdmin(admin.ModelAdmin):
+ def awesome_song(self, instance):
+ if instance.title == "Born to Run":
+ return "Best Ever!"
+ return "Status unknown."
+ validate(SongAdmin, Song)
+
+ def test_readonly_lambda(self):
+ class SongAdmin(admin.ModelAdmin):
+ readonly_fields = (lambda obj: "test",)
+
+ validate(SongAdmin, Song)
+
+ def test_graceful_m2m_fail(self):
+ """
+ Regression test for #12203/#12237 - Fail more gracefully when a M2M field that
+ specifies the 'through' option is included in the 'fields' or the 'fieldsets'
+ ModelAdmin options.
+ """
+
+ class BookAdmin(admin.ModelAdmin):
+ fields = ['authors']
+
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
+ validate,
+ BookAdmin, Book)
+
+ def test_cannon_include_through(self):
+ class FieldsetBookAdmin(admin.ModelAdmin):
+ fieldsets = (
+ ('Header 1', {'fields': ('name',)}),
+ ('Header 2', {'fields': ('authors',)}),
+ )
+ self.assertRaisesMessage(ImproperlyConfigured,
+ "'FieldsetBookAdmin.fieldsets[1][1]['fields']' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.",
+ validate,
+ FieldsetBookAdmin, Book)
+
+ def test_nested_fieldsets(self):
+ class NestedFieldsetAdmin(admin.ModelAdmin):
+ fieldsets = (
+ ('Main', {'fields': ('price', ('name', 'subtitle'))}),
+ )
+ validate(NestedFieldsetAdmin, Book)
+
+ def test_explicit_through_override(self):
+ """
+ Regression test for #12209 -- If the explicitly provided through model
+ is specified as a string, the admin should still be able use
+ Model.m2m_field.through
+ """
+
+ class AuthorsInline(admin.TabularInline):
+ model = Book.authors.through
+
+ class BookAdmin(admin.ModelAdmin):
+ inlines = [AuthorsInline]
+
+ # If the through model is still a string (and hasn't been resolved to a model)
+ # the validation will fail.
+ validate(BookAdmin, Book)
+
+ def test_non_model_fields(self):
+ """
+ Regression for ensuring ModelAdmin.fields can contain non-model fields
+ that broke with r11737
+ """
+ class SongForm(forms.ModelForm):
+ extra_data = forms.CharField()
+ class Meta:
+ model = Song
+
+ class FieldsOnFormOnlyAdmin(admin.ModelAdmin):
+ form = SongForm
+ fields = ['title', 'extra_data']
+
+ validate(FieldsOnFormOnlyAdmin, Song)
+
+
+
+