Fixed #14473 -- converted the model_package tests from doctests to unitests. We have always been at war with doctests. Thanks to Gabriel Hurley for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14227 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
056659c1cf
commit
c20f2f2ac9
|
@ -1,81 +1,72 @@
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from models.publication import Publication
|
||||||
|
from models.article import Article
|
||||||
|
|
||||||
|
|
||||||
class Advertisment(models.Model):
|
class Advertisment(models.Model):
|
||||||
customer = models.CharField(max_length=100)
|
customer = models.CharField(max_length=100)
|
||||||
publications = models.ManyToManyField("model_package.Publication", null=True, blank=True)
|
publications = models.ManyToManyField(
|
||||||
|
"model_package.Publication", null=True, blank=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
app_label = 'model_package'
|
app_label = 'model_package'
|
||||||
|
|
||||||
__test__ = {'API_TESTS': """
|
|
||||||
>>> from models.publication import Publication
|
|
||||||
>>> from models.article import Article
|
|
||||||
|
|
||||||
>>> p = Publication(title="FooBar")
|
class ModelPackageTests(TestCase):
|
||||||
>>> p.save()
|
def test_model_packages(self):
|
||||||
>>> p
|
p = Publication.objects.create(title="FooBar")
|
||||||
<Publication: Publication object>
|
|
||||||
|
|
||||||
>>> from django.contrib.sites.models import Site
|
current_site = Site.objects.get_current()
|
||||||
>>> current_site = Site.objects.get_current()
|
self.assertEqual(current_site.domain, "example.com")
|
||||||
>>> current_site
|
|
||||||
<Site: example.com>
|
|
||||||
|
|
||||||
# Regression for #12168: models split into subpackages still get M2M tables
|
# Regression for #12168: models split into subpackages still get M2M
|
||||||
|
# tables
|
||||||
|
a = Article.objects.create(headline="a foo headline")
|
||||||
|
a.publications.add(p)
|
||||||
|
a.sites.add(current_site)
|
||||||
|
|
||||||
>>> a = Article(headline="a foo headline")
|
a = Article.objects.get(id=a.pk)
|
||||||
>>> a.save()
|
self.assertEqual(a.id, a.pk)
|
||||||
>>> a.publications.add(p)
|
self.assertEqual(a.sites.count(), 1)
|
||||||
>>> a.sites.add(current_site)
|
|
||||||
|
|
||||||
>>> a = Article.objects.get(id=1)
|
# Regression for #12245 - Models can exist in the test package, too
|
||||||
>>> a
|
ad = Advertisment.objects.create(customer="Lawrence Journal-World")
|
||||||
<Article: Article object>
|
ad.publications.add(p)
|
||||||
>>> a.id
|
|
||||||
1
|
|
||||||
>>> a.sites.count()
|
|
||||||
1
|
|
||||||
|
|
||||||
# Regression for #12245 - Models can exist in the test package, too
|
ad = Advertisment.objects.get(id=ad.pk)
|
||||||
|
self.assertEqual(ad.publications.count(), 1)
|
||||||
|
|
||||||
>>> ad = Advertisment(customer="Lawrence Journal-World")
|
# Regression for #12386 - field names on the autogenerated intermediate
|
||||||
>>> ad.save()
|
# class that are specified as dotted strings don't retain any path
|
||||||
>>> ad.publications.add(p)
|
# component for the field or column name
|
||||||
|
self.assertEqual(
|
||||||
>>> ad = Advertisment.objects.get(id=1)
|
Article.publications.through._meta.fields[1].name, 'article'
|
||||||
>>> ad
|
)
|
||||||
<Advertisment: Advertisment object>
|
self.assertEqual(
|
||||||
|
Article.publications.through._meta.fields[1].get_attname_column(),
|
||||||
>>> ad.publications.count()
|
('article_id', 'article_id')
|
||||||
1
|
)
|
||||||
|
self.assertEqual(
|
||||||
# Regression for #12386 - field names on the autogenerated intermediate class
|
Article.publications.through._meta.fields[2].name, 'publication'
|
||||||
# that are specified as dotted strings don't retain any path component for the
|
)
|
||||||
# field or column name
|
self.assertEqual(
|
||||||
|
Article.publications.through._meta.fields[2].get_attname_column(),
|
||||||
>>> Article.publications.through._meta.fields[1].name
|
('publication_id', 'publication_id')
|
||||||
'article'
|
)
|
||||||
|
|
||||||
>>> Article.publications.through._meta.fields[1].get_attname_column()
|
|
||||||
('article_id', 'article_id')
|
|
||||||
|
|
||||||
>>> Article.publications.through._meta.fields[2].name
|
|
||||||
'publication'
|
|
||||||
|
|
||||||
>>> Article.publications.through._meta.fields[2].get_attname_column()
|
|
||||||
('publication_id', 'publication_id')
|
|
||||||
|
|
||||||
# The oracle backend truncates the name to 'model_package_article_publ233f'.
|
|
||||||
>>> Article._meta.get_field('publications').m2m_db_table() \\
|
|
||||||
... in ('model_package_article_publications', 'model_package_article_publ233f')
|
|
||||||
True
|
|
||||||
|
|
||||||
>>> Article._meta.get_field('publications').m2m_column_name()
|
|
||||||
'article_id'
|
|
||||||
|
|
||||||
>>> Article._meta.get_field('publications').m2m_reverse_name()
|
|
||||||
'publication_id'
|
|
||||||
|
|
||||||
"""}
|
|
||||||
|
|
||||||
|
# The oracle backend truncates the name to 'model_package_article_publ233f'.
|
||||||
|
self.assertTrue(
|
||||||
|
Article._meta.get_field('publications').m2m_db_table() in ('model_package_article_publications', 'model_package_article_publ233f')
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
Article._meta.get_field('publications').m2m_column_name(), 'article_id'
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
Article._meta.get_field('publications').m2m_reverse_name(),
|
||||||
|
'publication_id'
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue