Ticket #1186: test-query-rework.patch
File test-query-rework.patch, 7.3 KB (added by , 19 years ago) |
---|
-
tests/modeltests/one_to_one/models.py
66 66 67 67 >>> Restaurant.objects.get_object(place__id__exact=1) 68 68 Demon Dogs the restaurant 69 >>> Restaurant.objects.get_object(pk=1) 70 Demon Dogs the restaurant 71 >>> Restaurant.objects.get_object(place__exact=1) 72 Demon Dogs the restaurant 73 >>> Restaurant.objects.get_object(place__pk=1) 74 Demon Dogs the restaurant 69 75 >>> Restaurant.objects.get_object(place__name__startswith="Demon") 70 76 Demon Dogs the restaurant 71 >>> Restaurant.objects.get_object(pk=1)72 Demon Dogs the restaurant73 77 78 >>> Place.objects.get_object(id__exact=1) 79 Demon Dogs the place 80 >>> Place.objects.get_object(pk=1) 81 Demon Dogs the place 82 >>> Place.objects.get_object(restaurants__place__exact=1) 83 Demon Dogs the place 84 >>> Place.objects.get_object(restaurants__pk=1) 85 Demon Dogs the place 86 74 87 # Add a Waiter to the Restaurant. 75 88 >>> w = r.add_waiter(name='Joe') 76 89 >>> w.save() 77 90 >>> w 78 91 Joe the waiter at Demon Dogs the restaurant 79 92 93 # Query the waiters 94 >>> Waiter.objects.get_list(restaurant__place__exact=1) 95 [Joe the waiter at Demon Dogs the restaurant] 96 >>> Waiter.objects.get_list(restaurant__pk=1) 97 [Joe the waiter at Demon Dogs the restaurant] 98 >>> Waiter.objects.get_list(id__exact=1) 99 [Joe the waiter at Demon Dogs the restaurant] 100 >>> Waiter.objects.get_list(pk=1) 101 [Joe the waiter at Demon Dogs the restaurant] 102 103 # Delete the restaurant; the waiter should also be removed 80 104 >>> r = Restaurant.objects.get_object(pk=1) 81 105 >>> r.delete() 82 106 """ -
tests/modeltests/many_to_many/models.py
68 68 [Django lets you build Web apps easily, NASA uses Python] 69 69 70 70 # We can perform kwarg queries across m2m relationships 71 >>> Article.objects.get_list(publications__id__exact=1) 72 [Django lets you build Web apps easily, NASA uses Python] 71 73 >>> Article.objects.get_list(publications__pk=1) 72 74 [Django lets you build Web apps easily, NASA uses Python] 73 75 … … 78 80 [NASA uses Python] 79 81 80 82 # Reverse m2m queries (i.e., start at the table that doesn't have a ManyToManyField) 83 >>> Publication.objects.get_list(id__exact=1) 84 [The Python Journal] 85 >>> Publication.objects.get_list(pk=1) 86 [The Python Journal] 87 81 88 >>> Publication.objects.get_list(articles__headline__startswith="NASA") 82 89 [The Python Journal, Science News, Science Weekly] 83 90 91 >>> Publication.objects.get_list(articles__id__exact=1) 92 [The Python Journal] 93 84 94 >>> Publication.objects.get_list(articles__pk=1) 85 95 [The Python Journal] 86 96 -
tests/modeltests/custom_pk/models.py
47 47 ... 48 48 DoesNotExist: Employee does not exist for {'pk': 'foo'} 49 49 50 # Use the name of the primary key, rather than pk. 51 >>> Employee.objects.get_object(employee_code__exact='ABC123') 52 Dan Jones 53 50 54 # Fran got married and changed her last name. 51 55 >>> fran = Employee.objects.get_object(pk='XYZ456') 52 56 >>> fran.last_name = 'Jones' … … 66 70 [Sears] 67 71 >>> Business.objects.get_in_bulk(['Sears']) 68 72 {'Sears': Sears} 73 74 >>> Business.objects.get_list(name__exact='Sears') 75 [Sears] 76 >>> Business.objects.get_list(pk='Sears') 77 [Sears] 78 79 # Queries across tables, involving primary key 80 >>> Employee.objects.get_list(businesses__name__exact='Sears') 81 [Dan Jones, Fran Jones] 82 >>> Employee.objects.get_list(businesses__pk='Sears') 83 [Dan Jones, Fran Jones] 84 85 >>> Business.objects.get_list(employees__employee_code__exact='ABC123') 86 [Sears] 87 >>> Business.objects.get_list(employees__pk='ABC123') 88 [Sears] 89 >>> Business.objects.get_list(employees__first_name__startswith='Fran') 90 [Sears] 91 69 92 """ -
tests/modeltests/many_to_one/models.py
22 22 def __repr__(self): 23 23 return self.headline 24 24 25 25 26 API_TESTS = """ 26 27 # Create a Reporter. 27 28 >>> r = Reporter(first_name='John', last_name='Smith', email='john@example.com') … … 60 61 >>> r.get_article_count() 61 62 2 62 63 64 # Get articles by id 65 >>> Article.objects.get_list(id__exact=1) 66 [This is a test] 67 >>> Article.objects.get_list(pk=1) 68 [This is a test] 69 70 # Query on an article property 71 >>> Article.objects.get_list(headline__startswith='This') 72 [This is a test] 73 63 74 # The API automatically follows relationships as far as you need. 64 75 # Use double underscores to separate relationships. 65 76 # This works as many levels deep as you want. There's no limit. … … 83 94 # Find all Articles for the Reporter whose ID is 1. 84 95 >>> Article.objects.get_list(reporter__id__exact=1, order_by=['pub_date']) 85 96 [This is a test, John's second story] 97 >>> Article.objects.get_list(reporter__pk=1, order_by=['pub_date']) 98 [This is a test, John's second story] 86 99 87 # Note you need two underscores between "reporter" and "id" -- not one.100 # You need two underscores between "reporter" and "id" -- not one. 88 101 >>> Article.objects.get_list(reporter_id__exact=1) 89 102 Traceback (most recent call last): 90 103 ... 91 TypeError: got unexpected keyword argument 'reporter_id__exact'104 TypeError: Cannot resolve keyword 'reporter_id' into field 92 105 106 # You need to specify a comparison clause 107 >>> Article.objects.get_list(reporter_id=1) 108 Traceback (most recent call last): 109 ... 110 TypeError: Cannot parse keyword query 'reporter_id' 111 93 112 # "pk" shortcut syntax works in a related context, too. 94 113 >>> Article.objects.get_list(reporter__pk=1, order_by=['pub_date']) 95 114 [This is a test, John's second story] … … 109 128 >>> a4.get_reporter() 110 129 John Smith 111 130 131 # Reporters can be queried 132 >>> Reporter.objects.get_list(id__exact=1) 133 [John Smith] 134 >>> Reporter.objects.get_list(pk=1) 135 [John Smith] 136 >>> Reporter.objects.get_list(first_name__startswith='John') 137 [John Smith] 138 139 # Reporters can query in opposite direction of ForeignKey definition 140 >>> Reporter.objects.get_list(articles__id__exact=1) 141 [John Smith] 142 >>> Reporter.objects.get_list(articles__pk=1) 143 [John Smith] 144 >>> Reporter.objects.get_list(articles__headline__startswith='This') 145 [John Smith, John Smith, John Smith] 146 >>> Reporter.objects.get_list(articles__headline__startswith='This', distinct=True) 147 [John Smith] 148 149 # Queries can go round in circles. 150 >>> Reporter.objects.get_list(articles__reporter__first_name__startswith='John') 151 [John Smith, John Smith, John Smith, John Smith] 152 >>> Reporter.objects.get_list(articles__reporter__first_name__startswith='John', distinct=True) 153 [John Smith] 154 112 155 """ -
tests/modeltests/custom_columns/models.py
35 35 >>> Person.objects.get_list(firstname__exact='John') 36 36 Traceback (most recent call last): 37 37 ... 38 TypeError: got unexpected keyword argument 'firstname__exact'38 TypeError: Cannot resolve keyword 'firstname' into field 39 39 40 40 >>> p = Person.objects.get_object(last_name__exact='Smith') 41 41 >>> p.first_name