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 tests depending on year 2024 #473

Merged
merged 4 commits into from
Jan 28, 2024
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
2 changes: 1 addition & 1 deletion tapir/coop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def with_name(self, search_string: str):

def with_status(self, status: str, date=None):
if date is None:
date = datetime.date.today()
date = timezone.now()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as in DurationModelMixinQuerySet

active_ownerships = ShareOwnership.objects.active_temporal(date)

if status == MemberStatus.SOLD:
Expand Down
2 changes: 1 addition & 1 deletion tapir/shifts/tests/test_slot_template_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_editing_a_slot_template_does_not_affect_past_slots(self):
self.assertEqual("Name before", slot.name)

response = self.client.post(
reverse(self.SLOT_TEMPLATE_EDIT_VIEW, args=[shift_template.id]),
reverse(self.SLOT_TEMPLATE_EDIT_VIEW, args=[slot_template.id]),
{
"name": "Name after",
"check_update_future_shifts": True,
Expand Down
3 changes: 1 addition & 2 deletions tapir/utils/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from collections import namedtuple
from datetime import date

from django.core.exceptions import ValidationError
from django.db import models
Expand Down Expand Up @@ -299,7 +298,7 @@ def overlapping_with(self, obj) -> DurationModelMixinQuerySet:
def active_temporal(self, effective_date=None) -> DurationModelMixinQuerySet:
if not effective_date:
# if no effective date was given, use today as the default
effective_date = date.today()
effective_date = timezone.now()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this maybe be timezone.now().date()? The DurationModelMixin uses date fields, not datetime fields.
Though I'm not sure if dates can be timezone-aware

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the date class doesn't have a timezone. But do you see any problem with that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datetime.date.today() returns the local time, not UTC. I haven't thought it through, but it sounds like people could have an offset of 1 or 2 hours?!

Anyway, maybe it's parsed automatically or we ensure timezone-aware dates by timezone.now().date() (which is using UTC and not local time)

return self.overlapping_with(
# It's impossible to instantiate an abstract model, therefore create a namedtuple here
namedtuple("FakeDurationModelMixin", ["start_date", "end_date"])(
Expand Down
1 change: 0 additions & 1 deletion tapir/welcomedesk/tests/test_welcome_desk_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from tapir.coop.tests.factories import ShareOwnerFactory, MembershipPauseFactory
from tapir.shifts.models import (
ShiftAttendanceMode,
ShiftAccountEntry,
ShiftAttendanceTemplate,
ShiftExemption,
)
Expand Down
Loading