natexcvi commited on
Commit
0e92099
1 Parent(s): 2f18963

Refactor auth test

Browse files
Files changed (1) hide show
  1. test_service.py +11 -11
test_service.py CHANGED
@@ -72,18 +72,18 @@ def test_similarity(client: TestClient, image1_path, image2_path, exp_score):
72
  assert response.json()["score"] == pytest.approx(exp_score, abs=1e-4)
73
 
74
 
75
- def test_authentication(client: TestClient):
76
- response = client.post(
77
- "/embed",
78
- files=[("image", ("face_pic.jpeg", b""))],
79
- )
80
- assert response.status_code == 401
81
- assert response.json()["detail"] == "No token provided"
82
-
83
  response = client.post(
84
  "/embed",
85
  files=[("image", ("face_pic.jpeg", b""))],
86
- params={"token": "wrong_token"},
87
  )
88
- assert response.status_code == 401
89
- assert response.json()["detail"] == "Invalid token"
 
72
  assert response.json()["score"] == pytest.approx(exp_score, abs=1e-4)
73
 
74
 
75
+ @pytest.mark.parametrize(
76
+ "token, status_code, detail",
77
+ [
78
+ pytest.param(None, 401, "No token provided", id="no token"),
79
+ pytest.param("wrong_token", 401, "Invalid token", id="wrong token"),
80
+ ],
81
+ )
82
+ def test_authentication(client: TestClient, token: str, status_code: int, detail: str):
83
  response = client.post(
84
  "/embed",
85
  files=[("image", ("face_pic.jpeg", b""))],
86
+ params={"token": token} if token else {},
87
  )
88
+ assert response.status_code == status_code
89
+ assert response.json()["detail"] == detail