Project

General

Profile

Download (6.53 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / actes / tests.py @ b2f07b82

1 e411dc8b Mikaël Ates
# -*- coding: utf-8 -*-
2 76974b6f Benjamin Dauvergne
from datetime import datetime, date
3 5ae15fa7 Benjamin Dauvergne
4
from django.test import TestCase
5 e411dc8b Mikaël Ates
from django.contrib.auth.models import User
6
7
from validation import automated_validation, are_all_acts_of_the_day_locked, \
8
    get_days_with_acts_not_locked
9
from calebasse.dossiers.models import create_patient
10 76974b6f Benjamin Dauvergne
from calebasse.agenda.models import EventWithAct
11 e411dc8b Mikaël Ates
from calebasse.ressources.models import ActType, Service, WorkerType
12
from calebasse.personnes.models import Worker
13
14
15
class ActTest(TestCase):
16 96692361 Benjamin Dauvergne
    fixtures = ['services', 'filestates']
17 e411dc8b Mikaël Ates
    def test_act_validation(self):
18
        wtype = WorkerType.objects.create(name='ElDoctor', intervene=True)
19
        therapist1 = Worker.objects.create(first_name='Bob', last_name='Leponge', type=wtype)
20
        therapist2 = Worker.objects.create(first_name='Jean', last_name='Valjean', type=wtype)
21
        therapist3 = Worker.objects.create(first_name='Pierre', last_name='PaulJacques', type=wtype)
22
        act_type = ActType.objects.create(name='trepanation')
23 8c43db8d Mikaël Ates
        service = Service.objects.get(name='CMPP')
24 e411dc8b Mikaël Ates
25
        creator = User.objects.create(username='John')
26
        patient = create_patient('John', 'Doe', service, creator)
27
        patient2 = create_patient('Jimmy', 'Claff', service, creator)
28
        patient3 = create_patient('Bouba', 'Lourson', service, creator)
29
30 76974b6f Benjamin Dauvergne
        act_event = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M X', patient,
31 e411dc8b Mikaël Ates
                [therapist1, therapist2], act_type, service,
32
                start_datetime=datetime(2020, 10, 2, 7, 15),
33
                end_datetime=datetime(2020, 10, 2, 9, 20),
34 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 2))
35
        act_event2 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Y', patient, [therapist3],
36 e411dc8b Mikaël Ates
                act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15),
37
                end_datetime=datetime(2020, 10, 2, 12, 20),
38 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 2))
39
        act_event3 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M X', patient2,
40 e411dc8b Mikaël Ates
                [therapist1, therapist2], act_type, service,
41
                start_datetime=datetime(2020, 10, 2, 7, 15),
42
                end_datetime=datetime(2020, 10, 2, 9, 20),
43 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 2))
44
        act_event4 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Y', patient3, [therapist3],
45 e411dc8b Mikaël Ates
                act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15),
46
                end_datetime=datetime(2020, 10, 2, 12, 20),
47 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 2))
48
        act_event5 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Y', patient3, [therapist3],
49 e411dc8b Mikaël Ates
                act_type, service, start_datetime=datetime(2020, 10, 3, 10, 15),
50
                end_datetime=datetime(2020, 10, 3, 12, 20),
51 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 2))
52
        act_event6 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Z', patient, [therapist3],
53 e411dc8b Mikaël Ates
                act_type, service, start_datetime=datetime(2020, 10, 2, 10, 15),
54
                end_datetime=datetime(2020, 10, 2, 12, 20),
55 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 2))
56
        act_event7 = EventWithAct.objects.create_patient_appointment(creator, 'RDV avec M Z', patient, [therapist3],
57 e411dc8b Mikaël Ates
                act_type, service, start_datetime=datetime(2020, 10, 4, 10, 15),
58
                end_datetime=datetime(2020, 10, 4, 12, 20),
59 76974b6f Benjamin Dauvergne
                periodicity=1, until=date(2020, 10, 4))
