-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_load_balancer.py
139 lines (125 loc) · 4 KB
/
test_load_balancer.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from load_balancer_sliced import load_balancer
import json
import pytest
@pytest.fixture
def client():
with load_balancer.test_client() as client:
yield client
def test_hello_connection_test(client):
payload = dict(
job_name = "Tapan",
job_id = 2,
num_jobs = 12,
job_duration = 2,
)
result = client.post('/first_hello', data=payload, content_type='application/json')
assert b"OK" in result.data
def test_loadbalancer1_valid_input(client):
payload = dict(
job_name = "Tapan",
job_id = 4,
num_jobs = 11,
job_duration = 3,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"OK" in result.data
def test_loadbalancer2_invalid_jobname_1(client):
payload = dict(
job_name = None,
job_id = 1,
num_jobs = 2,
job_duration = 2,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer3_invalid_jobname_2(client):
payload = dict(
job_name = "",
job_id = 1,
num_jobs = 2,
job_duration = 2,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer4_invalid_jobid_1(client):
payload = dict(
job_name = "Tapan",
job_id = 3,
num_jobs = 2,
job_duration = 15,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer5_invalid_jobname_3(client):
payload = dict(
job_name = "j-1234858585858585858588585948359348594385983",
job_id = 1,
num_jobs = 50,
job_duration = 2,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer6_invalid_numjobs_1(client):
payload = dict(
job_name = "Tapan",
job_id = 1,
num_jobs = 101,
job_duration = 29,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer7_invalid_jobduration_1(client):
payload = dict(
job_name = "Tapan",
job_id = 1,
num_jobs = 99,
job_duration = 0,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer8_invalid_jobduration_2(client):
payload = dict(
job_name = "Tapan",
job_id = 1,
num_jobs = 100,
job_duration = 31,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer9_invalid_jobid_2(client):
payload = dict(
job_name = "Tapan",
job_id = -1,
num_jobs = 100,
job_duration = 31,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer10_invalid_jobid_3(client):
payload = dict(
job_name = "Tapan",
job_id = 102,
num_jobs = 100,
job_duration = 20,
)
payload = json.dumps(payload)
result = client.post('/DCN', data=payload, content_type='application/json')
assert b"Invalid Input" in result.data
def test_loadbalancer11_all_invalid(client):
payload = dict(
job_name = "",
job_id = -1,
num_jobs = 0,
job_duration = 0,
)
result = client.post('/DCN', json=payload)
assert b"Invalid Input" in result.data