Permalink
Browse files

Revert "Began implementing a shared set of test models to speed up te…

…sts."

This reverts commit 22b7870.
  • Loading branch information...
1 parent dfcce42 commit f5d4849cbeda994e7d2e43c4aaf2aac69d5c95bb @apollo13 apollo13 committed Jun 10, 2013
Showing with 215 additions and 206 deletions.
  1. +144 −140 tests/lookup/tests.py
  2. +22 −5 tests/model_forms/models.py
  3. +42 −47 tests/model_forms/tests.py
  4. +5 −12 tests/shared_models/models.py
  5. +2 −2 tests/signals_regress/tests.py
View
Oops, something went wrong.
@@ -17,7 +17,6 @@
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
-from shared_models.models import Author, Book
temp_storage_dir = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
temp_storage = FileSystemStorage(temp_storage_dir)
@@ -47,12 +46,22 @@ 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.')
+
+ class Meta:
+ ordering = ('name',)
+
+ def __str__(self):
+ return self.name
+
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=50)
slug = models.SlugField()
pub_date = models.DateField()
created = models.DateField(editable=False)
- writer = models.ForeignKey(Author)
+ writer = models.ForeignKey(Writer)
article = models.TextField()
categories = models.ManyToManyField(Category, blank=True)
status = models.PositiveIntegerField(choices=ARTICLE_STATUS, blank=True, null=True)
@@ -72,12 +81,12 @@ class ImprovedArticle(models.Model):
class ImprovedArticleWithParentLink(models.Model):
article = models.OneToOneField(Article, parent_link=True)
-class BetterAuthor(Author):
+class BetterWriter(Writer):
score = models.IntegerField()
@python_2_unicode_compatible
-class AuthorProfile(models.Model):
- writer = models.OneToOneField(Author, primary_key=True)
+class WriterProfile(models.Model):
+ writer = models.OneToOneField(Writer, primary_key=True)
age = models.PositiveIntegerField()
def __str__(self):
@@ -177,6 +186,14 @@ def __str__(self):
def __repr__(self):
return self.__str__()
+class Book(models.Model):
+ title = models.CharField(max_length=40)
+ author = models.ForeignKey(Writer, blank=True, null=True)
+ special_id = models.IntegerField(blank=True, null=True, unique=True)
+
+ 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)
@@ -17,13 +17,11 @@
from django.test import TestCase
from django.utils import six
-from shared_models.models import Author, Book
-
-from .models import (Article, ArticleStatus, BetterAuthor, BigInt,
+from .models import (Article, ArticleStatus, BetterWriter, BigInt, Book,
Category, CommaSeparatedInteger, CustomFieldForExclusionModel, DerivedBook,
DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
ImprovedArticleWithParentLink, Inventory, Post, Price,
- Product, TextFile, AuthorProfile, Colour, ColourfulItem,
+ Product, TextFile, Writer, WriterProfile, Colour, ColourfulItem,
ArticleStatusNote, DateTimePost, test_images)
if test_images:
@@ -54,13 +52,11 @@ class Meta:
class BookForm(forms.ModelForm):
class Meta:
- fields = ['title', 'author', 'pubdate']
- model = Book
+ model = Book
class DerivedBookForm(forms.ModelForm):
class Meta:
- fields = ['title', 'author', 'isbn', 'suffix1', 'suffix2']
model = DerivedBook
@@ -88,11 +84,11 @@ class Meta:
fields = '__all__'
-class CustomAuthorForm(forms.ModelForm):
+class CustomWriterForm(forms.ModelForm):
name = forms.CharField(required=False)
class Meta:
- model = Author
+ model = Writer
fields = '__all__'
@@ -128,7 +124,7 @@ class Meta:
class RoykoForm(forms.ModelForm):
class Meta:
- model = Author
+ model = Writer
fields = '__all__'
@@ -188,15 +184,14 @@ class Meta:
fields = '__all__'
-class BetterAuthorForm(forms.ModelForm):
+class BetterWriterForm(forms.ModelForm):
class Meta:
- model = BetterAuthor
+ model = BetterWriter
fields = '__all__'
-
-class AuthorProfileForm(forms.ModelForm):
+class WriterProfileForm(forms.ModelForm):
class Meta:
- model = AuthorProfile
+ model = WriterProfile
fields = '__all__'
@@ -324,14 +319,14 @@ class Meta:
forms.fields.BooleanField)
def test_override_field(self):
- class AuthorForm(forms.ModelForm):
+ class WriterForm(forms.ModelForm):
book = forms.CharField(required=False)
class Meta:
- model = Author
+ model = Writer
fields = '__all__'
- wf = AuthorForm({'name': 'Richard Lockridge'})
+ wf = WriterForm({'name': 'Richard Lockridge'})
self.assertTrue(wf.is_valid())
def test_limit_nonexistent_field(self):
@@ -556,7 +551,7 @@ def test_validates_with_replaced_field_excluded(self):
assert form.is_valid()
def test_notrequired_overrides_notblank(self):
- form = CustomAuthorForm({})
+ form = CustomWriterForm({})
assert form.is_valid()
@@ -565,7 +560,7 @@ def test_notrequired_overrides_notblank(self):
# unique/unique_together validation
class UniqueTest(TestCase):
def setUp(self):
- self.author = Author.objects.create(name='Mike Royko')
+ self.writer = Writer.objects.create(name='Mike Royko')
def test_simple_unique(self):
form = ProductForm({'slug': 'teddy-bear-blue'})
@@ -589,53 +584,53 @@ def test_unique_together(self):
def test_unique_null(self):
title = 'I May Be Wrong But I Doubt It'
- form = BookForm({'title': title, 'author': self.author.pk, 'pubdate': '2012-12-12 00:00:00'})
+ form = BookForm({'title': title, 'author': self.writer.pk})
self.assertTrue(form.is_valid())
form.save()
- form = BookForm({'title': title, 'author': self.author.pk, 'pubdate': '2012-12-12 00:00:00'})
+ form = BookForm({'title': title, 'author': self.writer.pk})
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertEqual(form.errors['__all__'], ['Book with this Title and Author already exists.'])
- form = BookForm({'title': title, 'pubdate': '2012-12-12 00:00:00'})
+ form = BookForm({'title': title})
self.assertTrue(form.is_valid())
form.save()
- form = BookForm({'title': title, 'pubdate': '2012-12-12 00:00:00'})
+ form = BookForm({'title': title})
self.assertTrue(form.is_valid())
def test_inherited_unique(self):
- form = BetterAuthorForm({'name': 'Mike Royko', 'score': 3})
+ title = 'Boss'
+ Book.objects.create(title=title, author=self.writer, special_id=1)
+ form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'special_id': '1', 'isbn': '12345'})
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
- self.assertEqual(form.errors['name'], ['Author with this Name already exists.'])
+ self.assertEqual(form.errors['special_id'], ['Book with this Special id already exists.'])
def test_inherited_unique_together(self):
title = 'Boss'
- form = BookForm({'title': title, 'author': self.author.pk, 'pubdate': '2012-12-12 00:00:00'})
+ form = BookForm({'title': title, 'author': self.writer.pk})
self.assertTrue(form.is_valid())
form.save()
- form = DerivedBookForm({'title': title, 'author': self.author.pk, 'isbn': '12345'})
+ form = DerivedBookForm({'title': title, 'author': self.writer.pk, 'isbn': '12345'})
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertEqual(form.errors['__all__'], ['Book with this Title and Author already exists.'])
def test_abstract_inherited_unique(self):
title = 'Boss'
isbn = '12345'
- dbook = DerivedBook.objects.create(title=title, author=self.author, isbn=isbn,
- pubdate='2012-12-12 00:00')
- form = DerivedBookForm({'title': 'Other', 'author': self.author.pk, 'isbn': isbn})
+ dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn)
+ form = DerivedBookForm({'title': 'Other', 'author': self.writer.pk, 'isbn': isbn})
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertEqual(form.errors['isbn'], ['Derived book with this Isbn already exists.'])
def test_abstract_inherited_unique_together(self):
title = 'Boss'
isbn = '12345'
- dbook = DerivedBook.objects.create(title=title, author=self.author, isbn=isbn,
- pubdate='2012-12-12 00:00')
+ dbook = DerivedBook.objects.create(title=title, author=self.writer, isbn=isbn)
form = DerivedBookForm({
'title': 'Other',
- 'author': self.author.pk,
+ 'author': self.writer.pk,
'isbn': '9876',
'suffix1': '0',
'suffix2': '0'
@@ -753,7 +748,7 @@ def test_model_to_dict_many_to_many(self):
]
for c in categories:
c.save()
- writer = Author(name='Test writer')
+ writer = Writer(name='Test writer')
writer.save()
art = Article(
@@ -862,10 +857,10 @@ def test_with_data(self):
with self.assertRaises(ValueError):
f.save()
- # Create a couple of Authors.
- w_royko = Author(name='Mike Royko')
+ # Create a couple of Writers.
+ w_royko = Writer(name='Mike Royko')
w_royko.save()
- w_woodward = Author(name='Bob Woodward')
+ w_woodward = Writer(name='Bob Woodward')
w_woodward.save()
# ManyToManyFields are represented by a MultipleChoiceField, ForeignKeys and any
# fields with the 'choices' attribute are represented by a ChoiceField.
@@ -903,9 +898,9 @@ def test_with_data(self):
# When the ModelForm is passed an instance, that instance's current values are
# inserted as 'initial' data in each Field.
- w = Author.objects.get(name='Mike Royko')
+ w = Writer.objects.get(name='Mike Royko')
f = RoykoForm(auto_id=False, instance=w)
- self.assertHTMLEqual(six.text_type(f), '''<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="100" /><br /><span class="helptext">Use both first and last names.</span></td></tr>''')
+ self.assertHTMLEqual(six.text_type(f), '''<tr><th>Name:</th><td><input type="text" name="name" value="Mike Royko" maxlength="50" /><br /><span class="helptext">Use both first and last names.</span></td></tr>''')
art = Article(
headline='Test article',
@@ -1117,7 +1112,7 @@ def test_with_data(self):
c4 = Category.objects.create(name='Fourth', url='4th')
self.assertEqual(c4.name, 'Fourth')
- w_bernstein = Author.objects.create(name='Carl Bernstein')
+ w_bernstein = Writer.objects.create(name='Carl Bernstein')
self.assertEqual(w_bernstein.name, 'Carl Bernstein')
self.assertHTMLEqual(f.as_ul(), '''<li>Headline: <input type="text" name="headline" maxlength="50" /></li>
<li>Slug: <input type="text" name="slug" maxlength="50" /></li>
@@ -1294,17 +1289,17 @@ def test_with_data(self):
self.assertEqual(list(ImprovedArticleWithParentLinkForm.base_fields), [])
- bw = BetterAuthor(name='Joe Better', score=10)
+ bw = BetterWriter(name='Joe Better', score=10)
bw.save()
self.assertEqual(sorted(model_to_dict(bw)),
- ['author_ptr', 'id', 'name', 'score'])
+ ['id', 'name', 'score', 'writer_ptr'])
- form = BetterAuthorForm({'name': 'Some Name', 'score': 12})
+ form = BetterWriterForm({'name': 'Some Name', 'score': 12})
self.assertEqual(form.is_valid(), True)
bw2 = form.save()
bw2.delete()
- form = AuthorProfileForm()
+ form = WriterProfileForm()
self.assertHTMLEqual(form.as_p(), '''<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer">
<option value="" selected="selected">---------</option>
<option value="%s">Bob Woodward</option>
@@ -1318,11 +1313,11 @@ def test_with_data(self):
'writer': six.text_type(w_woodward.pk),
'age': '65',
}
- form = AuthorProfileForm(data)
+ form = WriterProfileForm(data)
instance = form.save()
self.assertEqual(six.text_type(instance), 'Bob Woodward is 65')
- form = AuthorProfileForm(instance=instance)
+ form = WriterProfileForm(instance=instance)
self.assertHTMLEqual(form.as_p(), '''<p><label for="id_writer">Writer:</label> <select name="writer" id="id_writer">
<option value="">---------</option>
<option value="%s" selected="selected">Bob Woodward</option>
@@ -1,5 +1,3 @@
-from __future__ import unicode_literals
-
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
@@ -11,27 +9,22 @@ class Tag(models.Model):
@python_2_unicode_compatible
class Author(models.Model):
- name = models.CharField(max_length=100, help_text='Use both first and last names.',
- unique=True)
-
- class Meta:
- ordering = ['name']
+ name = models.CharField(max_length=100)
def __str__(self):
return self.name
@python_2_unicode_compatible
class Book(models.Model):
- title = models.CharField(max_length=200)
+ name = models.CharField(max_length=200)
pages = models.IntegerField(default=0)
- author = models.ForeignKey(Author, null=True, blank=True)
+ author = models.ForeignKey(Author, null=True)
pubdate = models.DateTimeField()
tags = models.ManyToManyField(Tag)
class Meta:
- ordering = ['-pubdate', 'title']
- unique_together = ['title', 'author']
+ ordering = ['-pubdate', 'name']
def __str__(self):
- return self.title
+ return self.name
@@ -77,7 +77,7 @@ def test_model_signals(self):
"Is created"
])
- b1 = Book(title='Snow Crash', pubdate='2012-02-02 12:00')
+ b1 = Book(name='Snow Crash', pubdate='2012-02-02 12:00')
self.assertEqual(self.get_signal_output(b1.save), [
"pre_save signal, Snow Crash",
"post_save signal, Snow Crash",
@@ -87,7 +87,7 @@ def test_model_signals(self):
def test_m2m_signals(self):
""" Assigning and removing to/from m2m shouldn't generate an m2m signal """
- b1 = Book(title='Snow Crash', pubdate='2012-02-02 12:00')
+ b1 = Book(name='Snow Crash', pubdate='2012-02-02 12:00')
self.get_signal_output(b1.save)
a1 = Author(name='Neal Stephenson')
self.get_signal_output(a1.save)

0 comments on commit f5d4849

Please sign in to comment.