2013-07-29 17:19:04 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2010-10-15 07:34:23 +00:00
|
|
|
from django.contrib.sites.models import Site
|
2009-11-20 00:59:38 +00:00
|
|
|
from django.db import models
|
2010-10-15 07:34:23 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
|
2011-10-13 18:04:12 +00:00
|
|
|
from .models.publication import Publication
|
|
|
|
from .models.article import Article
|
2010-10-15 07:34:23 +00:00
|
|
|
|
2009-11-20 00:59:38 +00:00
|
|
|
|
2014-05-29 00:39:14 +00:00
|
|
|
class Advertisement(models.Model):
|
2009-11-20 00:59:38 +00:00
|
|
|
customer = models.CharField(max_length=100)
|
2014-07-08 20:42:40 +00:00
|
|
|
publications = models.ManyToManyField("model_package.Publication", blank=True)
|
2009-11-20 00:59:38 +00:00
|
|
|
|
2009-11-05 11:57:28 +00:00
|
|
|
|
2010-10-15 07:34:23 +00:00
|
|
|
class ModelPackageTests(TestCase):
|
|
|
|
def test_model_packages(self):
|
|
|
|
p = Publication.objects.create(title="FooBar")
|
|
|
|
|
|
|
|
current_site = Site.objects.get_current()
|
|
|
|
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.publications.add(p)
|
|
|
|
a.sites.add(current_site)
|
|
|
|
|
|
|
|
a = Article.objects.get(id=a.pk)
|
|
|
|
self.assertEqual(a.id, a.pk)
|
|
|
|
self.assertEqual(a.sites.count(), 1)
|
|
|
|
|
|
|
|
# Regression for #12245 - Models can exist in the test package, too
|
2014-05-29 00:39:14 +00:00
|
|
|
ad = Advertisement.objects.create(customer="Lawrence Journal-World")
|
2010-10-15 07:34:23 +00:00
|
|
|
ad.publications.add(p)
|
|
|
|
|
2014-05-29 00:39:14 +00:00
|
|
|
ad = Advertisement.objects.get(id=ad.pk)
|
2010-10-15 07:34:23 +00:00
|
|
|
self.assertEqual(ad.publications.count(), 1)
|
|
|
|
|
|
|
|
# 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(
|
|
|
|
Article.publications.through._meta.fields[1].name, 'article'
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
Article.publications.through._meta.fields[1].get_attname_column(),
|
|
|
|
('article_id', 'article_id')
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
Article.publications.through._meta.fields[2].name, 'publication'
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
Article.publications.through._meta.fields[2].get_attname_column(),
|
|
|
|
('publication_id', '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'
|
|
|
|
)
|