PageRenderTime 102ms CodeModel.GetById 81ms app.highlight 6ms RepoModel.GetById 14ms app.codeStats 0ms

/tests/regressiontests/string_lookup/tests.py

https://code.google.com/p/mango-py/
Python | 78 lines | 53 code | 12 blank | 13 comment | 0 complexity | c93c5709b6eda434065dc1f3564b4407 MD5 | raw file
 1# -*- coding: utf-8 -*-
 2from django.test import TestCase
 3from regressiontests.string_lookup.models import Foo, Whiz, Bar, Article, Base, Child
 4
 5class StringLookupTests(TestCase):
 6
 7    def test_string_form_referencing(self):
 8        """
 9        Regression test for #1661 and #1662
10
11        Check that string form referencing of
12        models works, both as pre and post reference, on all RelatedField types.
13        """
14
15        f1 = Foo(name="Foo1")
16        f1.save()
17        f2 = Foo(name="Foo2")
18        f2.save()
19
20        w1 = Whiz(name="Whiz1")
21        w1.save()
22
23        b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
24        b1.save()
25
26        self.assertEqual(b1.normal, f1)
27
28        self.assertEqual(b1.fwd, w1)
29
30        self.assertEqual(b1.back, f2)
31
32        base1 = Base(name="Base1")
33        base1.save()
34
35        child1 = Child(name="Child1", parent=base1)
36        child1.save()
37
38        self.assertEqual(child1.parent, base1)
39
40    def test_unicode_chars_in_queries(self):
41        """
42        Regression tests for #3937
43
44        make sure we can use unicode characters in queries.
45        If these tests fail on MySQL, it's a problem with the test setup.
46        A properly configured UTF-8 database can handle this.
47        """
48
49        fx = Foo(name='Bjorn', friend=u'Fran??ois')
50        fx.save()
51        self.assertEqual(Foo.objects.get(friend__contains=u'\xe7'), fx)
52
53        # We can also do the above query using UTF-8 strings.
54        self.assertEqual(Foo.objects.get(friend__contains='\xc3\xa7'), fx)
55
56    def test_queries_on_textfields(self):
57        """
58        Regression tests for #5087
59
60        make sure we can perform queries on TextFields.
61        """
62
63        a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.')
64        a.save()
65        self.assertEqual(Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.'), a)
66
67        self.assertEqual(Article.objects.get(text__contains='quick brown fox'), a)
68
69    def test_ipaddress_on_postgresql(self):
70        """
71        Regression test for #708
72
73        "like" queries on IP address fields require casting to text (on PostgreSQL).
74        """
75        a = Article(name='IP test', text='The body', submitted_from='192.0.2.100')
76        a.save()
77        self.assertEqual(repr(Article.objects.filter(submitted_from__contains='192.0.2')),
78            repr([a]))