Révision 1af9e727
Ajouté par Frédéric Péters il y a plus de 9 ans
calebasse/dossiers/tests.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 |
import datetime |
|
3 |
|
|
2 | 4 |
from django.test import TestCase |
3 | 5 |
from django.contrib.auth.models import User |
4 | 6 |
|
5 |
from models import create_patient |
|
7 |
from models import create_patient, PatientContact
|
|
6 | 8 |
from calebasse.dossiers.models import Status |
7 | 9 |
from calebasse.ressources.models import Service |
8 | 10 |
|
... | ... | |
15 | 17 |
patient = create_patient('John', 'Doe', service, creator) |
16 | 18 |
for status in Status.objects.filter(services=service): |
17 | 19 |
patient.set_state(status, creator) |
20 |
|
|
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") |
Formats disponibles : Unified diff
dossiers: make the age format configurable via service settings
Closes #5469