1
- from django .db .models .query import QuerySet
2
1
from django .test import TestCase
3
- from django .utils .unittest import expectedFailure
4
2
5
3
from example_project .polls .models import Poll
6
4
7
5
from ..utils import (
8
6
BaseDjangoObjectActions ,
9
- QuerySetIsh ,
10
7
takes_instance_or_queryset ,
11
8
)
12
9
@@ -66,42 +63,6 @@ def test_get_djoa_button_attrs_custom_attrs_get_partitioned(self):
66
63
self .assertEqual (custom ['nonstandard' ], 'wombat' )
67
64
68
65
69
- class QuerySetIshTest (TestCase ):
70
- fixtures = ['sample_data' ]
71
-
72
- def setUp (self ):
73
- # WISHLIST don't depend on fixture
74
- self .obj = Poll .objects .get (pk = 1 )
75
-
76
- def test_can_turn_object_into_queryset (self ):
77
- qs = QuerySetIsh (self .obj )
78
- self .assertEqual (qs .count (), 1 )
79
- self .assertEqual (qs .get (), self .obj )
80
- self .assertEqual (qs .order_by ('foo' ).get (), self .obj )
81
- self .assertEqual (qs .all ().get (), self .obj )
82
- self .assertEqual (qs .filter ().get (), self .obj )
83
- self .assertEqual (qs .latest ('bar' ), self .obj )
84
-
85
- def test_queryset_supports_delete (self ):
86
- qs = QuerySetIsh (self .obj )
87
- qs .delete ()
88
- with self .assertRaises (Poll .DoesNotExist ):
89
- Poll .objects .get (pk = 1 )
90
-
91
- @expectedFailure
92
- def test_queryset_supports_filter (self ):
93
- # yeah, we don't actually support doing this, but it would be nice.
94
- qs = QuerySetIsh (self .obj )
95
- with self .assertRaises (Poll .DoesNotExist ):
96
- # this should be empty because the question is just `"hi"`
97
- qs .filter (question = 'abra cadabra' ).get ()
98
-
99
- def test_queryset_supports_update (self ):
100
- qs = QuerySetIsh (self .obj )
101
- qs .update (question = 'mooo' )
102
- self .assertEqual (Poll .objects .get (pk = 1 ).question , 'mooo' )
103
-
104
-
105
66
class DecoratorTest (TestCase ):
106
67
fixtures = ['sample_data' ]
107
68
@@ -128,17 +89,14 @@ def myfunc(foo, bar, queryset):
128
89
129
90
# passing in an instance yields a queryset (using positional args)
130
91
queryset = myfunc (None , None , self .obj )
131
- self .assertIsInstance (queryset , QuerySet )
132
92
# the resulting queryset only has one item and it's self.obj
133
93
self .assertEqual (queryset .get (), self .obj )
134
94
135
95
# passing in a queryset yields the same queryset
136
96
queryset = myfunc (None , None , self .queryset )
137
- self .assertIsInstance (queryset , QuerySet )
138
97
self .assertEqual (queryset , self .queryset )
139
98
140
99
# passing in an instance yields a queryset (using keyword args)
141
100
queryset = myfunc (None , None , queryset = self .obj )
142
- self .assertIsInstance (queryset , QuerySet )
143
101
# the resulting queryset only has one item and it's self.obj
144
102
self .assertEqual (queryset .get (), self .obj )
0 commit comments