-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
105 lines (84 loc) · 3.47 KB
/
tests.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/python3
# coding: utf-8
from __future__ import unicode_literals
"""
M2 TAL, INGÉNIERIE MULTILINGUE : TECHNIQUES WEB (REST API)
------------------------------------------
Ce module teste les fonctionnalités de l'API.
:copyright: © 2022 by Élise & Lufei & Alexandra.
"""
__version__ = "0.1"
import unittest
class TestURLs(unittest.TestCase):
""" TestCase for back.resources module """
def test_login(self):
from front.models.api import login_api
from front.app import dataviewerFront as frontend
from back.app import dataviewerBack as backend
tester = backend.test_client(self)
response = tester.post('/login', data={'email':'[email protected]', 'password':'1234'})
self.assertEqual(response.status_code, 200)
def test_register(self):
from back.app import dataviewerBack as backend
tester = backend.test_client(self)
response = tester.post('/register', data={'name':'Toto', 'email':'[email protected]', 'password':'1234'})
self.assertEqual(response.status_code, 200)
def test_get_all_data(self):
from back.app import dataviewerBack as backend
tester = backend.test_client(self)
response = tester.get('/covid/')
self.assertEqual(response.status_code, 200)
def test_create_data(self):
from back.app import dataviewerBack as backend
tester = backend.test_client(self)
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImFiY2RAMTYzLmNvbSIsImV4cCI6MTY0OTYzMDczMX0.JnuHTGTlYWAjq2p0SLso97Vm6kT-rt5KAGGcjo6iTYk"
headers = {"x-access-token": token}
response = tester.post('/covid/',
headers=headers,
data={
"classe_age": "65-74",
"commune_residence": 444,
"date_reference": "2022-03-22",
"effectif_1_inj": 0,
"effectif_cumu_1_inj": 1750,
"effectif_cumu_termine": 1730,
"effectif_termine": 0,
"libelle_classe_age": "de 65 à 74 ans",
"libelle_commune": "SASHAVILLE",
"population_carto": 680,
"semaine_injection": "2021-44",
"taux_1_inj": 0.018,
"taux_cumu_1_inj": 0.747,
"taux_cumu_termine": 0.823,
"taux_termine": 0.010
})
self.assertEqual(response.status_code, 200)
def test_create_data_fail(self):
from back.app import dataviewerBack as backend
tester = backend.test_client(self)
response = tester.post('/covid/',
data={
"classe_age": "65-74",
"commune_residence": 444,
"date_reference": "2022-03-22",
"effectif_1_inj": 0,
"effectif_cumu_1_inj": 1750,
"effectif_cumu_termine": 1730,
"effectif_termine": 0,
"libelle_classe_age": "de 65 à 74 ans",
"libelle_commune": "SASHAVILLE",
"population_carto": 680,
"semaine_injection": "2021-44",
"taux_1_inj": 0.018,
"taux_cumu_1_inj": 0.747,
"taux_cumu_termine": 0.823,
"taux_termine": 0.010
})
self.assertNotEqual(response.status_code, 200)
def test_get_one_data_from_id(self):
from back.app import dataviewerBack as backend
tester = backend.test_client(self)
response = tester.get('/covid/512/')
self.assertEqual(response.status_code, 200)
if __name__ == '__main__':
unittest.main(verbosity=8)