Revision 76974b6f
Added by Benjamin Dauvergne almost 12 years ago
calebasse/agenda/tests.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
Replace this with more appropriate tests for your application. |
6 | 6 |
""" |
7 |
from datetime import datetime |
|
7 |
from datetime import datetime, date, timedelta
|
|
8 | 8 |
|
9 | 9 |
from django.test import TestCase |
10 | 10 |
from django.contrib.auth.models import User |
11 |
from datetime import datetime, date |
|
12 |
from dateutil import rrule |
|
13 | 11 |
|
14 |
from calebasse.agenda.models import Occurrence, Event |
|
15 |
from calebasse.actes.models import EventAct |
|
16 |
from calebasse.dossiers.models import PatientRecord |
|
12 |
from calebasse.agenda.models import Event, EventType, EventWithAct |
|
17 | 13 |
from calebasse.dossiers.models import create_patient |
18 | 14 |
from calebasse.ressources.models import ActType, Service, WorkerType |
19 | 15 |
from calebasse.personnes.models import Worker |
16 |
from calebasse.actes.models import Act |
|
20 | 17 |
|
21 | 18 |
class EventTest(TestCase): |
22 | 19 |
fixtures = ['services', 'filestates'] |
23 | 20 |
def setUp(self): |
24 | 21 |
self.creator = User.objects.create(username='John') |
25 | 22 |
|
26 |
def test_create_events(self): |
|
27 |
event = Event.objects.create_event("test 1", 'un test', description='42 42', |
|
28 |
start_datetime=datetime(2012, 10, 20, 13), end_datetime=datetime(2012, 10, 20, 14), |
|
29 |
freq=rrule.WEEKLY, count=3) |
|
30 |
self.assertEqual(str(event), 'test 1') |
|
23 |
def test_recurring_events(self): |
|
24 |
event = Event.objects.create(start_datetime=datetime(2012, 10, 20, 13), |
|
25 |
end_datetime=datetime(2012, 10, 20, 13, 30), event_type=EventType(id=1), |
|
26 |
recurrence_week_period=3, recurrence_end_date=date(2012, 12, 1)) |
|
27 |
event.clean() |
|
28 |
event.save() |
|
29 |
# Test model |
|
30 |
self.assertEqual(event.timedelta(), timedelta(minutes=30)) |
|
31 |
occurences = list(event.all_occurences()) |
|
32 |
self.assertEqual(occurences[0].start_datetime, |
|
33 |
datetime(2012, 10, 20, 13)) |
|
34 |
self.assertEqual(occurences[0].end_datetime, |
|
35 |
datetime(2012, 10, 20, 13, 30)) |
|
36 |
self.assertEqual(occurences[1].start_datetime, |
|
37 |
datetime(2012, 11, 10, 13)) |
|
38 |
self.assertEqual(occurences[1].end_datetime, |
|
39 |
datetime(2012, 11, 10, 13, 30)) |
|
40 |
self.assertEqual(occurences[2].start_datetime, |
|
41 |
datetime(2012, 12, 1, 13)) |
|
42 |
self.assertEqual(occurences[2].end_datetime, |
|
43 |
datetime(2012, 12, 1, 13, 30)) |
|
44 |
self.assertEqual(len(occurences), 3) |
|
45 |
self.assertTrue(event.is_recurring()) |
|
46 |
self.assertEqual(event.next_occurence(today=date(2012, 10, 21)).start_datetime, |
|
47 |
datetime(2012, 11, 10, 13)) |
|
48 |
self.assertEqual(event.next_occurence(today=date(2012, 11, 30)).start_datetime, |
|
49 |
datetime(2012, 12, 1, 13)) |
|
50 |
self.assertEqual(event.next_occurence(today=date(2012, 12, 2)), None) |
|
51 |
# Test manager |
|
52 |
i = datetime(2012, 10, 1) |
|
53 |
while i < datetime(2013, 2, 1): |
|
54 |
d = i.date() |
|
55 |
if d in (date(2012, 10, 20), date(2012, 11, 10), date(2012, 12, 1)): |
|
56 |
self.assertEqual(list(Event.objects.for_today(d)), [event], d) |
|
57 |
else: |
|
58 |
self.assertEqual(list(Event.objects.for_today(d)), [], d) |
|
59 |
i += timedelta(days=1) |
|
60 |
|
|
31 | 61 |
|
32 | 62 |
def test_create_appointments(self): |
33 |
service_camsp = Service.objects.create(name='CAMSP')
|
|
63 |
service_camsp = Service.objects.get(name='CAMSP')
|
|
34 | 64 |
|
35 |
patient = create_patient('Jean', 'Lepoulpe', service_camsp, self.creator, date_selected=datetime(2020, 10, 5))
|
|
65 |
patient = create_patient('Jean', 'LEPOULPE', service_camsp, self.creator, date_selected=datetime(2020, 10, 5))
|
|
36 | 66 |
wtype = WorkerType.objects.create(name='ElDoctor', intervene=True) |
37 | 67 |
therapist1 = Worker.objects.create(first_name='Bob', last_name='Leponge', type=wtype) |
38 | 68 |
therapist2 = Worker.objects.create(first_name='Jean', last_name='Valjean', type=wtype) |
39 |
therapist3 = Worker.objects.create(first_name='Pierre', last_name='PaulJacques', type=wtype) |
|
40 | 69 |
act_type = ActType.objects.create(name='trepanation') |
41 | 70 |
service = Service.objects.create(name='CMPP') |
42 |
act_event = EventAct.objects.create_patient_appointment(self.creator, 'RDV avec M X', patient,
|
|
71 |
appointment1 = EventWithAct.objects.create_patient_appointment(self.creator, 'RDV avec M X', patient,
|
|
43 | 72 |
[therapist1, therapist2], act_type, service, |
44 | 73 |
start_datetime=datetime(2020, 10, 2, 7, 15), |
45 | 74 |
end_datetime=datetime(2020, 10, 2, 9, 20), |
46 |
freq=rrule.WEEKLY, byweekday=rrule.FR, until=datetime(2040, 10, 2)) |
|
47 |
act_event2 = EventAct.objects.create_patient_appointment(self.creator, 'RDV avec M Y', patient, [therapist3], |
|
75 |
periodicity=None, until=None) |
|
76 |
self.assertEqual(unicode(appointment1), u'Rdv le 2020-10-02 07:15:00 de Jean LEPOULPE avec Bob LEPONGE, Jean VALJEAN pour trepanation (1)') |
|
77 |
|
|
78 |
def test_create_recurring_appointment(self): |
|
79 |
service_camsp = Service.objects.get(name='CAMSP') |
|
80 |
patient = create_patient('Jean', 'LEPOULPE', service_camsp, self.creator, date_selected=datetime(2020, 10, 5)) |
|
81 |
wtype = WorkerType.objects.create(name='ElDoctor', intervene=True) |
|
82 |
therapist3 = Worker.objects.create(first_name='Pierre', last_name='PaulJacques', type=wtype) |
|
83 |
act_type = ActType.objects.create(name='trepanation') |
|
84 |
service = Service.objects.create(name='CMPP') |
|
85 |
appointment2 = EventWithAct.objects.create_patient_appointment(self.creator, 'RDV avec M Y', patient, [therapist3], |
|
48 | 86 |
act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15), |
49 | 87 |
end_datetime=datetime(2020, 10, 2, 12, 20), |
50 |
freq=rrule.WEEKLY, byweekday=rrule.FR, until=datetime(2021, 10, 2)) |
|
51 |
self.assertEqual(str(act_event), 'Rdv le 2020-10-02 07:15:00 de Jean Lepoulpe avec Bob Leponge, Jean Valjean pour trepanation (1)') |
|
52 |
self.assertEqual( |
|
53 |
str(Occurrence.objects.daily_occurrences(datetime(2020, 10, 8), [therapist2])), |
|
54 |
'[]' |
|
55 |
) |
|
56 |
self.assertEqual( |
|
57 |
str(Occurrence.objects.daily_occurrences(datetime(2020, 10, 9), [therapist2])), |
|
58 |
'[<Occurrence: RDV avec M X: 2020-10-09T07:15:00>]' |
|
59 |
) |
|
60 |
self.assertEqual( |
|
61 |
str(Occurrence.objects.daily_occurrences(datetime(2020, 10, 9), [therapist3])), |
|
62 |
'[<Occurrence: RDV avec M Y: 2020-10-09T10:15:00>]' |
|
63 |
) |
|
88 |
periodicity=2, until=date(2020, 10, 16)) |
|
89 |
occurences = list(appointment2.all_occurences()) |
|
90 |
self.assertEqual(len(occurences), 2) |
|
91 |
self.assertEqual(Act.objects.filter(parent_event=appointment2).count(), |
|
92 |
2) |
|
93 |
self.assertEqual(occurences[0].act.date, occurences[0].start_datetime.date()) |
|
94 |
self.assertEqual(occurences[1].act.date, occurences[1].start_datetime.date()) |
|
95 |
self.assertEqual(Act.objects.filter(parent_event=appointment2).count(), |
|
96 |
2) |
|
97 |
appointment2.recurrence_week_period = None |
|
98 |
appointment2.save() |
|
99 |
self.assertEqual(Act.objects.filter(parent_event=appointment2).count(), |
|
100 |
1) |
|
101 |
appointment2.recurrence_week_period = 2 |
|
102 |
appointment2.recurrence_end_date = date(2020, 10, 16) |
|
103 |
appointment2.save() |
|
104 |
occurences = list(appointment2.all_occurences()) |
|
105 |
self.assertEqual(len(occurences), 2) |
|
106 |
self.assertEqual(Act.objects.filter(parent_event=appointment2).count(), 2) |
|
107 |
occurences[1].act.set_state('ANNUL_NOUS', self.creator) |
|
108 |
appointment2.recurrence_week_period = None |
|
109 |
appointment2.save() |
|
110 |
occurences = list(appointment2.all_occurences()) |
|
111 |
self.assertEqual(len(occurences), 1) |
|
112 |
self.assertEqual(Act.objects.filter(parent_event=appointment2).count(), 1) |
|
113 |
self.assertEqual(Act.objects.count(), 2) |
|
64 | 114 |
|
65 |
def test_create_holiday(self): |
|
66 |
"""docstring for test_create_event""" |
|
67 |
wtype = WorkerType.objects.create(name='ElProfessor', intervene=True) |
|
68 |
user = Worker.objects.create(first_name='Jean-Claude', last_name='Van Damme', type=wtype) |
|
69 |
event = Event.objects.create_holiday(date(2012, 12, 12), date(2012,12,30), |
|
70 |
[user], motive='tournage d\'un film') |
|
71 |
self.assertEqual(str(event), 'Conge') |
|
72 |
#event = user.event.occurrence_set.all()[0] |
|
73 |
#self.assertEqual(event.end_time - event.start_time, timedelta(0, 7200)) |
Also available in: Unified diff
agenda/actes/dossiers: move Occurence fields into Event, add recurring events support