summaryrefslogtreecommitdiff
path: root/parts/django/tests/regressiontests/string_lookup/tests.py
blob: ddf7a8a76c31bb9dba54be8aa9c1fa8443435edb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
from django.test import TestCase
from regressiontests.string_lookup.models import Foo, Whiz, Bar, Article, Base, Child

class StringLookupTests(TestCase):

    def test_string_form_referencing(self):
        """
        Regression test for #1661 and #1662

        Check that string form referencing of
        models works, both as pre and post reference, on all RelatedField types.
        """

        f1 = Foo(name="Foo1")
        f1.save()
        f2 = Foo(name="Foo2")
        f2.save()

        w1 = Whiz(name="Whiz1")
        w1.save()

        b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
        b1.save()

        self.assertEquals(b1.normal, f1)

        self.assertEquals(b1.fwd, w1)

        self.assertEquals(b1.back, f2)

        base1 = Base(name="Base1")
        base1.save()

        child1 = Child(name="Child1", parent=base1)
        child1.save()

        self.assertEquals(child1.parent, base1)

    def test_unicode_chars_in_queries(self):
        """
        Regression tests for #3937

        make sure we can use unicode characters in queries.
        If these tests fail on MySQL, it's a problem with the test setup.
        A properly configured UTF-8 database can handle this.
        """

        fx = Foo(name='Bjorn', friend=u'François')
        fx.save()
        self.assertEquals(Foo.objects.get(friend__contains=u'\xe7'), fx)

        # We can also do the above query using UTF-8 strings.
        self.assertEquals(Foo.objects.get(friend__contains='\xc3\xa7'), fx)

    def test_queries_on_textfields(self):
        """
        Regression tests for #5087

        make sure we can perform queries on TextFields.
        """

        a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.')
        a.save()
        self.assertEquals(Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.'), a)

        self.assertEquals(Article.objects.get(text__contains='quick brown fox'), a)

    def test_ipaddress_on_postgresql(self):
        """
        Regression test for #708

        "like" queries on IP address fields require casting to text (on PostgreSQL).
        """
        a = Article(name='IP test', text='The body', submitted_from='192.0.2.100')
        a.save()
        self.assertEquals(repr(Article.objects.filter(submitted_from__contains='192.0.2')),
            repr([a]))