From 00dc6fbb03987e3178fdba2e69929944d7d866ac Mon Sep 17 00:00:00 2001 From: Nwokolo Godwin Chidera Date: Wed, 2 Oct 2024 02:06:41 +0100 Subject: [PATCH 1/3] Add Test For Single Day Event Year String Render Add test that checks single day event renders year string exactly once since event is guaranteed to commence and conclude within the same day and hence the same year. --- events/tests/test_views.py | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/events/tests/test_views.py b/events/tests/test_views.py index 34ca27831..985af69dc 100644 --- a/events/tests/test_views.py +++ b/events/tests/test_views.py @@ -253,6 +253,87 @@ def test_events_scheduled_current_year_does_not_display_current_year(self): response.content.decode() ) + def test_single_day_event_only_renders_event_date_year_string_if_relevant(self): + url = reverse('events:events') + single_day_event_starting_and_ending_in_current_year = Event.objects.create( + title='Single Day Event Starting & Ending In Current Year', creator=self.user, calendar=self.calendar) + single_day_all_day_event_starting_and_ending_in_current_year = Event.objects.create( + title='Single Day All Day Event Starting & Ending In Current Year', + creator=self.user, + calendar=self.calendar) + single_day_event_starting_and_ending_in_future_year = Event.objects.create( + title='Single Day Event Staring And Ending In Future Year', creator=self.user, + calendar=self.calendar) + single_day_all_day_event_starting_and_ending_in_future_year = Event.objects.create( + title='Single Day All Day Event Starting And Ending In Future Year', + creator=self.user, + calendar=self.calendar) + + occurring_time_dtstart = self.now + datetime.timedelta(minutes=2) + + OccurringRule.objects.create( + event=single_day_event_starting_and_ending_in_current_year, + dt_start=occurring_time_dtstart, + dt_end=occurring_time_dtstart + datetime.timedelta(minutes=5) + ) + OccurringRule.objects.create( + all_day=True, + event=single_day_all_day_event_starting_and_ending_in_current_year, + dt_start=occurring_time_dtstart, + dt_end=occurring_time_dtstart + datetime.timedelta(minutes=5) + ) + OccurringRule.objects.create( + event=single_day_event_starting_and_ending_in_future_year, + dt_start=occurring_time_dtstart + datetime.timedelta(days=366), + dt_end=occurring_time_dtstart + datetime.timedelta(minutes=10) + ) + OccurringRule.objects.create( + all_day=True, + event=single_day_all_day_event_starting_and_ending_in_future_year, + dt_start=occurring_time_dtstart + datetime.timedelta(days=366), + dt_end=occurring_time_dtstart + datetime.timedelta(minutes=10) + ) + + response = self.client.get(url) + + # Single Day Event Starting & Ending In Current Year + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + + # Single Day All Day Event Starting & Ending In Current Year + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + + # Single Day Event Staring And Ending In Future Year + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + + # Single Day All Day Event Starting And Ending In Future Year + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + class EventSubmitTests(TestCase): event_submit_url = reverse_lazy('events:event_submit') From 7769a36c6b0ced391651de87d9cacbdef9a647c0 Mon Sep 17 00:00:00 2001 From: Nwokolo Godwin Chidera Date: Wed, 2 Oct 2024 02:08:09 +0100 Subject: [PATCH 2/3] Add Test For Multi Day Event Year String Render Add test that checks for proper year string rendering on multi-day events. --- events/tests/test_views.py | 113 +++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/events/tests/test_views.py b/events/tests/test_views.py index 985af69dc..9882a7b29 100644 --- a/events/tests/test_views.py +++ b/events/tests/test_views.py @@ -334,6 +334,119 @@ def test_single_day_event_only_renders_event_date_year_string_if_relevant(self): f'', response.content.decode()) + def test_multi_day_event_only_render_end_year_information_when_dt_end_is_valid(self): + url = reverse('events:events') + multi_day_event_starting_and_ending_in_current_year = Event.objects.create( + title='Multi-Day Event Starting & Ending In Current Year', creator=self.user, calendar=self.calendar) + multi_day_all_day_event_starting_and_ending_in_current_year = Event.objects.create( + title='Multi-Day All Day Event Starting & Ending In Current Year', + creator=self.user, + calendar=self.calendar) + multi_day_event_starting_in_current_year_and_ending_in_future_year = Event.objects.create( + title='Multi-Day Event Staring In Current Year And Ending In Future Year', creator=self.user, + calendar=self.calendar) + multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year = Event.objects.create( + title='Multi-Day All Day Event Starting In Current Year And Ending In Future Year', + creator=self.user, + calendar=self.calendar) + multi_day_event_starting_and_ending_in_future_year = Event.objects.create( + title='Multi-Day Event Staring And Ending In Future Year', creator=self.user, + calendar=self.calendar) + multi_day_all_day_event_starting_and_ending_in_future_year = Event.objects.create( + title='Multi-Day All Day Event Starting And Ending In Future Year', + creator=self.user, + calendar=self.calendar) + + occurring_time_dtstart = self.now + datetime.timedelta(minutes=2) + + OccurringRule.objects.create( + event=multi_day_event_starting_and_ending_in_current_year, + dt_start=occurring_time_dtstart, + dt_end=occurring_time_dtstart + datetime.timedelta(days=1) + ) + OccurringRule.objects.create( + all_day=True, + event=multi_day_all_day_event_starting_and_ending_in_current_year, + dt_start=occurring_time_dtstart, + dt_end=occurring_time_dtstart + datetime.timedelta(days=1) + ) + OccurringRule.objects.create( + event=multi_day_event_starting_in_current_year_and_ending_in_future_year, + dt_start=occurring_time_dtstart, + dt_end=occurring_time_dtstart + datetime.timedelta(days=366) + ) + OccurringRule.objects.create( + all_day=True, + event=multi_day_all_day_event_starting_in_current_year_and_ending_in_future_year, + dt_start=occurring_time_dtstart, + dt_end=occurring_time_dtstart + datetime.timedelta(days=366) + ) + OccurringRule.objects.create( + event=multi_day_event_starting_and_ending_in_future_year, + dt_start=occurring_time_dtstart + datetime.timedelta(days=366), + dt_end=occurring_time_dtstart + datetime.timedelta(days=367) + ) + OccurringRule.objects.create( + all_day=True, + event=multi_day_all_day_event_starting_and_ending_in_future_year, + dt_start=occurring_time_dtstart + datetime.timedelta(days=366), + dt_end=occurring_time_dtstart + datetime.timedelta(days=367) + ) + response = self.client.get(url) + + # Multi-Day All Day Event Starting & Ending In Current Year + self.assertIn( + f'', + response.content.decode()) + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + + # Multi-Day Event Staring In Current Year And Ending In Future Year + self.assertIn( + f'', + response.content.decode()) + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + + # Multi-Day All Day Event Starting In Current Year And Ending In Future Year + self.assertIn( + f'', + response.content.decode()) + self.assertIn( + f'', + response.content.decode()) + self.assertNotIn( + f'', + response.content.decode()) + + # Multi-Day Event Staring And Ending In Future Year + self.assertIn( + f'', + response.content.decode()) + self.assertIn( + f'', + response.content.decode()) + + # Multi-Day All Day Event Starting And Ending In Future Year + self.assertIn( + f'', + response.content.decode()) + self.assertIn( + f'', + response.content.decode()) + + class EventSubmitTests(TestCase): event_submit_url = reverse_lazy('events:event_submit') From 86cb81f6b4a9c0e1d78ee1391b19cd32f70d7bcb Mon Sep 17 00:00:00 2001 From: Nwokolo Godwin Chidera Date: Wed, 2 Oct 2024 02:10:12 +0100 Subject: [PATCH 3/3] Fix Duplicate Year String At Render Template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix incorrect rendering logic at template ensuring: • Single day events only render one year string. • Multi-day events only render end-date-year string only if it's valid. --- templates/events/includes/time_tag.html | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/templates/events/includes/time_tag.html b/templates/events/includes/time_tag.html index 90bc4491b..316aaba36 100644 --- a/templates/events/includes/time_tag.html +++ b/templates/events/includes/time_tag.html @@ -4,10 +4,6 @@ {{ next_time.dt_start|date:"Y" }} - - {{ next_time.dt_start|date:"Y" }} - - {% 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 }} @@ -23,10 +19,10 @@ {% if next_time.valid_dt_end %} – {{ next_time.dt_end|date:"d N" }} + + {{ next_time.dt_end|date:"Y" }} + {% endif %} - - {{ next_time.dt_end|date:"Y" }} - {% endif %} \ No newline at end of file