Skip to content

Commit 609d6bb

Browse files
authored
Refactor cycle update and delete tests
### Description This pull request resolves [Issue #170](#170) by consolidating the fragmented and duplicated `TestUpdateCycle` and `TestDeleteCycle` classes in `backend/tests/test_cycles.py`. #### Details: * **Class Consolidation:** Merged all test methods for updating and deleting cycles into single, unified `TestUpdateCycle` and `TestDeleteCycle` classes respectively. * **Removal of Duplicates:** Eliminated duplicate `not_found` test definitions that resulted from the fragmented class structure. * **Pipeline Integrity:** Ensures success tests (`test_update_cycle_success` and `test_delete_cycle_success`) are no longer shadowed and are fully executed during test runs. Closes #170
1 parent 7589820 commit 609d6bb

1 file changed

Lines changed: 15 additions & 33 deletions

File tree

backend/tests/test_cycles.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,17 @@ def test_update_cycle_success(self, client, auth_headers):
151151

152152
def test_update_cycle_not_found(self, client, auth_headers):
153153
"""Non-existent cycle returns 404."""
154-
resp = client.put("/cycles/bad_id", headers=auth_headers, json={"startDate": "2026-06-01", "endDate": "2026-06-05"})
154+
resp = client.put("/cycles/nonexistent_id", headers=auth_headers, json={"startDate": "2026-07-01"})
155155
assert resp.status_code == 404
156156

157+
def test_update_cycle_invalid_dates(self, client, auth_headers):
158+
"""Updating with invalid date range returns 400."""
159+
resp = client.put("/cycles/some_id", headers=auth_headers, json={
160+
"startDate": "2026-07-10",
161+
"endDate": "2026-07-05",
162+
})
163+
assert resp.status_code == 400 or resp.status_code == 404
164+
157165

158166
class TestDeleteCycle:
159167
"""DELETE /cycles/<id> endpoint tests."""
@@ -171,9 +179,14 @@ def test_delete_cycle_success(self, client, auth_headers):
171179

172180
def test_delete_cycle_not_found(self, client, auth_headers):
173181
"""Non-existent cycle returns 404."""
174-
resp = client.delete("/cycles/bad_id", headers=auth_headers)
182+
resp = client.delete("/cycles/nonexistent_id", headers=auth_headers)
175183
assert resp.status_code == 404
176184

185+
def test_delete_cycle_no_auth(self, client):
186+
"""Deleting without auth returns 401."""
187+
resp = client.delete("/cycles/some_id")
188+
assert resp.status_code == 401
189+
177190

178191
class TestCyclePrediction:
179192
"""GET /cycle-prediction endpoint tests."""
@@ -185,34 +198,3 @@ def test_cycle_prediction_success(self, client, auth_headers):
185198
assert resp.status_code == 200
186199
data = resp.get_json()
187200
assert isinstance(data, dict)
188-
189-
190-
class TestUpdateCycle:
191-
"""PUT /cycles/<id> endpoint tests."""
192-
193-
def test_update_cycle_not_found(self, client, auth_headers):
194-
"""Updating a non-existent cycle returns 404."""
195-
resp = client.put("/cycles/nonexistent_id", headers=auth_headers, json={"startDate": "2026-07-01"})
196-
assert resp.status_code == 404
197-
198-
def test_update_cycle_invalid_dates(self, client, auth_headers):
199-
"""Updating with invalid date range returns 400."""
200-
resp = client.put("/cycles/some_id", headers=auth_headers, json={
201-
"startDate": "2026-07-10",
202-
"endDate": "2026-07-05",
203-
})
204-
assert resp.status_code == 400 or resp.status_code == 404
205-
206-
207-
class TestDeleteCycle:
208-
"""DELETE /cycles/<id> endpoint tests."""
209-
210-
def test_delete_cycle_not_found(self, client, auth_headers):
211-
"""Deleting a non-existent cycle returns 404."""
212-
resp = client.delete("/cycles/nonexistent_id", headers=auth_headers)
213-
assert resp.status_code == 404
214-
215-
def test_delete_cycle_no_auth(self, client):
216-
"""Deleting without auth returns 401."""
217-
resp = client.delete("/cycles/some_id")
218-
assert resp.status_code == 401

0 commit comments

Comments
 (0)