Ticket #14473: model_package_test_conversion.diff

File model_package_test_conversion.diff, 4.7 KB (added by Gabriel Hurley, 14 years ago)
  • tests/modeltests/model_package/tests.py

     
    11from django.db import models
     2from django.test import TestCase
    23
    34class Advertisment(models.Model):
    45    customer = models.CharField(max_length=100)
     
    78    class Meta:
    89        app_label = 'model_package'
    910
    10 __test__ = {'API_TESTS': """
    11 >>> from models.publication import Publication
    12 >>> from models.article import Article
    1311
    14 >>> p = Publication(title="FooBar")
    15 >>> p.save()
    16 >>> p
    17 <Publication: Publication object>
    18 
    19 >>> from django.contrib.sites.models import Site
    20 >>> current_site = Site.objects.get_current()
    21 >>> current_site
    22 <Site: example.com>
    23 
    24 # Regression for #12168: models split into subpackages still get M2M tables
    25 
    26 >>> a = Article(headline="a foo headline")
    27 >>> a.save()
    28 >>> a.publications.add(p)
    29 >>> a.sites.add(current_site)
    30 
    31 >>> a = Article.objects.get(id=1)
    32 >>> a
    33 <Article: Article object>
    34 >>> a.id
    35 1
    36 >>> a.sites.count()
    37 1
    38 
    39 # Regression for #12245 - Models can exist in the test package, too
    40 
    41 >>> ad = Advertisment(customer="Lawrence Journal-World")
    42 >>> ad.save()
    43 >>> ad.publications.add(p)
    44 
    45 >>> ad = Advertisment.objects.get(id=1)
    46 >>> ad
    47 <Advertisment: Advertisment object>
    48 
    49 >>> ad.publications.count()
    50 1
    51 
    52 # Regression for #12386 - field names on the autogenerated intermediate class
    53 # that are specified as dotted strings don't retain any path component for the
    54 # field or column name
    55 
    56 >>> Article.publications.through._meta.fields[1].name
    57 'article'
    58 
    59 >>> Article.publications.through._meta.fields[1].get_attname_column()
    60 ('article_id', 'article_id')
    61 
    62 >>> Article.publications.through._meta.fields[2].name
    63 'publication'
    64 
    65 >>> Article.publications.through._meta.fields[2].get_attname_column()
    66 ('publication_id', 'publication_id')
    67 
    68 # The oracle backend truncates the name to 'model_package_article_publ233f'.
    69 >>> Article._meta.get_field('publications').m2m_db_table() \\
    70 ... in ('model_package_article_publications', 'model_package_article_publ233f')
    71 True
    72 
    73 >>> Article._meta.get_field('publications').m2m_column_name()
    74 'article_id'
    75 
    76 >>> Article._meta.get_field('publications').m2m_reverse_name()
    77 'publication_id'
    78 
    79 """}
    80 
    81 
     12class ModelPackageTests(TestCase):
     13    def test_model_packages(self):
     14        from models.publication import Publication
     15        from models.article import Article
     16        p = Publication(title="FooBar")
     17        p.save()
     18        self.assertEqual(repr(p), "<Publication: Publication object>")
     19       
     20        from django.contrib.sites.models import Site
     21        current_site = Site.objects.get_current()
     22        self.assertEqual(repr(current_site), "<Site: example.com>")
     23       
     24        # Regression for #12168: models split into subpackages still get M2M tables
     25        a = Article(headline="a foo headline")
     26        a.save()
     27        a.publications.add(p)
     28        a.sites.add(current_site)
     29       
     30        a = Article.objects.get(id=1)
     31        self.assertEqual(repr(a), "<Article: Article object>")
     32        self.assertEqual(a.id, 1)
     33        self.assertEqual(a.sites.count(), 1)
     34   
     35        # Regression for #12245 - Models can exist in the test package, too
     36        ad = Advertisment(customer="Lawrence Journal-World")
     37        ad.save()
     38        ad.publications.add(p)
     39       
     40        ad = Advertisment.objects.get(id=1)
     41        self.assertEqual(repr(ad), "<Advertisment: Advertisment object>")
     42        self.assertEqual(ad.publications.count(), 1)
     43       
     44        # Regression for #12386 - field names on the autogenerated intermediate class
     45        # that are specified as dotted strings don't retain any path component for the
     46        # field or column name
     47        self.assertEqual(Article.publications.through._meta.fields[1].name, 'article')
     48        self.assertEqual(Article.publications.through._meta.fields[1].get_attname_column(), ('article_id', 'article_id'))
     49        self.assertEqual(Article.publications.through._meta.fields[2].name, 'publication')
     50        self.assertEqual(Article.publications.through._meta.fields[2].get_attname_column(), ('publication_id', 'publication_id'))
     51       
     52        # The oracle backend truncates the name to 'model_package_article_publ233f'.
     53        self.assertTrue(Article._meta.get_field('publications').m2m_db_table() in ('model_package_article_publications', 'model_package_article_publ233f'))
     54       
     55        self.assertEqual(Article._meta.get_field('publications').m2m_column_name(), 'article_id')
     56        self.assertEqual(Article._meta.get_field('publications').m2m_reverse_name(), 'publication_id')
Back to Top