Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Migrated string_lookup doctests. Thanks to Stephan Jaekel.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13895 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6b5a240d50e83a0aef8c74d7423cc4e5178d357f 1 parent 1bcde8d
Russell Keith-Magee authored September 27, 2010
64  tests/regressiontests/string_lookup/models.py
@@ -43,67 +43,3 @@ class Article(models.Model):
43 43
 
44 44
     def __str__(self):
45 45
         return "Article %s" % self.name
46  
-
47  
-__test__ = {'API_TESTS': ur"""
48  
-# Regression test for #1661 and #1662: Check that string form referencing of
49  
-# models works, both as pre and post reference, on all RelatedField types.
50  
-
51  
->>> f1 = Foo(name="Foo1")
52  
->>> f1.save()
53  
->>> f2 = Foo(name="Foo2")
54  
->>> f2.save()
55  
-
56  
->>> w1 = Whiz(name="Whiz1")
57  
->>> w1.save()
58  
-
59  
->>> b1 = Bar(name="Bar1", normal=f1, fwd=w1, back=f2)
60  
->>> b1.save()
61  
-
62  
->>> b1.normal
63  
-<Foo: Foo Foo1>
64  
-
65  
->>> b1.fwd
66  
-<Whiz: Whiz Whiz1>
67  
-
68  
->>> b1.back
69  
-<Foo: Foo Foo2>
70  
-
71  
->>> base1 = Base(name="Base1")
72  
->>> base1.save()
73  
-
74  
->>> child1 = Child(name="Child1", parent=base1)
75  
->>> child1.save()
76  
-
77  
->>> child1.parent
78  
-<Base: Base Base1>
79  
-
80  
-# Regression tests for #3937: make sure we can use unicode characters in
81  
-# queries.
82  
-# BUG: These tests fail on MySQL, but it's a problem with the test setup. A
83  
-# properly configured UTF-8 database can handle this.
84  
-
85  
->>> fx = Foo(name='Bjorn', friend=u'François')
86  
->>> fx.save()
87  
->>> Foo.objects.get(friend__contains=u'\xe7')
88  
-<Foo: Foo Bjorn>
89  
-
90  
-# We can also do the above query using UTF-8 strings.
91  
->>> Foo.objects.get(friend__contains='\xc3\xa7')
92  
-<Foo: Foo Bjorn>
93  
-
94  
-# Regression tests for #5087: make sure we can perform queries on TextFields.
95  
->>> a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.')
96  
->>> a.save()
97  
->>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.')
98  
-<Article: Article Test>
99  
-
100  
->>> Article.objects.get(text__contains='quick brown fox')
101  
-<Article: Article Test>
102  
-
103  
-# Regression test for #708: "like" queries on IP address fields require casting
104  
-# to text (on PostgreSQL).
105  
->>> Article(name='IP test', text='The body', submitted_from='192.0.2.100').save()
106  
->>> Article.objects.filter(submitted_from__contains='192.0.2')
107  
-[<Article: Article IP test>]
108  
-
109  
-"""}
78  tests/regressiontests/string_lookup/tests.py
... ...
@@ -0,0 +1,78 @@
  1
+# -*- coding: utf-8 -*-
  2
+from django.test import TestCase
  3
+from regressiontests.string_lookup.models import Foo, Whiz, Bar, Article, Base, Child
  4
+
  5
+class 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.assertEquals(b1.normal, f1)
  27
+
  28
+        self.assertEquals(b1.fwd, w1)
  29
+
  30
+        self.assertEquals(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.assertEquals(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.assertEquals(Foo.objects.get(friend__contains=u'\xe7'), fx)
  52
+
  53
+        # We can also do the above query using UTF-8 strings.
  54
+        self.assertEquals(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.assertEquals(Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.'), a)
  66
+
  67
+        self.assertEquals(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.assertEquals(repr(Article.objects.filter(submitted_from__contains='192.0.2')),
  78
+            repr([a]))

0 notes on commit 6b5a240

Please sign in to comment.
Something went wrong with that request. Please try again.