class TimelineFilterTestCa seMixin BaseTestCaseMixin def __init__ self

 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
class TimelineFilterTestCaseMixin(BaseTestCaseMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def test_timeline_filter_with_events(self):
sub_matter = SubMatterFactory(matter__organization__members=[self.user])
event = EventFactory(date=str_to_date('2015-01-15'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-01'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-07'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-15'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-21'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-30'), sub_matter=sub_matter, event=event)
res = self.client.get(reverse('task-list'), {'from': '2015-01-14', 'to': '2015-01-16'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 5)
res = self.client.get(reverse('task-list'), {'from': '2015-01-16', 'to': '2015-02-01'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 0)
def test_timeline_filter_without_events(self):
sub_matter = SubMatterFactory(matter__organization__members=[self.user])
self.object_factory(created=str_to_date('2015-01-01'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-07'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-15'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-21'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-30'), sub_matter=sub_matter)
res = self.client.get(reverse('task-list'), {'from': '2015-01-01', 'to': '2015-02-01'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 5)
res = self.client.get(reverse('task-list'), {'from': '2015-01-01', 'to': '2015-01-07'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 2)
res = self.client.get(reverse('task-list'), {'from': '2015-01-15', 'to': '2015-01-30'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 3)
res = self.client.get(reverse('task-list'), {'from': '2015-02-02', 'to': '2015-03-01'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertEqual(len(res.data), 0)
def test_timeline_filter_mixed(self):
sub_matter = SubMatterFactory(matter__organization__members=[self.user])
event = EventFactory(date=str_to_date('2015-01-15'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-01'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-07'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-15'), sub_matter=sub_matter, event=event)
self.object_factory(created=str_to_date('2015-01-21'), sub_matter=sub_matter)
self.object_factory(created=str_to_date('2015-01-30'), sub_matter=sub_matter)
res = self.client.get(reverse('task-list'), {'from': '2015-01-14', 'to': '2015-01-15'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
# only one task in this range, but there's also the event, so we expect to see all 3 tasks related
# to the event
self.assertEqual(len(res.data), 3)
res = self.client.get(reverse('task-list'), {'from': '2015-01-14', 'to': '2015-01-21'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
# event, an event's task and one eventless task in this range. all the event's tasks + single eventless task = 4
self.assertEqual(len(res.data), 4)
res = self.client.get(reverse('task-list'), {'from': '2015-01-01', 'to': '2015-01-14'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
# two event's tasks in this range, but not the event itself, so nothing should be returned
self.assertEqual(len(res.data), 0)
res = self.client.get(reverse('task-list'), {'from': '2015-01-14', 'to': '2015-02-02'})
self.assertEqual(res.status_code, status.HTTP_200_OK)
# event and the eventless tasks, we should get all 5 tasks
self.assertEqual(len(res.data), 5)