~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (4.4.9 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20101012113435-5rk3p18nyanuhj6g
* SECURITY UPDATE: XSS in CSRF protections. New upstream release
  - CVE-2010-3082
* debian/patches/01_disable_url_verify_regression_tests.diff:
  - updated to disable another test that fails without internet connection
  - patch based on work by Kai Kasurinen and Krzysztof Klimonda
* debian/control: don't Build-Depends on locales-all, which doesn't exist
  in maverick

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.core import management
 
2
from django.test import TestCase
 
3
 
 
4
from models import Article
 
5
 
 
6
 
 
7
class SampleTestCase(TestCase):
 
8
    fixtures = ['fixture1.json', 'fixture2.json']
 
9
 
 
10
    def testClassFixtures(self):
 
11
        "Test cases can load fixture objects into models defined in packages"
 
12
        self.assertEqual(Article.objects.count(), 4)
 
13
        self.assertQuerysetEqual(
 
14
            Article.objects.all(),[
 
15
                "Django conquers world!",
 
16
                "Copyright is fine the way it is",
 
17
                "Poker has no place on ESPN",
 
18
                "Python program becomes self aware"
 
19
            ],
 
20
            lambda a: a.headline
 
21
        )
 
22
 
 
23
 
 
24
class FixtureTestCase(TestCase):
 
25
    def test_initial_data(self):
 
26
        "Fixtures can load initial data into models defined in packages"
 
27
        #Syncdb introduces 1 initial data object from initial_data.json
 
28
        self.assertQuerysetEqual(
 
29
            Article.objects.all(), [
 
30
                "Python program becomes self aware"
 
31
            ],
 
32
            lambda a: a.headline
 
33
        )
 
34
 
 
35
    def test_loaddata(self):
 
36
        "Fixtures can load data into models defined in packages"
 
37
        # Load fixture 1. Single JSON file, with two objects
 
38
        management.call_command("loaddata", "fixture1.json", verbosity=0, commit=False)
 
39
        self.assertQuerysetEqual(
 
40
            Article.objects.all(), [
 
41
                "Time to reform copyright",
 
42
                "Poker has no place on ESPN",
 
43
                "Python program becomes self aware",
 
44
            ],
 
45
            lambda a: a.headline,
 
46
        )
 
47
 
 
48
        # Load fixture 2. JSON file imported by default. Overwrites some
 
49
        # existing objects
 
50
        management.call_command("loaddata", "fixture2.json", verbosity=0, commit=False)
 
51
        self.assertQuerysetEqual(
 
52
            Article.objects.all(), [
 
53
                "Django conquers world!",
 
54
                "Copyright is fine the way it is",
 
55
                "Poker has no place on ESPN",
 
56
                "Python program becomes self aware",
 
57
            ],
 
58
            lambda a: a.headline,
 
59
        )
 
60
 
 
61
        # Load a fixture that doesn't exist
 
62
        management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
 
63
        self.assertQuerysetEqual(
 
64
            Article.objects.all(), [
 
65
                "Django conquers world!",
 
66
                "Copyright is fine the way it is",
 
67
                "Poker has no place on ESPN",
 
68
                "Python program becomes self aware",
 
69
            ],
 
70
            lambda a: a.headline,
 
71
        )