Kaydet (Commit) 22b7870e authored tarafından Florian Apolloner's avatar Florian Apolloner

Began implementing a shared set of test models to speed up tests.

üst 1059da8d
This diff is collapsed.
......@@ -16,6 +16,7 @@ from django.db import models
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)
......@@ -44,23 +45,13 @@ 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.')
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(Writer)
writer = models.ForeignKey(Author)
article = models.TextField()
categories = models.ManyToManyField(Category, blank=True)
status = models.PositiveIntegerField(choices=ARTICLE_STATUS, blank=True, null=True)
......@@ -80,12 +71,12 @@ class ImprovedArticle(models.Model):
class ImprovedArticleWithParentLink(models.Model):
article = models.OneToOneField(Article, parent_link=True)
class BetterWriter(Writer):
class BetterAuthor(Author):
score = models.IntegerField()
@python_2_unicode_compatible
class WriterProfile(models.Model):
writer = models.OneToOneField(Writer, primary_key=True)
class AuthorProfile(models.Model):
writer = models.OneToOneField(Author, primary_key=True)
age = models.PositiveIntegerField()
def __str__(self):
......@@ -192,14 +183,6 @@ 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)
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)
......
This diff is collapsed.
from __future__ import unicode_literals
from django.db import models
from django.utils import timezone
from django.utils.encoding import python_2_unicode_compatible
......@@ -9,7 +11,11 @@ class Tag(models.Model):
@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
name = models.CharField(max_length=100, help_text='Use both first and last names.',
unique=True)
class Meta:
ordering = ['name']
def __str__(self):
return self.name
......@@ -17,14 +23,15 @@ class Author(models.Model):
@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=200)
title = models.CharField(max_length=200)
pages = models.IntegerField(default=0)
author = models.ForeignKey(Author, null=True)
author = models.ForeignKey(Author, null=True, blank=True)
pubdate = models.DateTimeField()
tags = models.ManyToManyField(Tag)
class Meta:
ordering = ['-pubdate', 'name']
ordering = ['-pubdate', 'title']
unique_together = ['title', 'author']
def __str__(self):
return self.name
return self.title
......@@ -77,7 +77,7 @@ class SignalsRegressTests(TestCase):
"Is created"
])
b1 = Book(name='Snow Crash', pubdate='2012-02-02 12:00')
b1 = Book(title='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 @@ class SignalsRegressTests(TestCase):
def test_m2m_signals(self):
""" Assigning and removing to/from m2m shouldn't generate an m2m signal """
b1 = Book(name='Snow Crash', pubdate='2012-02-02 12:00')
b1 = Book(title='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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment