Skip to content

Commit 96637a4

Browse files
committed
chore: Updated tests
1 parent 19bf428 commit 96637a4

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

tests/controllers/test_auth_controller.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def test_signup_success():
1414
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=None)), \
1515
patch("app.controllers.auth_controller.create_user", new=AsyncMock()):
16-
response = client.post("/auth/signup", json={
16+
response = client.post("/signup", json={
1717
"email": "test@example.com",
1818
"password": "13pAssword*"
1919
})
@@ -24,7 +24,7 @@ def test_signup_success():
2424

2525
def test_signup_user_exists():
2626
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value={"email": "test@example.com"})):
27-
response = client.post("/auth/signup", json={"email": "test@example.com", "password": "13pAssword*"})
27+
response = client.post("/signup", json={"email": "test@example.com", "password": "13pAssword*"})
2828
assert response.status_code == 409
2929
assert response.json()["code"] == "user_already_exists"
3030
assert response.json()["message"] == "User with this email already exists"
@@ -39,15 +39,15 @@ def test_signup_user_exists():
3939
def test_signup_fails_with_weak_password(password, status_code, error_message):
4040
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=None)), \
4141
patch("app.controllers.auth_controller.create_user", new=AsyncMock()):
42-
response = client.post("/auth/signup", json={"email": "test@example.com", "password": password})
42+
response = client.post("/signup", json={"email": "test@example.com", "password": password})
4343
assert response.status_code == status_code
4444
assert response.json()["code"] == "validation_error"
4545
assert response.json()["message"] == error_message
4646

4747

4848
def test_signup_wrong_email():
4949
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=None)):
50-
response = client.post("/auth/signup", json={"email": "some_text", "password": "13pAssword*"})
50+
response = client.post("/signup", json={"email": "some_text", "password": "13pAssword*"})
5151
assert response.status_code == 422
5252
assert response.json()["code"] == "validation_error"
5353
assert response.json()["message"] == "value is not a valid email address: An email address must have an @-sign."
@@ -56,7 +56,7 @@ def test_signup_wrong_email():
5656
# --- LOGIN ---
5757
def test_login_user_not_exist():
5858
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=None)):
59-
response = client.post("/auth/login", json={"email": "nouser@example.com", "password": "13pAssword*"})
59+
response = client.post("/login", json={"email": "nouser@example.com", "password": "13pAssword*"})
6060
assert response.status_code == 400
6161
assert response.json()["code"] == "user_no_exist"
6262
assert response.json()["message"] == "User with this email does not exist"
@@ -65,7 +65,7 @@ def test_login_user_not_exist():
6565
def test_login_wrong_password():
6666
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=User(email= "test@example.com", password="hashed"))), \
6767
patch("app.controllers.auth_controller.verify_password", new=AsyncMock(return_value=False)):
68-
response = client.post("/auth/login", json={"email": "test@example.com", "password": "15pAssword*"})
68+
response = client.post("/login", json={"email": "test@example.com", "password": "15pAssword*"})
6969
assert response.status_code == 400
7070
assert response.json()["code"] == "Incorrect password"
7171
assert response.json()["message"] == "The password provided is incorrect"
@@ -76,7 +76,7 @@ def test_login_success():
7676
patch("app.controllers.auth_controller.verify_password", new=AsyncMock(return_value=True)), \
7777
patch("app.controllers.auth_controller.create_access_token", new=AsyncMock(return_value="access")), \
7878
patch("app.controllers.auth_controller.create_refresh_token", new=AsyncMock(return_value="refresh")):
79-
response = client.post("/auth/login", json={"email": "test@example.com", "password": "13pAssword*"})
79+
response = client.post("/login", json={"email": "test@example.com", "password": "13pAssword*"})
8080
assert response.status_code == 200
8181
assert response.json()["code"] == "success"
8282
assert response.json()["message"] == "Login successful"
@@ -87,7 +87,7 @@ def test_login_success():
8787
def test_logout_no_refresh_token():
8888
headers = {"Authorization": "Bearer faketoken"}
8989
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}):
90-
response = client.post("/auth/logout", headers=headers)
90+
response = client.post("/logout", headers=headers)
9191
assert response.status_code == 400
9292
assert response.json()["code"] == "missing_refresh_token"
9393
assert response.json()["message"] == "No refresh token provided"
@@ -99,7 +99,7 @@ def test_logout_success():
9999
patch("app.controllers.auth_controller.create_revoked_token", new=AsyncMock()), \
100100
patch("app.controllers.auth_controller.read_expiration_date", new=AsyncMock(return_value=123456)):
101101
cookies = {"refresh_token": "refresh"}
102-
response = client.post("/auth/logout", headers=headers, cookies=cookies)
102+
response = client.post("/logout", headers=headers, cookies=cookies)
103103
assert response.status_code == 200
104104
assert response.json()["code"] == "success"
105105
assert response.json()["message"] == "Logout successful, refresh token revoked"
@@ -108,7 +108,7 @@ def test_logout_success():
108108
# --- ACCOUNT EXISTS ---
109109
def test_account_exists_true():
110110
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value={"email": "test@example.com"})):
111-
response = client.post("/auth/account_exists", json={"email": "test@example.com"})
111+
response = client.post("/account_exists", json={"email": "test@example.com"})
112112
assert response.status_code == 200
113113
assert response.json()["user_exists"] is True
114114
assert response.json()["code"] == "success"
@@ -117,7 +117,7 @@ def test_account_exists_true():
117117

118118
def test_account_exists_false():
119119
with patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=None)):
120-
response = client.post("/auth/account_exists", json={"email": "nouser@example.com"})
120+
response = client.post("/account_exists", json={"email": "nouser@example.com"})
121121
assert response.status_code == 200
122122
assert response.json()["user_exists"] is False
123123
assert response.json()["code"] == "success"
@@ -129,7 +129,7 @@ def test_change_password_user_not_exist():
129129
headers = {"Authorization": "Bearer faketoken"}
130130
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}), \
131131
patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=None)):
132-
response = client.post("/auth/change_password", json={"email": "nouser@example.com", "old_password": "13pAssword*", "new_password": "14pAssword*"}, headers=headers)
132+
response = client.post("/change_password", json={"email": "nouser@example.com", "old_password": "13pAssword*", "new_password": "14pAssword*"}, headers=headers)
133133
assert response.status_code == 400
134134
assert response.json()["code"] == "user_no_exist"
135135
assert response.json()["message"] == "User with email nouser@example.com don't exist"
@@ -140,7 +140,7 @@ def test_change_password_invalid_old_password():
140140
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}), \
141141
patch("app.controllers.auth_controller.read_user_by_email", new=AsyncMock(return_value=User(email="test@example.com", password="hashed"))), \
142142
patch("app.controllers.auth_controller.verify_password", new=AsyncMock(return_value=False)):
143-
response = client.post("/auth/change_password", json={"email": "test@example.com", "old_password": "15pAssword*", "new_password": "14pAssword*"}, headers=headers)
143+
response = client.post("/change_password", json={"email": "test@example.com", "old_password": "15pAssword*", "new_password": "14pAssword*"}, headers=headers)
144144
assert response.status_code == 400
145145
assert response.json()["code"] == "invalid_old_password"
146146
assert response.json()["message"] == "Invalid old password"
@@ -153,7 +153,7 @@ def test_change_password_success():
153153
patch("app.controllers.auth_controller.verify_password", new=AsyncMock(return_value=True)), \
154154
patch("app.controllers.auth_controller.get_hashed_password", new=AsyncMock(return_value="new_hashed")), \
155155
patch("app.controllers.auth_controller.update_user_password", new=AsyncMock()):
156-
response = client.post("/auth/change_password", json={"email": "test@example.com", "old_password": "13pAssword*", "new_password": "14pAssword*"}, headers=headers)
156+
response = client.post("/change_password", json={"email": "test@example.com", "old_password": "13pAssword*", "new_password": "14pAssword*"}, headers=headers)
157157
assert response.status_code == 200
158158
assert response.json()["code"] == "success"
159159
assert response.json()["message"] == "Password changed successfully"
@@ -163,7 +163,7 @@ def test_change_password_success():
163163
def test_check_token_missing():
164164
headers = {"Authorization": "Bearer faketoken"}
165165
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}):
166-
response = client.post("/auth/check_token", json={"token": ""}, headers=headers)
166+
response = client.post("/check_token", json={"token": ""}, headers=headers)
167167
assert response.status_code == 400
168168
assert response.json()["code"] == "token_missing"
169169
assert response.json()["message"] == "No token was provided"
@@ -173,7 +173,7 @@ def test_check_token_valid():
173173
headers = {"Authorization": "Bearer faketoken"}
174174
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}), \
175175
patch("app.controllers.auth_controller.verify_access_token", new=AsyncMock(return_value={"user_id": "abc123"})):
176-
response = client.post("/auth/check_token", json={"token": "sometoken"}, headers=headers)
176+
response = client.post("/check_token", json={"token": "sometoken"}, headers=headers)
177177
assert response.status_code == 200
178178
assert response.json()["valid"] is True
179179
assert response.json()["code"] == "success"
@@ -184,7 +184,7 @@ def test_check_token_expired():
184184
headers = {"Authorization": "Bearer faketoken"}
185185
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}), \
186186
patch("app.controllers.auth_controller.verify_access_token", new=AsyncMock(side_effect=ExpiredSignatureError)):
187-
response = client.post("/auth/check_token", json={"token": "expiredtoken"}, headers=headers)
187+
response = client.post("/check_token", json={"token": "expiredtoken"}, headers=headers)
188188
assert response.status_code == 401
189189
assert response.json()["code"] == "token_expired"
190190
assert response.json()["message"] == "The token has expired"
@@ -194,7 +194,7 @@ def test_check_token_invalid():
194194
headers = {"Authorization": "Bearer faketoken"}
195195
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}), \
196196
patch("app.controllers.auth_controller.verify_access_token", new=AsyncMock(side_effect=InvalidTokenError)):
197-
response = client.post("/auth/check_token", json={"token": "invalidtoken"}, headers=headers)
197+
response = client.post("/check_token", json={"token": "invalidtoken"}, headers=headers)
198198
assert response.status_code == 401
199199
assert response.json()["code"] == "token_invalid"
200200
assert response.json()["message"] == "The token is invalid"
@@ -204,7 +204,7 @@ def test_check_token_invalid():
204204
def test_refresh_token_missing():
205205
headers = {"Authorization": "Bearer faketoken"}
206206
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}):
207-
response = client.post("/auth/refresh_token", headers=headers)
207+
response = client.post("/refresh_token", headers=headers)
208208
assert response.status_code == 400
209209
assert response.json()["code"] == "missing_refresh_token"
210210
assert response.json()["message"] == "No refresh token provided"
@@ -215,7 +215,7 @@ def test_refresh_token_revoked():
215215
with patch("app.utils.jwt_encoder.verify_access_token", return_value={"user_id": "abc123"}), \
216216
patch("app.controllers.auth_controller.is_token_revoked", new=AsyncMock(return_value=True)):
217217
cookies = {"refresh_token": "revokedtoken"}
218-
response = client.post("/auth/refresh_token", cookies=cookies, headers=headers)
218+
response = client.post("/refresh_token", cookies=cookies, headers=headers)
219219
assert response.status_code == 401
220220
assert response.json()["code"] == "token_revoked"
221221
assert response.json()["message"] == "The refresh token has been revoked"
@@ -228,7 +228,7 @@ def test_refresh_token_success():
228228
patch("app.controllers.auth_controller.verify_refresh_token", new=AsyncMock(return_value={"user_id": "1"})), \
229229
patch("app.controllers.auth_controller.create_access_token", new=AsyncMock(return_value="new_access")):
230230
cookies = {"refresh_token": "validtoken"}
231-
response = client.post("/auth/refresh_token", cookies=cookies, headers=headers)
231+
response = client.post("/refresh_token", cookies=cookies, headers=headers)
232232
print(response.json())
233233
assert response.status_code == 200
234234
assert response.json()["code"] == "success"

tests/controllers/test_health_controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
def test_health():
88
response = client.get("/health")
99
assert response.status_code == 200
10-
assert response.json() == {"code": "healthy"}
10+
assert response.json() == {"code": "healthy", "message": "Service is running"}

0 commit comments

Comments
 (0)