Project

General

Profile

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

calebasse / calebasse / dossiers / tests.py @ a9520794

1 8b82d1fa Mikaël Ates
# -*- coding: utf-8 -*-
2 1af9e727 Frédéric Péters
import datetime
3
4 8b82d1fa Mikaël Ates
from django.test import TestCase
5
from django.contrib.auth.models import User
6 5ae15fa7 Benjamin Dauvergne
7 1af9e727 Frédéric Péters
from models import create_patient, PatientContact
8 586af040 Jérôme Schneider
from calebasse.dossiers.models import Status
9 bb8c46e4 Mikaël Ates
from calebasse.ressources.models import Service
10 5ae15fa7 Benjamin Dauvergne
11
12 8b82d1fa Mikaël Ates
class PatientRecordTest(TestCase):
13 5ae15fa7 Benjamin Dauvergne
14 8b82d1fa Mikaël Ates
    def test_states(self):
15
        creator = User.objects.create(username='John')
16 586af040 Jérôme Schneider
        for service in Service.objects.all():
17 8b82d1fa Mikaël Ates
            patient = create_patient('John', 'Doe', service, creator)
18 586af040 Jérôme Schneider
            for status in Status.objects.filter(services=service):
19
                patient.set_state(status, creator)
20 1af9e727 Frédéric Péters
21
22
class AgeTest(TestCase):
23
    def test_unknown(self):
24
        patient = PatientContact()
25
        self.assertEqual(patient.age(), "inconnu")
26
27
    def test_one_day(self):
28
        patient = PatientContact()
29
        patient.birthdate = datetime.date.today() - datetime.timedelta(days=1)
30
        self.assertEqual(patient.age(), "1 jour")
31
32
    def test_three_days(self):
33
        patient = PatientContact()
34
        patient.birthdate = datetime.date.today() - datetime.timedelta(days=3)
35
        self.assertEqual(patient.age(), "3 jours")
36
37
    def test_two_months(self):
38
        patient = PatientContact()
39
        today = datetime.date.today()
40
        if today.day > 28:
41
            # don't run this test on such months, we can't be sure the exact
42
            # date will exist
43
            return
44
        date = today - datetime.timedelta(days=65)
45
        patient.birthdate = datetime.date(date.year, date.month, today.day)
46
        self.assertEqual(patient.age(), "2 mois")
47
48
    def test_two_months_one_day(self):
49
        patient = PatientContact()
50
        today = datetime.date.today()
51
        if today.day > 28:
52
            # don't run this test on such months, we can't be sure the exact
53
            # date will exist
54
            return
55
        date = today - datetime.timedelta(days=62)
56
        patient.birthdate = datetime.date(date.year, date.month, today.day) - datetime.timedelta(days=1)
57
        self.assertEqual(patient.age(), "2 mois et 1 jour")
58
59
    def test_two_months_three_days(self):
60
        patient = PatientContact()
61
        today = datetime.date.today()
62
        if today.day > 25:
63
            # don't run this test on such months, we can't be sure the exact
64
            # date will exist
65
            return
66
        date = today - datetime.timedelta(days=62)
67
        patient.birthdate = datetime.date(date.year, date.month, today.day) - datetime.timedelta(days=3)
68
        self.assertEqual(patient.age(), "2 mois et 3 jours")
69
70
    def test_six_months(self):
71
        patient = PatientContact()
72
        today = datetime.date.today()
73
        date = today - datetime.timedelta(days=31*6)
74
        patient.birthdate = datetime.date(date.year, date.month, date.day)
75
        self.assertEqual(patient.age(), "6 mois")
76
77
    def test_thirtheen_months(self):
78
        patient = PatientContact()
79
        today = datetime.date.today()
80
        date = today - datetime.timedelta(days=31*13)
81
        patient.birthdate = datetime.date(date.year, date.month, date.day)
82
        self.assertEqual(patient.age(), "13 mois")
83
84
    def test_two_years(self):
85
        patient = PatientContact()
86
        today = datetime.date.today()
87
        date = today
88
        patient.birthdate = datetime.date(date.year-2, date.month, date.day)
89
        self.assertEqual(patient.age(), "2 ans")
90
        self.assertEqual(patient.age(age_format='months_only'), "24 mois")
91
92
    def test_two_years_one_month(self):
93
        patient = PatientContact()
94
        today = datetime.date.today()
95
        date = today
96
        patient.birthdate = datetime.date(date.year-2, date.month, date.day) - \
97
                datetime.timedelta(days=31)
98
        self.assertEqual(patient.age(), "2 ans et 1 mois")
99
        self.assertEqual(patient.age(age_format='months_only'), "25 mois")