-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_app.py
More file actions
80 lines (73 loc) · 2.99 KB
/
test_app.py
File metadata and controls
80 lines (73 loc) · 2.99 KB
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
from fastapi.testclient import TestClient
from main import app
from datetime import datetime
# test to check the correct functioning of the /ping route
def test_ping():
with TestClient(app) as client:
response = client.get("/ping")
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["ping"] == "pong" # Changing the syntax due to added timestamp
# test to check if Iris Virginica is classified correctly
def test_pred_no_defects():
''' Test case 1 '''
# defining a sample payload for the testcase
payload = {
"mccabe_line_count_of_code": 24,
"mccabe_cyclomatic_complexity": 5,
"mccabe_essential_complexity": 1,
"mccabe_design_complexity": 3,
"halstead_total_operators_operands": 63,
"halstead_volume": 309.13,
"halstead_program_length": 0.11,
"halstead_difficulty": 9.5,
"halstead_intelligence": 32.54,
"halstead_effort": 2936.77,
"halstead_b": 0.1,
"halstead_time_estimator": 163.15,
"halstead_line_count": 1,
"halstead_count_of_lines_of_comments": 0,
"halstead_count_of_blank_lines": 6,
"lOCodeAndComment": 0,
"unique_operators": 15,
"unique_operands": 15,
"total_operators": 44,
"total_operands": 19,
"branchCount": 9
}
with TestClient(app) as client:
response = client.post("/predict", json=payload)
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["defects"] == "No defects" # Changing the syntax due to added timestamp
def test_pred_defects():
''' Test case 2 '''
# defining a sample payload for the testcase
payload = {
"mccabe_line_count_of_code": 28,
"mccabe_cyclomatic_complexity": 6,
"mccabe_essential_complexity": 5,
"mccabe_design_complexity": 5,
"halstead_total_operators_operands": 104,
"halstead_volume": 564.33,
"halstead_program_length": 0.06,
"halstead_difficulty": 16.09,
"halstead_intelligence": 35.08,
"halstead_effort": 9078.38,
"halstead_b": 0.19,
"halstead_time_estimator": 504.35,
"halstead_line_count": 2,
"halstead_count_of_lines_of_comments": 7,
"halstead_count_of_blank_lines": 0,
"lOCodeAndComment": 0,
"unique_operators": 20,
"unique_operands": 23,
"total_operators": 67,
"total_operands": 37,
"branchCount": 11
}
with TestClient(app) as client:
response = client.post("/predict", json=payload)
# asserting the correct response is received
assert response.status_code == 200
assert response.json()["defects"] == "defects" # Changing the syntax due to added timestamp