~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import absolute_import
2
 
 
3
 
from django.db import connection
4
 
from django.test import TestCase
5
 
 
6
 
from .models import A01, A02, B01, B02, C01, C02, Unmanaged2, Managed1
7
 
 
8
 
 
9
 
class SimpleTests(TestCase):
10
 
 
11
 
    def test_simple(self):
12
 
        """
13
 
        The main test here is that the all the models can be created without
14
 
        any database errors. We can also do some more simple insertion and
15
 
        lookup tests whilst we're here to show that the second of models do
16
 
        refer to the tables from the first set.
17
 
        """
18
 
        # Insert some data into one set of models.
19
 
        a = A01.objects.create(f_a="foo", f_b=42)
20
 
        B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
21
 
        c = C01.objects.create(f_a="barney", f_b=1)
22
 
        c.mm_a = [a]
23
 
 
24
 
        # ... and pull it out via the other set.
25
 
        a2 = A02.objects.all()[0]
26
 
        self.assertTrue(isinstance(a2, A02))
27
 
        self.assertEqual(a2.f_a, "foo")
28
 
 
29
 
        b2 = B02.objects.all()[0]
30
 
        self.assertTrue(isinstance(b2, B02))
31
 
        self.assertEqual(b2.f_a, "fred")
32
 
 
33
 
        self.assertTrue(isinstance(b2.fk_a, A02))
34
 
        self.assertEqual(b2.fk_a.f_a, "foo")
35
 
 
36
 
        self.assertEqual(list(C02.objects.filter(f_a=None)), [])
37
 
 
38
 
        resp = list(C02.objects.filter(mm_a=a.id))
39
 
        self.assertEqual(len(resp), 1)
40
 
 
41
 
        self.assertTrue(isinstance(resp[0], C02))
42
 
        self.assertEqual(resp[0].f_a, 'barney')
43
 
 
44
 
 
45
 
class ManyToManyUnmanagedTests(TestCase):
46
 
 
47
 
    def test_many_to_many_between_unmanaged(self):
48
 
        """
49
 
        The intermediary table between two unmanaged models should not be created.
50
 
        """
51
 
        table = Unmanaged2._meta.get_field('mm').m2m_db_table()
52
 
        tables = connection.introspection.table_names()
53
 
        self.assertTrue(table not in tables, "Table '%s' should not exist, but it does." % table)
54
 
 
55
 
    def test_many_to_many_between_unmanaged_and_managed(self):
56
 
        """
57
 
        An intermediary table between a managed and an unmanaged model should be created.
58
 
        """
59
 
        table = Managed1._meta.get_field('mm').m2m_db_table()
60
 
        tables = connection.introspection.table_names()
61
 
        self.assertTrue(table in tables, "Table '%s' does not exist." % table)