~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to tests/modeltests/model_package/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-05-21 07:52:55 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100521075255-ii78v1dyfmyu3uzx
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

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