Skip to content

Commit 54841d9

Browse files
committed
change test to mnist
1 parent 4c7080d commit 54841d9

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

test/pytest/test_data/0.png

272 Bytes
Loading

test/pytest/test_token_authorization.py

+17-22
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
ROOT_DIR = os.path.join(tempfile.gettempdir(), "workspace")
1414
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")
1616
config_file = os.path.join(REPO_ROOT, "test/resources/config_token.properties")
1717

1818

@@ -46,11 +46,6 @@ def read_key_file(type):
4646
with open(json_file_path) as json_file:
4747
json_data = json.load(json_file)
4848

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-
5449
options = {
5550
"management": json_data.get("management", {}).get("key", "NOT_PRESENT"),
5651
"inference": json_data.get("inference", {}).get("key", "NOT_PRESENT"),
@@ -74,8 +69,8 @@ def setup_torchserve():
7469
header = {"Authorization": f"Bearer {key}"}
7570

7671
params = (
77-
("model_name", "resnet18"),
78-
("url", "resnet-18.mar"),
72+
("model_name", "mnist"),
73+
("url", "mnist.mar"),
7974
("initial_workers", "1"),
8075
("synchronous", "true"),
8176
)
@@ -106,8 +101,8 @@ def setup_torchserve_expiration():
106101
header = {"Authorization": f"Bearer {key}"}
107102

108103
params = (
109-
("model_name", "resnet18"),
110-
("url", "resnet-18.mar"),
104+
("model_name", "mnist"),
105+
("url", "mnist.mar"),
111106
("initial_workers", "1"),
112107
("synchronous", "true"),
113108
)
@@ -126,7 +121,7 @@ def setup_torchserve_expiration():
126121
def test_managament_api_with_token(setup_torchserve):
127122
key = read_key_file("management")
128123
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)
130125

131126
assert response.status_code == 200, "Token check failed"
132127

@@ -135,7 +130,7 @@ def test_managament_api_with_token(setup_torchserve):
135130
def test_managament_api_with_incorrect_token(setup_torchserve):
136131
# Using random key
137132
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)
139134

140135
assert response.status_code == 400, "Token check failed"
141136

@@ -146,8 +141,8 @@ def test_inference_api_with_token(setup_torchserve):
146141
header = {"Authorization": f"Bearer {key}"}
147142

148143
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")},
151146
headers=header,
152147
)
153148

@@ -160,8 +155,8 @@ def test_inference_api_with_incorrect_token(setup_torchserve):
160155
header = {"Authorization": "Bearer abcd1234"}
161156

162157
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")},
165160
headers=header,
166161
)
167162

@@ -178,8 +173,8 @@ def test_token_inference_api(setup_torchserve):
178173

179174
# check inference works with current token
180175
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")},
183178
headers=header_inference,
184179
)
185180
assert response.status_code == 200, "Token check failed"
@@ -193,8 +188,8 @@ def test_token_inference_api(setup_torchserve):
193188

194189
# check inference does not works with original token
195190
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")},
198193
headers=header_inference,
199194
)
200195
assert response.status_code == 400, "Token check failed"
@@ -220,10 +215,10 @@ def test_token_management_api(setup_torchserve):
220215
def test_token_expiration_time(setup_torchserve_expiration):
221216
key = read_key_file("management")
222217
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)
224219
assert response.status_code == 200, "Token check failed"
225220

226221
time.sleep(15)
227222

228-
response = requests.get("http://localhost:8081/models/resnet18", headers=header)
223+
response = requests.get("http://localhost:8081/models/mnist", headers=header)
229224
assert response.status_code == 400, "Token check failed"

0 commit comments

Comments
 (0)