Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test cases that, while checking the 404 status code, make requests to non-existent urls rather than non-existent resources. #5938

Merged
merged 3 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/backend/integration/api/organisations/test_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def test_get_organisation_campaigns_passes(self):
response_body, {"campaigns": [{"id": 1, "name": "Test Campaign"}]}
)

def test_get_non_existent_organisation_campaigns_fails(self):
"""
Test that the endpoint returns 404 when retrieving campaigns for non existent organisation
"""
response = self.client.get(f"{self.endpoint_url}98/campaigns/")
self.assertEqual(response.status_code, 404)
# def test_get_non_existent_organisation_campaigns_fails(self):
# """
# Test that the endpoint returns 404 when retrieving campaigns for non existent organisation
# """
# response = self.client.get(f"/api/v2/organisations/111111/campaigns/")
# self.assertEqual(response.status_code, 404)

# delete
def test_delete_organisation_campaign_by_admin_passes(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/integration/api/projects/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_returns_404_if_project_does_not_exist(self):
"""Test that the endpoint returns 404 if the project does not exist"""
# Act
response = self.client.post(
"/api/v2/projects/999/transfer",
"/api/v2/projects/1111111/actions/transfer-ownership/",
headers={"Authorization": self.test_user_access_token},
json={"username": "test_user"},
)
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/integration/api/projects/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ def test_returns_404_if_user_doesnt_exist(self):
Test 404 is returned if project doesn't exist
"""
# Act
response = self.client.get("/api/v2/projects/test_user_123/queries/touched/")
response = self.client.get("/api/v2/projects/queries/non_existent/touched/")
self.assertEqual(response.status_code, 404)


Expand Down
24 changes: 17 additions & 7 deletions tests/backend/integration/api/tasks/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
def test_returns_404_if_project_does_not_exist(self):
"""Test that a 404 is returned if the project does not exist."""
# Act
response = self.client.get("/api/projects/999/tasks")
response = self.client.get("/api/v2/projects/11111/tasks/")
# Assert
self.assertEqual(response.status_code, 404)

Expand Down Expand Up @@ -95,8 +95,16 @@ def test_returns_403_if_user_not_admin(self):

def test_returns_404_if_project_does_not_exist(self):
"""Test that a 404 is returned if the project does not exist."""
# Arrange
self.test_user.role = UserRole.ADMIN.value # Since only admins can delete tasks
self.test_user.save()
body = {"tasks": [1, 2]}
# Act
response = self.client.delete("/api/projects/999/tasks")
response = self.client.delete(
"/api/v2/projects/11111/tasks/",
headers={"Authorization": self.test_user_access_token},
json=body,
)
# Assert
self.assertEqual(response.status_code, 404)

Expand Down Expand Up @@ -168,14 +176,16 @@ def setUp(self):
def test_returrns_404_if_project_does_not_exist(self):
"""Test that a 404 is returned if the project does not exist."""
# Act
response = self.client.get("/api/projects/999/tasks/1")
response = self.client.get("/api/v2/projects/11111/tasks/1/")
# Assert
self.assertEqual(response.status_code, 404)

def test_returns_404_if_task_does_not_exist(self):
"""Test that a 404 is returned if the task does not exist."""
# Act
response = self.client.get(f"/api/projects/{self.test_project.id}/tasks/999")
response = self.client.get(
f"/api/v2/projects/{self.test_project.id}/tasks/999/"
)
# Assert
self.assertEqual(response.status_code, 404)

Expand Down Expand Up @@ -226,7 +236,7 @@ def setUp(self):
def test_returns_404_if_project_does_not_exist(self):
"""Test that a 404 is returned if the project does not exist."""
# Act
response = self.client.get("/api/projects/999/tasks/queries/gpx")
response = self.client.get("/api/v2/projects/11111/tasks/queries/gpx/")
# Assert
self.assertEqual(response.status_code, 404)

Expand Down Expand Up @@ -293,7 +303,7 @@ def setUp(self):
def test_returns_404_if_project_does_not_exist(self):
"""Test that a 404 is returned if the project does not exist."""
# Act
response = self.client.get("/api/projects/999/tasks/queries/xml")
response = self.client.get("/api/v2/projects/11111/tasks/queries/xml/")
# Assert
self.assertEqual(response.status_code, 404)

Expand Down Expand Up @@ -382,7 +392,7 @@ def test_returns_404_if_user_does_not_exist(self):
"""Test that a 404 is returned if the user does not exist."""
# Act
response = self.client.get(
"/api/projects/hello/tasks/queries/own/invalidated/",
"/api/v2/projects/non_existent/tasks/queries/own/invalidated/",
headers={"Authorization": self.test_user_access_token},
)
# Assert
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/integration/api/users/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def test_returns_404_if_user_does_not_exist(self):
"""Test that the API returns 404 if user does not exist"""
# Act
response = self.client.get(
"/api/v2/users/999/recommendedProjects/",
"api/v2/users/non_existent/recommended-projects/",
headers={"Authorization": self.user_session_token},
)
# Assert
Expand Down