From 49a27440b5a3cafd6f34cd4796c39d0be9c807e1 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 13 Sep 2024 11:17:44 -0300 Subject: [PATCH 1/3] refactor: session recording URL label helper --- ietf/meeting/models.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ietf/meeting/models.py b/ietf/meeting/models.py index 01b695bcea..e169077800 100644 --- a/ietf/meeting/models.py +++ b/ietf/meeting/models.py @@ -1331,16 +1331,18 @@ def onsite_tool_url(self): return url.format(session=self) return None + def _session_recording_url_label(self): + if self.meeting.type.slug == "ietf" and self.has_onsite_tool: + session_label = f"IETF{self.meeting.number}-{self.group.acronym.upper()}-{self.official_timeslotassignment().timeslot.time.strftime('%Y%m%d-%H%M')}" + else: + session_label = f"IETF-{self.group.acronym.upper()}-{self.official_timeslotassignment().timeslot.time.strftime('%Y%m%d-%H%M')}" + return session_label + def session_recording_url(self): url_formatter = getattr(settings, "MEETECHO_SESSION_RECORDING_URL", "") url = None if url_formatter and self.video_stream_url: - if self.meeting.type.slug == "ietf" and self.has_onsite_tool: - session_label = f"IETF{self.meeting.number}-{self.group.acronym.upper()}-{self.official_timeslotassignment().timeslot.time.strftime('%Y%m%d-%H%M')}" - else: - session_label = f"IETF-{self.group.acronym.upper()}-{self.official_timeslotassignment().timeslot.time.strftime('%Y%m%d-%H%M')}" - url = url_formatter.format(session_label=session_label) - + url = url_formatter.format(session_label=self._session_recording_url_label()) return url From 69b3eb4b98e2d6948f70fc7043373e1b92e95fd2 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 13 Sep 2024 11:19:48 -0300 Subject: [PATCH 2/3] test: update tests, avoid tz dependence --- ietf/meeting/tests_models.py | 67 +++++++++++++++++------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/ietf/meeting/tests_models.py b/ietf/meeting/tests_models.py index 0a089ee9e8..17b2a3600c 100644 --- a/ietf/meeting/tests_models.py +++ b/ietf/meeting/tests_models.py @@ -8,6 +8,7 @@ from django.conf import settings from django.test import override_settings +import ietf.meeting.models from ietf.group.factories import GroupFactory, GroupHistoryFactory from ietf.meeting.factories import MeetingFactory, SessionFactory, AttendedFactory, SessionPresentationFactory from ietf.meeting.models import Session @@ -156,46 +157,40 @@ def test_alpha_str(self): self.assertEqual(Session._alpha_str(27 * 26 - 1), "zz") self.assertEqual(Session._alpha_str(27 * 26), "aaa") - def test_session_recording_url(self): - group_acronym = "foobar" - meeting_date = datetime.date.today() - meeting_number = 123 - - # IETF meeting + @patch.object(ietf.meeting.models.Session, "_session_recording_url_label", return_value="LABEL") + def test_session_recording_url(self, mock): + for session_type in ["ietf", "interim"]: + session = SessionFactory(meeting__type_id=session_type) + with override_settings(): + if hasattr(settings, "MEETECHO_SESSION_RECORDING_URL"): + del settings.MEETECHO_SESSION_RECORDING_URL + self.assertIsNone(session.session_recording_url()) + + settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com" + self.assertEqual(session.session_recording_url(), "http://player.example.com") + + settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com?{session_label}" + self.assertEqual(session.session_recording_url(), "http://player.example.com?LABEL") + + def test_session_recording_url_label_ietf(self): session = SessionFactory( meeting__type_id='ietf', - meeting__date=meeting_date, - group__acronym=group_acronym, - meeting__number=meeting_number, + meeting__date=datetime.date.today(), + meeting__number="123", + group__acronym="acro", ) - with override_settings(): - if hasattr(settings, "MEETECHO_SESSION_RECORDING_URL"): - del settings.MEETECHO_SESSION_RECORDING_URL - self.assertIsNone(session.session_recording_url()) - - settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com" - self.assertEqual(session.session_recording_url(), "http://player.example.com") - - settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com?{session_label}" - self.assertIn(f"IETF{meeting_number}-{group_acronym.upper()}", session.session_recording_url()) - self.assertIn(f"{meeting_date.strftime('%Y%m%d')}", session.session_recording_url()) - self.assertTrue(session.session_recording_url().startswith("http://player.example.com")) + session_time = session.official_timeslotassignment().timeslot.time + self.assertEqual( + f"IETF123-ACRO-{session_time:%Y%m%d-%H%M}", # n.b., time in label is UTC + session._session_recording_url_label()) - # interim meeting + def test_session_recording_url_label_interim(self): session = SessionFactory( meeting__type_id='interim', - meeting__date=meeting_date, - group__acronym=group_acronym, + meeting__date=datetime.date.today(), + group__acronym="acro", ) - with override_settings(): - if hasattr(settings, "MEETECHO_SESSION_RECORDING_URL"): - del settings.MEETECHO_SESSION_RECORDING_URL - self.assertIsNone(session.session_recording_url()) - - settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com" - self.assertEqual(session.session_recording_url(), "http://player.example.com") - - settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com?{session_label}" - self.assertIn(f"IETF-{group_acronym.upper()}", session.session_recording_url()) - self.assertIn(f"{meeting_date.strftime('%Y%m%d')}", session.session_recording_url()) - self.assertTrue(session.session_recording_url().startswith("http://player.example.com")) + session_time = session.official_timeslotassignment().timeslot.time + self.assertEqual( + f"IETF-ACRO-{session_time:%Y%m%d-%H%M}", # n.b., time in label is UTC + session._session_recording_url_label()) From e4cdf2e718cf71e200278a91e4728a24d95c171b Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 13 Sep 2024 11:32:29 -0300 Subject: [PATCH 3/3] test: use date_today() --- ietf/meeting/tests_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ietf/meeting/tests_models.py b/ietf/meeting/tests_models.py index 17b2a3600c..8457423c51 100644 --- a/ietf/meeting/tests_models.py +++ b/ietf/meeting/tests_models.py @@ -175,7 +175,7 @@ def test_session_recording_url(self, mock): def test_session_recording_url_label_ietf(self): session = SessionFactory( meeting__type_id='ietf', - meeting__date=datetime.date.today(), + meeting__date=date_today(), meeting__number="123", group__acronym="acro", ) @@ -187,7 +187,7 @@ def test_session_recording_url_label_ietf(self): def test_session_recording_url_label_interim(self): session = SessionFactory( meeting__type_id='interim', - meeting__date=datetime.date.today(), + meeting__date=date_today(), group__acronym="acro", ) session_time = session.official_timeslotassignment().timeslot.time