Skip to content

Commit

Permalink
more lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Jan 18, 2025
1 parent 6599c96 commit ad23975
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions care/emr/tests/test_schedule_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import UTC, datetime, timedelta

from django.urls import reverse
from rest_framework import status
Expand Down Expand Up @@ -33,8 +33,8 @@ def setUp(self):
self.schedule = Schedule.objects.create(
resource=self.resource,
name="Test Schedule",
valid_from=datetime.now() - timedelta(days=30),
valid_to=datetime.now() + timedelta(days=30),
valid_from=datetime.now(UTC) - timedelta(days=30),
valid_to=datetime.now(UTC) + timedelta(days=30),
)
self.availability = Availability.objects.create(
schedule=self.schedule,
Expand Down Expand Up @@ -77,8 +77,8 @@ def create_schedule(self, **kwargs):
schedule = Schedule.objects.create(
resource=self.resource,
name=kwargs.get("name", "Test Schedule"),
valid_from=kwargs.get("valid_from", datetime.now()),
valid_to=kwargs.get("valid_to", datetime.now() + timedelta(days=30)),
valid_from=kwargs.get("valid_from", datetime.now(UTC)),
valid_to=kwargs.get("valid_to", datetime.now(UTC) + timedelta(days=30)),
)
for availability in kwargs.get("availabilities", []):
schedule.availabilities.create(**availability)
Expand All @@ -88,8 +88,8 @@ def create_slot(self, **kwargs):
data = {
"resource": self.resource,
"availability": self.availability,
"start_datetime": datetime.now() + timedelta(minutes=30),
"end_datetime": datetime.now() + timedelta(minutes=60),
"start_datetime": datetime.now(UTC) + timedelta(minutes=30),
"end_datetime": datetime.now(UTC) + timedelta(minutes=60),
"allocated": 0,
}
data.update(kwargs)
Expand All @@ -111,7 +111,7 @@ def create_booking(self, **kwargs):

def generate_schedule_data(self, **kwargs):
"""Helper to generate valid schedule data."""
valid_from = datetime.now()
valid_from = datetime.now(UTC)
valid_to = valid_from + timedelta(days=30)

return {
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_create_schedule_with_invalid_dates(self):
role = self.create_role_with_permissions(permissions)
self.attach_role_facility_organization_user(self.organization, self.user, role)

valid_from = datetime.now()
valid_from = datetime.now(UTC)
valid_to = valid_from - timedelta(days=1) # Invalid: end before start

schedule_data = self.generate_schedule_data(
Expand Down Expand Up @@ -305,8 +305,8 @@ def test_update_schedule_validity_with_booking_outside_new_validity(self):

self.create_booking(
token_slot=self.create_slot(
start_datetime=datetime.now() + timedelta(days=4),
end_datetime=datetime.now() + timedelta(days=5),
start_datetime=datetime.now(UTC) + timedelta(days=4),
end_datetime=datetime.now(UTC) + timedelta(days=5),
)
)
updated_data = {
Expand All @@ -333,8 +333,8 @@ def test_delete_schedule_with_future_bookings(self):

self.create_booking(
token_slot=self.create_slot(
start_datetime=datetime.now() + timedelta(days=4),
end_datetime=datetime.now() + timedelta(days=5),
start_datetime=datetime.now(UTC) + timedelta(days=4),
end_datetime=datetime.now(UTC) + timedelta(days=5),
)
)
delete_url = self._get_schedule_url(self.schedule.external_id)
Expand All @@ -356,8 +356,8 @@ def test_delete_schedule_with_future_cancelled_bookings(self):

self.create_booking(
token_slot=self.create_slot(
start_datetime=datetime.now() + timedelta(days=4),
end_datetime=datetime.now() + timedelta(days=5),
start_datetime=datetime.now(UTC) + timedelta(days=4),
end_datetime=datetime.now(UTC) + timedelta(days=5),
),
status=BookingStatusChoices.cancelled.value,
)
Expand Down Expand Up @@ -396,8 +396,8 @@ def _get_exception_url(self, exception_id):
def create_exception(self, **kwargs):
from care.emr.models import AvailabilityException

valid_from = datetime.now().date()
valid_to = (datetime.now() + timedelta(days=1)).date()
valid_from = datetime.now(UTC).date()
valid_to = (datetime.now(UTC) + timedelta(days=1)).date()
return AvailabilityException.objects.create(
resource=self.resource,
valid_from=valid_from,
Expand All @@ -409,8 +409,8 @@ def create_exception(self, **kwargs):

def generate_exception_data(self, **kwargs):
"""Helper to generate valid availability exception data."""
valid_from = datetime.now().date()
valid_to = (datetime.now() + timedelta(days=1)).date()
valid_from = datetime.now(UTC).date()
valid_to = (datetime.now(UTC) + timedelta(days=1)).date()

return {
"user": str(self.user.external_id),
Expand Down Expand Up @@ -553,8 +553,8 @@ def test_create_exception_with_bookings(self):
schedule = Schedule.objects.create(
resource=self.resource,
name="Test Schedule",
valid_from=datetime.now() - timedelta(days=30),
valid_to=datetime.now() + timedelta(days=30),
valid_from=datetime.now(UTC) - timedelta(days=30),
valid_to=datetime.now(UTC) + timedelta(days=30),
)

# Create an availability
Expand All @@ -568,15 +568,17 @@ def test_create_exception_with_bookings(self):
reason="Regular schedule",
availability=[
{
"day_of_week": datetime.now().weekday(),
"day_of_week": datetime.now(UTC).weekday(),
"start_time": "09:00:00",
"end_time": "17:00:00",
}
],
)

# Create a slot for today
slot_start = datetime.now().replace(hour=10, minute=0, second=0, microsecond=0)
slot_start = datetime.now(UTC).replace(
hour=10, minute=0, second=0, microsecond=0
)
slot = TokenSlot.objects.create(
resource=self.resource,
availability=availability,
Expand Down Expand Up @@ -652,8 +654,8 @@ def create_schedule(self, **kwargs):
schedule = Schedule.objects.create(
resource=self.resource,
name=kwargs.get("name", "Test Schedule"),
valid_from=kwargs.get("valid_from", datetime.now()),
valid_to=kwargs.get("valid_to", datetime.now() + timedelta(days=30)),
valid_from=kwargs.get("valid_from", datetime.now(UTC)),
valid_to=kwargs.get("valid_to", datetime.now(UTC) + timedelta(days=30)),
)
for availability in kwargs.get("availabilities", []):
schedule.availabilities.create(**availability)
Expand Down Expand Up @@ -763,8 +765,8 @@ def test_delete_availability_with_future_bookings(self):
token_slot = TokenSlot.objects.create(
resource=self.resource,
availability=availability,
start_datetime=datetime.now() + timedelta(days=4),
end_datetime=datetime.now() + timedelta(days=5),
start_datetime=datetime.now(UTC) + timedelta(days=4),
end_datetime=datetime.now(UTC) + timedelta(days=5),
)
TokenBooking.objects.create(
token_slot=token_slot,
Expand Down

0 comments on commit ad23975

Please sign in to comment.