4
4
from .models import Tag
5
5
6
6
7
- class QueriesFilterByObjectId (TestCase ):
7
+ class ObjectIdTests (TestCase ):
8
8
@classmethod
9
9
def setUpTestData (cls ):
10
10
cls .group_id_str_1 = "1" * 24
@@ -19,72 +19,72 @@ def setUpTestData(cls):
19
19
cls .t5 = Tag .objects .create (name = "t5" , parent = cls .t3 )
20
20
21
21
def test_filter_group_id_is_null_false (self ):
22
- """Filter objects where group_id is not null"""
22
+ """Filter objects where group_id is not null. """
23
23
qs = Tag .objects .filter (group_id__isnull = False ).order_by ("name" )
24
24
self .assertSequenceEqual (qs , [self .t3 , self .t4 ])
25
25
26
26
def test_filter_group_id_is_null_true (self ):
27
- """Filter objects where group_id is null"""
27
+ """Filter objects where group_id is null. """
28
28
qs = Tag .objects .filter (group_id__isnull = True ).order_by ("name" )
29
29
self .assertSequenceEqual (qs , [self .t1 , self .t2 , self .t5 ])
30
30
31
31
def test_filter_group_id_equal_str (self ):
32
- """Filter by group_id with a specific string value"""
32
+ """Filter by group_id with a specific string value. """
33
33
qs = Tag .objects .filter (group_id = self .group_id_str_1 ).order_by ("name" )
34
34
self .assertSequenceEqual (qs , [self .t3 ])
35
35
36
36
def test_filter_group_id_equal_obj (self ):
37
- """Filter by group_id with a specific ObjectId value"""
37
+ """Filter by group_id with a specific ObjectId value. """
38
38
qs = Tag .objects .filter (group_id = self .group_id_obj_1 ).order_by ("name" )
39
39
self .assertSequenceEqual (qs , [self .t3 ])
40
40
41
41
def test_filter_group_id_in_str_values (self ):
42
- """Filter by group_id with string values in a list"""
42
+ """Filter by group_id with string values in a list. """
43
43
qs = Tag .objects .filter (group_id__in = [self .group_id_str_1 , self .group_id_str_2 ]).order_by (
44
44
"name"
45
45
)
46
46
self .assertSequenceEqual (qs , [self .t3 , self .t4 ])
47
47
48
48
def test_filter_group_id_in_obj_values (self ):
49
- """Filter by group_id with ObjectId values in a list"""
49
+ """Filter by group_id with ObjectId values in a list. """
50
50
qs = Tag .objects .filter (group_id__in = [self .group_id_obj_1 , self .group_id_obj_2 ]).order_by (
51
51
"name"
52
52
)
53
53
self .assertSequenceEqual (qs , [self .t3 , self .t4 ])
54
54
55
55
def test_filter_group_id_equal_subquery (self ):
56
- """Filter by group_id using a subquery"""
56
+ """Filter by group_id using a subquery. """
57
57
subquery = Tag .objects .filter (name = "t3" ).values ("group_id" )
58
58
qs = Tag .objects .filter (group_id__in = subquery ).order_by ("name" )
59
59
self .assertSequenceEqual (qs , [self .t3 ])
60
60
61
61
def test_filter_group_id_in_subquery (self ):
62
- """Filter by group_id using a subquery with multiple values"""
62
+ """Filter by group_id using a subquery with multiple values. """
63
63
subquery = Tag .objects .filter (name__in = ["t3" , "t4" ]).values ("group_id" )
64
64
qs = Tag .objects .filter (group_id__in = subquery ).order_by ("name" )
65
65
self .assertSequenceEqual (qs , [self .t3 , self .t4 ])
66
66
67
67
def test_filter_parent_by_children_values_str (self ):
68
- """Query to select parents of children with specific string group_id"""
68
+ """Query to select parents of children with specific string group_id. """
69
69
child_ids = Tag .objects .filter (group_id = self .group_id_str_1 ).values_list ("id" , flat = True )
70
70
parent_qs = Tag .objects .filter (children__id__in = child_ids ).distinct ().order_by ("name" )
71
71
self .assertSequenceEqual (parent_qs , [self .t1 ])
72
72
73
73
def test_filter_parent_by_children_values_obj (self ):
74
- """Query to select parents of children with specific ObjectId group_id"""
74
+ """Query to select parents of children with specific ObjectId group_id. """
75
75
child_ids = Tag .objects .filter (group_id = self .group_id_obj_1 ).values_list ("id" , flat = True )
76
76
parent_qs = Tag .objects .filter (children__id__in = child_ids ).distinct ().order_by ("name" )
77
77
self .assertSequenceEqual (parent_qs , [self .t1 ])
78
78
79
79
def test_filter_group_id_union_with_str (self ):
80
- """Combine queries using union with string values"""
80
+ """Combine queries using union with string values. """
81
81
qs_a = Tag .objects .filter (group_id = self .group_id_str_1 )
82
82
qs_b = Tag .objects .filter (group_id = self .group_id_str_2 )
83
83
union_qs = qs_a .union (qs_b ).order_by ("name" )
84
84
self .assertSequenceEqual (union_qs , [self .t3 , self .t4 ])
85
85
86
86
def test_filter_group_id_union_with_obj (self ):
87
- """Combine queries using union with ObjectId values"""
87
+ """Combine queries using union with ObjectId values. """
88
88
qs_a = Tag .objects .filter (group_id = self .group_id_obj_1 )
89
89
qs_b = Tag .objects .filter (group_id = self .group_id_obj_2 )
90
90
union_qs = qs_a .union (qs_b ).order_by ("name" )
0 commit comments