60 e411dc8b Mikaël Ates
61 76974b6f Benjamin Dauvergne
        act_event3.act.set_state('ABS_EXC', creator)
62
        act_event6.act.set_state('VALIDE', creator)
63 5ae15fa7 Benjamin Dauvergne
64 76974b6f Benjamin Dauvergne
        result = automated_validation(date(2020, 10, 2), service, creator, commit=False)
65 08bf3477 Mikaël Ates
        self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
66 76974b6f Benjamin Dauvergne
        self.assertTrue(act_event.act.is_state('NON_VALIDE'))
67
        self.assertTrue(act_event2.act.is_state('NON_VALIDE'))
68
        self.assertTrue(act_event3.act.is_state('ABS_EXC'))
69
        self.assertTrue(act_event4.act.is_state('NON_VALIDE'))
70
        self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
71
        self.assertTrue(act_event6.act.is_state('VALIDE'))
72 fbec3e9b Mikaël Ates
73 76974b6f Benjamin Dauvergne
        result = automated_validation(date(2020, 10, 2), service, creator)
74 08bf3477 Mikaël Ates
        self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
75 5ae15fa7 Benjamin Dauvergne
76 76974b6f Benjamin Dauvergne
        self.assertTrue(act_event.act.is_state('VALIDE'))
77
        self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
78
        self.assertTrue(act_event3.act.is_state('ABS_EXC'))
79
        self.assertTrue(act_event4.act.is_state('VALIDE'))
80
        self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
81
        self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
82 fbec3e9b Mikaël Ates
83 e411dc8b Mikaël Ates
        self.assertTrue(are_all_acts_of_the_day_locked(datetime(2020, 10, 2, 12, 20)))
84
        self.assertFalse(are_all_acts_of_the_day_locked(datetime(2020, 10, 3, 12, 20)))
85
        self.assertFalse(are_all_acts_of_the_day_locked(datetime(2020, 10, 4, 12, 20)))
86
        self.assertEqual(get_days_with_acts_not_locked(datetime(2020, 10, 2), datetime(2020, 10, 4)),
87 76974b6f Benjamin Dauvergne
            [date(2020, 10, 3), date(2020, 10, 4)])
88 fbec3e9b Mikaël Ates
89
        result = automated_validation(datetime(2020, 10, 2, 12, 20), service, creator, commit=False)
90 08bf3477 Mikaël Ates
        self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
91 76974b6f Benjamin Dauvergne
        self.assertTrue(act_event.act.is_state('VALIDE'))
92
        self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
93
        self.assertTrue(act_event3.act.is_state('ABS_EXC'))
94
        self.assertTrue(act_event4.act.is_state('VALIDE'))
95
        self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
96
        self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
97 fbec3e9b Mikaël Ates
98
        result = automated_validation(datetime(2020, 10, 2, 12, 20), service, creator)
99 08bf3477 Mikaël Ates
        self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
100 76974b6f Benjamin Dauvergne
        self.assertTrue(act_event.act.is_state('VALIDE'))
101
        self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
102
        self.assertTrue(act_event3.act.is_state('ABS_EXC'))
103
        self.assertTrue(act_event4.act.is_state('VALIDE'))
104
        self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
105
        self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))
106 fbec3e9b Mikaël Ates
107
        result = automated_validation(datetime(2020, 10, 2, 12, 20), service, creator, commit=False)
108 08bf3477 Mikaël Ates
        self.assertEqual(result, (5,2,2,0,1,0,0,0,0,0,0,0))
109 76974b6f Benjamin Dauvergne
        self.assertTrue(act_event.act.is_state('VALIDE'))
110
        self.assertTrue(act_event2.act.is_state('ACT_DOUBLE'))
111
        self.assertTrue(act_event3.act.is_state('ABS_EXC'))
112
        self.assertTrue(act_event4.act.is_state('VALIDE'))
113
        self.assertTrue(act_event5.act.is_state('NON_VALIDE'))
114
        self.assertTrue(act_event6.act.is_state('ACT_DOUBLE'))