This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
/
test_cases.py
101 lines (71 loc) · 2.77 KB
/
test_cases.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Tests for test case queryset-filtering by ID and with optional ID prefix.
"""
from sets import Set
from tests import case
from moztrap.view.lists.cases import PrefixIDFilter
class PrefixIDFilterTest(case.DBTestCase):
"""Tests for PrefixIDFilter"""
def create_testdata(self):
testdata = {}
testdata["cv1"] = self.F.CaseVersionFactory.create(name="CV 1",
case=self.F.CaseFactory.create(idprefix="pre"))
testdata["cv2"] = self.F.CaseVersionFactory.create(name="CV 2")
testdata["cv3"] = self.F.CaseVersionFactory.create(name="CV 3",
case=self.F.CaseFactory.create(idprefix="moz"))
testdata["cv4"] = self.F.CaseVersionFactory.create(name="CV 4",
case=self.F.CaseFactory.create(idprefix="moz"))
return testdata
def filter(self, criteria):
f = PrefixIDFilter("id")
res = f.filter(
self.model.CaseVersion.objects.all(),
criteria,
)
return res
def test_prefix_and_id(self):
"""prefix and ID"""
td = self.create_testdata()
res = self.filter([u"pre-{0}".format(td["cv1"].case.id)])
self.assertEqual(res.get().name, "CV 1")
def test_prefix_only(self):
"""prefix only"""
self.create_testdata()
res = self.filter([u"pre"])
self.assertEqual(res.get().name, "CV 1")
def test_id_only(self):
"""ID only"""
td = self.create_testdata()
res = self.filter([unicode(td["cv1"].case.id)])
self.assertEqual(res.get().name, "CV 1")
def test_id_and_prefix_from_different_cases_gets_both(self):
"""ID from one case and prefix from a different case gets both"""
td = self.create_testdata()
res = self.filter([u"pre", unicode(td["cv2"].case.id)])
self.assertEqual(
Set([x.name for x in res.all()]),
Set(["CV 1", "CV 2"]),
)
def test_id_case_without_prefix(self):
"""id when case has no prefix"""
td = self.create_testdata()
res = self.filter([unicode(td["cv2"].case.id)])
self.assertEqual(res.get().name, "CV 2")
def test_cases_different_prefix_return_both(self):
"""
3 cases have 2 different prefixes returns cases from both prefixes.
"""
self.create_testdata()
res = self.filter([u"pre", u"moz"])
self.assertEqual(
Set([x.name for x in res.all()]),
Set(["CV 1", "CV 3", "CV 4"]),
)
def test_cases_same_prefix_return_both(self):
"""2 cases with no prefixes, IDs OR'ed"""
self.create_testdata()
res = self.filter([u"moz"])
self.assertEqual(
Set([x.name for x in res.all()]),
Set(["CV 3", "CV 4"]),
)