PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/modeltests/model_package/tests.py

https://code.google.com/p/mango-py/
Python | 72 lines | 51 code | 14 blank | 7 comment | 0 complexity | 33a75138bac58093aa50f11bdf94d6bf MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.sites.models import Site
  2. from django.db import models
  3. from django.test import TestCase
  4. from models.publication import Publication
  5. from models.article import Article
  6. class Advertisment(models.Model):
  7. customer = models.CharField(max_length=100)
  8. publications = models.ManyToManyField(
  9. "model_package.Publication", null=True, blank=True
  10. )
  11. class Meta:
  12. app_label = 'model_package'
  13. class ModelPackageTests(TestCase):
  14. def test_model_packages(self):
  15. p = Publication.objects.create(title="FooBar")
  16. current_site = Site.objects.get_current()
  17. self.assertEqual(current_site.domain, "example.com")
  18. # Regression for #12168: models split into subpackages still get M2M
  19. # tables
  20. a = Article.objects.create(headline="a foo headline")
  21. a.publications.add(p)
  22. a.sites.add(current_site)
  23. a = Article.objects.get(id=a.pk)
  24. self.assertEqual(a.id, a.pk)
  25. self.assertEqual(a.sites.count(), 1)
  26. # Regression for #12245 - Models can exist in the test package, too
  27. ad = Advertisment.objects.create(customer="Lawrence Journal-World")
  28. ad.publications.add(p)
  29. ad = Advertisment.objects.get(id=ad.pk)
  30. self.assertEqual(ad.publications.count(), 1)
  31. # Regression for #12386 - field names on the autogenerated intermediate
  32. # class that are specified as dotted strings don't retain any path
  33. # component for the field or column name
  34. self.assertEqual(
  35. Article.publications.through._meta.fields[1].name, 'article'
  36. )
  37. self.assertEqual(
  38. Article.publications.through._meta.fields[1].get_attname_column(),
  39. ('article_id', 'article_id')
  40. )
  41. self.assertEqual(
  42. Article.publications.through._meta.fields[2].name, 'publication'
  43. )
  44. self.assertEqual(
  45. Article.publications.through._meta.fields[2].get_attname_column(),
  46. ('publication_id', 'publication_id')
  47. )
  48. # The oracle backend truncates the name to 'model_package_article_publ233f'.
  49. self.assertTrue(
  50. Article._meta.get_field('publications').m2m_db_table() in ('model_package_article_publications', 'model_package_article_publ233f')
  51. )
  52. self.assertEqual(
  53. Article._meta.get_field('publications').m2m_column_name(), 'article_id'
  54. )
  55. self.assertEqual(
  56. Article._meta.get_field('publications').m2m_reverse_name(),
  57. 'publication_id'
  58. )