-
Notifications
You must be signed in to change notification settings - Fork 592
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(#1701): Events page displays year for events scheduled to start or end at a future year #2500
base: main
Are you sure you want to change the base?
Changes from all commits
1502c10
4198812
ff1ad8b
e3125d9
178742b
e0fdf7c
115af08
aa4d55b
207a0af
c7cfabd
fa6e0ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,6 @@ def test_recurring_event(self): | |
self.assertEqual(self.event.next_time.dt_start, recurring_time_dtstart) | ||
self.assertTrue(rt.valid_dt_end()) | ||
|
||
|
||
rt.begin = now - datetime.timedelta(days=5) | ||
rt.finish = now - datetime.timedelta(days=3) | ||
rt.save() | ||
|
@@ -186,3 +185,25 @@ def test_event_previous_event(self): | |
# 'Event.previous_event' can return None if there is no | ||
# OccurringRule or RecurringRule found. | ||
self.assertIsNone(self.event.previous_event) | ||
|
||
def test_scheduled_to_start_this_year_method(self): | ||
now = seconds_resolution(timezone.now()) | ||
|
||
occurring_time_dtstart = now + datetime.timedelta(days=3) | ||
OccurringRule.objects.create( | ||
event=self.event, | ||
dt_start=occurring_time_dtstart, | ||
dt_end=occurring_time_dtstart | ||
) | ||
self.assertTrue(self.event.is_scheduled_to_start_this_year()) | ||
|
||
def test_scheduled_to_end_this_year_method(self): | ||
now = seconds_resolution(timezone.now()) | ||
|
||
occurring_time_dtstart = now + datetime.timedelta(days=3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment here concerning
with previous comment at https://github.com/python/pythondotorg/pull/2500/files#r1764230987 If it's fine with everyone, I'll await feedback first before making any more changes to the pull request so I'd attempt resolving all concerns with as minimal back-and-forth as possible. Thank you for your time and best regards everyone. |
||
OccurringRule.objects.create( | ||
event=self.event, | ||
dt_start=occurring_time_dtstart, | ||
dt_end=occurring_time_dtstart | ||
) | ||
self.assertTrue(self.event.is_scheduled_to_end_this_year()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
{% if next_time.single_day %} | ||
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}<span class="say-no-more"> {{ next_time.dt_start|date:"Y" }}</span>{% if not next_time.all_day %} {{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }}{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }} {{ next_time.dt_end|date:"e" }}{% endif %}{% endif %}</time> | ||
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }} | ||
<span id="start-{{ object.id }}"{% if scheduled_start_this_year %} class="say-no-more"{% endif %}> | ||
{{ next_time.dt_start|date:"Y" }} | ||
</span> | ||
|
||
<span id="start-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}> | ||
{{ next_time.dt_start|date:"Y" }} | ||
</span> | ||
|
||
{% if not next_time.all_day %} | ||
{{ next_time.dt_start|date:"fA"|lower }} {{ next_time.dt_start|date:"e" }} | ||
{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"fA"|lower }} | ||
{{ next_time.dt_end|date:"e" }} | ||
{% endif %} | ||
{% endif %} | ||
</time> | ||
{% else %} | ||
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }}{% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"d N" }}{% endif %} <span class="say-no-more"> {{ next_time.dt_end|date:"Y" }}</span></time> | ||
<time datetime="{{ next_time.dt_start|date:'c' }}">{{ next_time.dt_start|date:"d N" }} | ||
<span id="start-{{ object.id }}"{% if scheduled_start_this_year %} class="say-no-more"{% endif %}> | ||
{{ next_time.dt_start|date:"Y" }} | ||
</span> | ||
|
||
{% if next_time.valid_dt_end %} – | ||
{{ next_time.dt_end|date:"d N" }} | ||
{% endif %} | ||
|
||
<span id="end-{{ object.id }}"{% if scheduled_end_this_year %} class="say-no-more"{% endif %}> | ||
{{ next_time.dt_end|date:"Y" }} | ||
</span> | ||
</time> | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmmm... Thinking about this test again. On the off chance that tests are run between the 29th of December and the 31st of December, this test will fail since the next year will be set to 3 days ahead...
So if tests are run on the 29th of December,
occurring_time_dtstart
will be set to 3 days from then which would be the 1st of January (the following year).Since the date comparison is made against
datetime.datetime.now().year
atEvent.is_scheduled_to_start_this_year
andEvent.is_scheduled_to_end_this_year
, (https://github.com/alvindera97/pythondotorg/blob/fa6e0ced4827a1652aa2eef0a80db22b1a2c4fe2/events/models.py#L184-L189) having a timedelta of 3 days makes running tests within the last 3 days of the year flaky.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use something like https://github.com/spulec/freezegun to freeze time so the tests run reliably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @hugovk, for suggesting freezegun to handle the time-dependent tests. I have tested the updates locally, and I’m ready to push the changes to the current pull request. However, before proceeding, I wanted to get clarity on one remaining concern regarding the introduction of external dependencies into the project.
Specifically, I’m unsure of the current team policy regarding the addition of new dependencies. My concern revolves around potential risks that come with relying on third-party libraries, such as maintenance issues, security vulnerabilities, and compatibility with future versions of Python/Django.
In this case, while freezegun is a robust library for freezing time, I wonder if it’s necessary to introduce an entire dependency solely to address the time-delta requirements of the Event object in the tests. I'm considering whether there might be an alternative approach that avoids the need for an external library, such as directly mocking time or using built-in Python features to clamp dates.
I would appreciate your thoughts on whether the use of freezegun is acceptable for this situation, or if the team would prefer exploring another solution.
However, as an example, I thought of reducing the time-deltas. Here's a snippet without freezegun:
Looking forward to your feedback 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your question, it's always good to keep these things in mind. My feeling is that it would be okay, as there are already a number of third-party dependencies, but I'll leave it to the maintainers to answer more concretely.
An alternative would be to use something like
unitest.mock
to fake the date returned bydatetime.timedelta
.