summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-03 09:51:49 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-03 09:51:49 -0800
commit7288e1b02b2504b1694fe14df2d81e6a354c5610 (patch)
treea4bb2a34ffc03d4939c6d8f961bddc1918b8fd9c /tests/model_forms
parent91078f566904e49fbf99ec6375ba627e821f6143 (diff)
parent4f151da1e5e9bf527548a5737d9cd314e3abc68e (diff)
Merge pull request #1852 from jasonamyers/cleanup/PEP8
Cleanup/pep8 tests
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/models.py28
-rw-r--r--tests/model_forms/tests.py11
2 files changed, 36 insertions, 3 deletions
diff --git a/tests/model_forms/models.py b/tests/model_forms/models.py
index 34644a4bb9..72bf1ff26a 100644
--- a/tests/model_forms/models.py
+++ b/tests/model_forms/models.py
@@ -34,6 +34,7 @@ ARTICLE_STATUS_CHAR = (
('l', 'Live'),
)
+
@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
@@ -46,6 +47,7 @@ class Category(models.Model):
def __repr__(self):
return self.__str__()
+
@python_2_unicode_compatible
class Writer(models.Model):
name = models.CharField(max_length=50, help_text='Use both first and last names.')
@@ -56,6 +58,7 @@ class Writer(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=50)
@@ -76,15 +79,19 @@ class Article(models.Model):
def __str__(self):
return self.headline
+
class ImprovedArticle(models.Model):
article = models.OneToOneField(Article)
+
class ImprovedArticleWithParentLink(models.Model):
article = models.OneToOneField(Article, parent_link=True)
+
class BetterWriter(Writer):
score = models.IntegerField()
+
@python_2_unicode_compatible
class WriterProfile(models.Model):
writer = models.OneToOneField(Writer, primary_key=True)
@@ -93,6 +100,7 @@ class WriterProfile(models.Model):
def __str__(self):
return "%s is %s" % (self.writer, self.age)
+
@python_2_unicode_compatible
class TextFile(models.Model):
description = models.CharField(max_length=20)
@@ -144,6 +152,7 @@ try:
except ImproperlyConfigured:
test_images = False
+
@python_2_unicode_compatible
class CommaSeparatedInteger(models.Model):
field = models.CommaSeparatedIntegerField(max_length=20)
@@ -151,6 +160,7 @@ class CommaSeparatedInteger(models.Model):
def __str__(self):
return self.field
+
@python_2_unicode_compatible
class Product(models.Model):
slug = models.SlugField(unique=True)
@@ -158,6 +168,7 @@ class Product(models.Model):
def __str__(self):
return self.slug
+
@python_2_unicode_compatible
class Price(models.Model):
price = models.DecimalField(max_digits=10, decimal_places=2)
@@ -169,9 +180,11 @@ class Price(models.Model):
class Meta:
unique_together = (('price', 'quantity'),)
+
class ArticleStatus(models.Model):
status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True)
+
@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
@@ -187,6 +200,7 @@ class Inventory(models.Model):
def __repr__(self):
return self.__str__()
+
class Book(models.Model):
title = models.CharField(max_length=40)
author = models.ForeignKey(Writer, blank=True, null=True)
@@ -195,6 +209,7 @@ class Book(models.Model):
class Meta:
unique_together = ('title', 'author')
+
class BookXtra(models.Model):
isbn = models.CharField(max_length=16, unique=True)
suffix1 = models.IntegerField(blank=True, default=0)
@@ -204,9 +219,11 @@ class BookXtra(models.Model):
unique_together = (('suffix1', 'suffix2'))
abstract = True
+
class DerivedBook(Book, BookXtra):
pass
+
@python_2_unicode_compatible
class ExplicitPK(models.Model):
key = models.CharField(max_length=20, primary_key=True)
@@ -218,6 +235,7 @@ class ExplicitPK(models.Model):
def __str__(self):
return self.key
+
@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
@@ -228,6 +246,7 @@ class Post(models.Model):
def __str__(self):
return self.title
+
@python_2_unicode_compatible
class DateTimePost(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
@@ -238,9 +257,11 @@ class DateTimePost(models.Model):
def __str__(self):
return self.title
+
class DerivedPost(Post):
pass
+
@python_2_unicode_compatible
class BigInt(models.Model):
biggie = models.BigIntegerField()
@@ -248,6 +269,7 @@ class BigInt(models.Model):
def __str__(self):
return six.text_type(self.biggie)
+
class MarkupField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs["max_length"] = 20
@@ -260,16 +282,19 @@ class MarkupField(models.CharField):
# regressed at r10062
return None
+
class CustomFieldForExclusionModel(models.Model):
name = models.CharField(max_length=10)
markup = MarkupField()
+
class FlexibleDatePost(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField(blank=True, null=True)
+
@python_2_unicode_compatible
class Colour(models.Model):
name = models.CharField(max_length=50)
@@ -281,14 +306,17 @@ class Colour(models.Model):
def __str__(self):
return self.name
+
class ColourfulItem(models.Model):
name = models.CharField(max_length=50)
colours = models.ManyToManyField(Colour)
+
class ArticleStatusNote(models.Model):
name = models.CharField(max_length=20)
status = models.ManyToManyField(ArticleStatus)
+
class CustomErrorMessage(models.Model):
name1 = models.CharField(max_length=50,
validators=[validators.validate_slug],
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index a71f716264..95092c2b7a 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -185,6 +185,7 @@ class BetterWriterForm(forms.ModelForm):
model = BetterWriter
fields = '__all__'
+
class WriterProfileForm(forms.ModelForm):
class Meta:
model = WriterProfile
@@ -234,6 +235,7 @@ class ColourfulItemForm(forms.ModelForm):
# model forms for testing work on #9321:
+
class StatusNoteForm(forms.ModelForm):
class Meta:
model = ArticleStatusNote
@@ -295,7 +297,7 @@ class ModelFormBaseTest(TestCase):
fields = '__all__'
self.assertIsInstance(ReplaceField.base_fields['url'],
- forms.fields.BooleanField)
+ forms.fields.BooleanField)
def test_replace_field_variant_2(self):
# Should have the same result as before,
@@ -308,7 +310,7 @@ class ModelFormBaseTest(TestCase):
fields = ['url']
self.assertIsInstance(ReplaceField.base_fields['url'],
- forms.fields.BooleanField)
+ forms.fields.BooleanField)
def test_replace_field_variant_3(self):
# Should have the same result as before,
@@ -321,7 +323,7 @@ class ModelFormBaseTest(TestCase):
fields = [] # url will still appear, since it is explicit above
self.assertIsInstance(ReplaceField.base_fields['url'],
- forms.fields.BooleanField)
+ forms.fields.BooleanField)
def test_override_field(self):
class WriterForm(forms.ModelForm):
@@ -583,6 +585,7 @@ class IncompleteCategoryFormWithFields(forms.ModelForm):
fields = ('name', 'slug')
model = Category
+
class IncompleteCategoryFormWithExclude(forms.ModelForm):
"""
A form that replaces the model's url field with a custom one. This should
@@ -788,6 +791,7 @@ class UniqueTest(TestCase):
"slug": "Django 1.0"}, instance=p)
self.assertTrue(form.is_valid())
+
class ModelToDictTests(TestCase):
"""
Tests for forms.models.model_to_dict
@@ -859,6 +863,7 @@ class ModelToDictTests(TestCase):
#Ensure many-to-many relation appears as a list
self.assertIsInstance(d['categories'], list)
+
class OldFormForXTests(TestCase):
def test_base_form(self):
self.assertEqual(Category.objects.count(), 0)