Skip to content

Commit

Permalink
Merge pull request #6186 from hotosm/fix/testcase-for-task-statistics
Browse files Browse the repository at this point in the history
fix: unit test fail for backend tasks/statistics
  • Loading branch information
kshitijrajsharma authored Jan 8, 2024
2 parents b3bedc5 + e551652 commit ae66919
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tests/backend/integration/api/tasks/test_statistics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta

from backend.models.postgis.task import Task, TaskStatus
from backend.services.campaign_service import CampaignService, CampaignProjectDTO
Expand Down Expand Up @@ -105,7 +105,11 @@ def test_returns_200_if_valid_date_range(self):
response = self.client.get(
self.url,
headers={"Authorization": self.user_session_token},
query_string={"startDate": "2023-01-01"},
query_string={
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
)
},
)
# Assert
self.assertEqual(response.status_code, 200)
Expand All @@ -130,7 +134,9 @@ def test_filters_task_by_project(self):
self.url,
headers={"Authorization": self.user_session_token},
query_string={
"startDate": "2023-01-01",
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
),
"projectId": self.test_project_1.id,
},
)
Expand All @@ -152,7 +158,9 @@ def test_filters_by_multiple_projects(self):
self.url,
headers={"Authorization": self.user_session_token},
query_string={
"startDate": "2023-01-01",
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
),
"projectId": f"{self.test_project_1.id}, {self.test_project_2.id}",
},
)
Expand All @@ -173,7 +181,9 @@ def test_filters_by_organisation_id(self):
self.url,
headers={"Authorization": self.user_session_token},
query_string={
"startDate": "2023-01-01",
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
),
"organisationId": test_organisation.id,
},
)
Expand All @@ -194,7 +204,9 @@ def test_filters_by_organisation_name(self):
self.url,
headers={"Authorization": self.user_session_token},
query_string={
"startDate": "2023-01-01",
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
),
"organisationName": test_organisation.name,
},
)
Expand All @@ -217,7 +229,9 @@ def test_filters_by_campaign(self):
self.url,
headers={"Authorization": self.user_session_token},
query_string={
"startDate": "2023-01-01",
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
),
"campaign": test_campaign.name,
},
)
Expand All @@ -239,7 +253,9 @@ def test_filters_by_country(self):
self.url,
headers={"Authorization": self.user_session_token},
query_string={
"startDate": "2023-01-01",
"startDate": (datetime.now() - timedelta(days=6 * 30)).strftime(
"%Y-%m-%d"
),
"country": "Nepal",
},
)
Expand Down

0 comments on commit ae66919

Please sign in to comment.