Skip to content

Commit

Permalink
Update based on failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meomancer committed Sep 10, 2024
1 parent 5d295ca commit 218b575
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion django_project/gap/admin/crop_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class CropInsightRequestAdmin(admin.ModelAdmin):
"""Admin for CropInsightRequest."""

list_display = (
'requested_date', 'farm_count', 'file_url', 'last_task_status',
'requested_at', 'farm_count', 'file_url', 'last_task_status',
'background_tasks'
)
filter_horizontal = ('farms',)
Expand Down
13 changes: 8 additions & 5 deletions django_project/gap/models/crop_insight.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import json
import uuid
from datetime import date
from datetime import date, timedelta

from django.conf import settings
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -438,7 +438,10 @@ def background_task_running(self):
def today_reports():
"""Return query of today reports."""
now = timezone.now()
return CropInsightRequest.objects.filter(requested_date=now.date())
return CropInsightRequest.objects.filter(
requested_at__gte=now.date(),
requested_at__lte=now.date() + timedelta(days=1),
)

@property
def skip_run(self):
Expand Down Expand Up @@ -471,10 +474,10 @@ def skip_run(self):

now = timezone.now()
try:
if self.requested_date.date() != now.date():
if self.requested_at.date() != now.date():
return True
except AttributeError:
if self.requested_date != now.date():
if self.requested_at != now.date():
return True

Check warning on line 481 in django_project/gap/models/crop_insight.py

View check run for this annotation

Codecov / codecov/patch

django_project/gap/models/crop_insight.py#L478-L481

Added lines #L478 - L481 were not covered by tests
return False

Expand Down Expand Up @@ -503,7 +506,7 @@ def title(self) -> str:
f"({east_africa_timezone})"
)

def generate_report(self):
def _generate_report(self):
"""Generate reports."""
from spw.generator.crop_insight import CropInsightFarmGenerator
output = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class CropInsideTaskRUDTest(TestCase):
def test_today_reports(self):
"""Test query today reports."""
now = timezone.now()
self.Factory(requested_date=now)
self.Factory(requested_date=now)
self.Factory(requested_date=now + datetime.timedelta(days=-1))
self.Factory(requested_at=now)
self.Factory(requested_at=now)
self.Factory(requested_at=now + datetime.timedelta(days=-1))
self.assertEqual(CropInsightRequest.today_reports().count(), 2)

@patch('gap.models.crop_insight.CropInsightRequest._generate_report')
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_retry(self, mock_generate_report):

# Report 8 is the older one
report_8 = self.Factory(
requested_date=now + datetime.timedelta(days=-1)
requested_at=now + datetime.timedelta(days=-1)
)

# Below is older tasks
Expand Down

0 comments on commit 218b575

Please sign in to comment.