Fixed #18586 -- Split up model_package.ModelPackageTests.
This commit is contained in:
parent
b481c85697
commit
e1513a7960
|
@ -1,7 +1,8 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.db import models
|
from django.db import models, connection
|
||||||
|
from django.db.backends.utils import truncate_name
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from .models.publication import Publication
|
from .models.publication import Publication
|
||||||
|
@ -14,14 +15,16 @@ class Advertisement(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class ModelPackageTests(TestCase):
|
class ModelPackageTests(TestCase):
|
||||||
def test_model_packages(self):
|
def test_m2m_tables_in_subpackage_models(self):
|
||||||
|
"""
|
||||||
|
Regression for #12168: models split into subpackages still get M2M
|
||||||
|
tables.
|
||||||
|
"""
|
||||||
p = Publication.objects.create(title="FooBar")
|
p = Publication.objects.create(title="FooBar")
|
||||||
|
|
||||||
current_site = Site.objects.get_current()
|
current_site = Site.objects.get_current()
|
||||||
self.assertEqual(current_site.domain, "example.com")
|
self.assertEqual(current_site.domain, "example.com")
|
||||||
|
|
||||||
# Regression for #12168: models split into subpackages still get M2M
|
|
||||||
# tables
|
|
||||||
a = Article.objects.create(headline="a foo headline")
|
a = Article.objects.create(headline="a foo headline")
|
||||||
a.publications.add(p)
|
a.publications.add(p)
|
||||||
a.sites.add(current_site)
|
a.sites.add(current_site)
|
||||||
|
@ -30,16 +33,23 @@ class ModelPackageTests(TestCase):
|
||||||
self.assertEqual(a.id, a.pk)
|
self.assertEqual(a.id, a.pk)
|
||||||
self.assertEqual(a.sites.count(), 1)
|
self.assertEqual(a.sites.count(), 1)
|
||||||
|
|
||||||
# Regression for #12245 - Models can exist in the test package, too
|
def test_models_in_the_test_package(self):
|
||||||
|
"""
|
||||||
|
Regression for #12245 - Models can exist in the test package, too.
|
||||||
|
"""
|
||||||
|
p = Publication.objects.create(title="FooBar")
|
||||||
ad = Advertisement.objects.create(customer="Lawrence Journal-World")
|
ad = Advertisement.objects.create(customer="Lawrence Journal-World")
|
||||||
ad.publications.add(p)
|
ad.publications.add(p)
|
||||||
|
|
||||||
ad = Advertisement.objects.get(id=ad.pk)
|
ad = Advertisement.objects.get(id=ad.pk)
|
||||||
self.assertEqual(ad.publications.count(), 1)
|
self.assertEqual(ad.publications.count(), 1)
|
||||||
|
|
||||||
# Regression for #12386 - field names on the autogenerated intermediate
|
def test_automatic_m2m_column_names(self):
|
||||||
# class that are specified as dotted strings don't retain any path
|
"""
|
||||||
# component for the field or column name
|
Regression for #12386 - field names on the autogenerated intermediate
|
||||||
|
class that are specified as dotted strings don't retain any path
|
||||||
|
component for the field or column name.
|
||||||
|
"""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
Article.publications.through._meta.fields[1].name, 'article'
|
Article.publications.through._meta.fields[1].name, 'article'
|
||||||
)
|
)
|
||||||
|
@ -55,9 +65,9 @@ class ModelPackageTests(TestCase):
|
||||||
('publication_id', 'publication_id')
|
('publication_id', 'publication_id')
|
||||||
)
|
)
|
||||||
|
|
||||||
# The oracle backend truncates the name to 'model_package_article_publ233f'.
|
self.assertEqual(
|
||||||
self.assertTrue(
|
Article._meta.get_field('publications').m2m_db_table(),
|
||||||
Article._meta.get_field('publications').m2m_db_table() in ('model_package_article_publications', 'model_package_article_publ233f')
|
truncate_name('model_package_article_publications', connection.ops.max_name_length()),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue