12
12
13
13
ROOT_DIR = os .path .join (tempfile .gettempdir (), "workspace" )
14
14
REPO_ROOT = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "../../" )
15
- data_file_kitten = os .path .join (REPO_ROOT , "test/pytest/test_data/kitten.jpg " )
15
+ data_file_zero = os .path .join (REPO_ROOT , "test/pytest/test_data/0.png " )
16
16
config_file = os .path .join (REPO_ROOT , "test/resources/config_token.properties" )
17
17
18
18
@@ -46,11 +46,6 @@ def read_key_file(type):
46
46
with open (json_file_path ) as json_file :
47
47
json_data = json .load (json_file )
48
48
49
- # Extract the three keys
50
- # management_key =
51
- # inference_key = json_data.get("inference", {}).get("key", "NOT_PRESENT")
52
- # api_key = json_data.get("API", {}).get("key", "NOT_PRESENT")
53
-
54
49
options = {
55
50
"management" : json_data .get ("management" , {}).get ("key" , "NOT_PRESENT" ),
56
51
"inference" : json_data .get ("inference" , {}).get ("key" , "NOT_PRESENT" ),
@@ -74,8 +69,8 @@ def setup_torchserve():
74
69
header = {"Authorization" : f"Bearer { key } " }
75
70
76
71
params = (
77
- ("model_name" , "resnet18 " ),
78
- ("url" , "resnet-18 .mar" ),
72
+ ("model_name" , "mnist " ),
73
+ ("url" , "mnist .mar" ),
79
74
("initial_workers" , "1" ),
80
75
("synchronous" , "true" ),
81
76
)
@@ -106,8 +101,8 @@ def setup_torchserve_expiration():
106
101
header = {"Authorization" : f"Bearer { key } " }
107
102
108
103
params = (
109
- ("model_name" , "resnet18 " ),
110
- ("url" , "resnet-18 .mar" ),
104
+ ("model_name" , "mnist " ),
105
+ ("url" , "mnist .mar" ),
111
106
("initial_workers" , "1" ),
112
107
("synchronous" , "true" ),
113
108
)
@@ -126,7 +121,7 @@ def setup_torchserve_expiration():
126
121
def test_managament_api_with_token (setup_torchserve ):
127
122
key = read_key_file ("management" )
128
123
header = {"Authorization" : f"Bearer { key } " }
129
- response = requests .get ("http://localhost:8081/models/resnet18 " , headers = header )
124
+ response = requests .get ("http://localhost:8081/models/mnist " , headers = header )
130
125
131
126
assert response .status_code == 200 , "Token check failed"
132
127
@@ -135,7 +130,7 @@ def test_managament_api_with_token(setup_torchserve):
135
130
def test_managament_api_with_incorrect_token (setup_torchserve ):
136
131
# Using random key
137
132
header = {"Authorization" : "Bearer abcd1234" }
138
- response = requests .get (f"http://localhost:8081/models/resnet18 " , headers = header )
133
+ response = requests .get (f"http://localhost:8081/models/mnist " , headers = header )
139
134
140
135
assert response .status_code == 400 , "Token check failed"
141
136
@@ -146,8 +141,8 @@ def test_inference_api_with_token(setup_torchserve):
146
141
header = {"Authorization" : f"Bearer { key } " }
147
142
148
143
response = requests .post (
149
- url = "http://localhost:8080/predictions/resnet18 " ,
150
- files = {"data" : open (data_file_kitten , "rb" )},
144
+ url = "http://localhost:8080/predictions/mnist " ,
145
+ files = {"data" : open (data_file_zero , "rb" )},
151
146
headers = header ,
152
147
)
153
148
@@ -160,8 +155,8 @@ def test_inference_api_with_incorrect_token(setup_torchserve):
160
155
header = {"Authorization" : "Bearer abcd1234" }
161
156
162
157
response = requests .post (
163
- url = "http://localhost:8080/predictions/resnet18 " ,
164
- files = {"data" : open (data_file_kitten , "rb" )},
158
+ url = "http://localhost:8080/predictions/mnist " ,
159
+ files = {"data" : open (data_file_zero , "rb" )},
165
160
headers = header ,
166
161
)
167
162
@@ -178,8 +173,8 @@ def test_token_inference_api(setup_torchserve):
178
173
179
174
# check inference works with current token
180
175
response = requests .post (
181
- url = "http://localhost:8080/predictions/resnet18 " ,
182
- files = {"data" : open (data_file_kitten , "rb" )},
176
+ url = "http://localhost:8080/predictions/mnist " ,
177
+ files = {"data" : open (data_file_zero , "rb" )},
183
178
headers = header_inference ,
184
179
)
185
180
assert response .status_code == 200 , "Token check failed"
@@ -193,8 +188,8 @@ def test_token_inference_api(setup_torchserve):
193
188
194
189
# check inference does not works with original token
195
190
response = requests .post (
196
- url = "http://localhost:8080/predictions/resnet18 " ,
197
- files = {"data" : open (data_file_kitten , "rb" )},
191
+ url = "http://localhost:8080/predictions/mnist " ,
192
+ files = {"data" : open (data_file_zero , "rb" )},
198
193
headers = header_inference ,
199
194
)
200
195
assert response .status_code == 400 , "Token check failed"
@@ -220,10 +215,10 @@ def test_token_management_api(setup_torchserve):
220
215
def test_token_expiration_time (setup_torchserve_expiration ):
221
216
key = read_key_file ("management" )
222
217
header = {"Authorization" : f"Bearer { key } " }
223
- response = requests .get ("http://localhost:8081/models/resnet18 " , headers = header )
218
+ response = requests .get ("http://localhost:8081/models/mnist " , headers = header )
224
219
assert response .status_code == 200 , "Token check failed"
225
220
226
221
time .sleep (15 )
227
222
228
- response = requests .get ("http://localhost:8081/models/resnet18 " , headers = header )
223
+ response = requests .get ("http://localhost:8081/models/mnist " , headers = header )
229
224
assert response .status_code == 400 , "Token check failed"
0 commit comments