refactor: helper for session recording URL; fix test (#7933)

* refactor: session recording URL label helper

* test: update tests, avoid tz dependence

* test: use date_today()
This commit is contained in:
Jennifer Richards 2024-09-13 18:42:51 -03:00 committed by GitHub
parent 65547a7a9d
commit f5c132a20a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 41 deletions

View file

@ -1331,16 +1331,18 @@ class Session(models.Model):
return url.format(session=self) return url.format(session=self)
return None 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): def session_recording_url(self):
url_formatter = getattr(settings, "MEETECHO_SESSION_RECORDING_URL", "") url_formatter = getattr(settings, "MEETECHO_SESSION_RECORDING_URL", "")
url = None url = None
if url_formatter and self.video_stream_url: if url_formatter and self.video_stream_url:
if self.meeting.type.slug == "ietf" and self.has_onsite_tool: url = url_formatter.format(session_label=self._session_recording_url_label())
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)
return url return url

View file

@ -8,6 +8,7 @@ from mock import patch
from django.conf import settings from django.conf import settings
from django.test import override_settings from django.test import override_settings
import ietf.meeting.models
from ietf.group.factories import GroupFactory, GroupHistoryFactory from ietf.group.factories import GroupFactory, GroupHistoryFactory
from ietf.meeting.factories import MeetingFactory, SessionFactory, AttendedFactory, SessionPresentationFactory from ietf.meeting.factories import MeetingFactory, SessionFactory, AttendedFactory, SessionPresentationFactory
from ietf.meeting.models import Session from ietf.meeting.models import Session
@ -156,46 +157,40 @@ class SessionTests(TestCase):
self.assertEqual(Session._alpha_str(27 * 26 - 1), "zz") self.assertEqual(Session._alpha_str(27 * 26 - 1), "zz")
self.assertEqual(Session._alpha_str(27 * 26), "aaa") self.assertEqual(Session._alpha_str(27 * 26), "aaa")
def test_session_recording_url(self): @patch.object(ietf.meeting.models.Session, "_session_recording_url_label", return_value="LABEL")
group_acronym = "foobar" def test_session_recording_url(self, mock):
meeting_date = date_today() for session_type in ["ietf", "interim"]:
meeting_number = 123 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")
# IETF meeting def test_session_recording_url_label_ietf(self):
session = SessionFactory( session = SessionFactory(
meeting__type_id='ietf', meeting__type_id='ietf',
meeting__date=meeting_date, meeting__date=date_today(),
group__acronym=group_acronym, meeting__number="123",
meeting__number=meeting_number, group__acronym="acro",
) )
with override_settings(): session_time = session.official_timeslotassignment().timeslot.time
if hasattr(settings, "MEETECHO_SESSION_RECORDING_URL"): self.assertEqual(
del settings.MEETECHO_SESSION_RECORDING_URL f"IETF123-ACRO-{session_time:%Y%m%d-%H%M}", # n.b., time in label is UTC
self.assertIsNone(session.session_recording_url()) session._session_recording_url_label())
settings.MEETECHO_SESSION_RECORDING_URL = "http://player.example.com" def test_session_recording_url_label_interim(self):
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"))
# interim meeting
session = SessionFactory( session = SessionFactory(
meeting__type_id='interim', meeting__type_id='interim',
meeting__date=meeting_date, meeting__date=date_today(),
group__acronym=group_acronym, group__acronym="acro",
) )
with override_settings(): session_time = session.official_timeslotassignment().timeslot.time
if hasattr(settings, "MEETECHO_SESSION_RECORDING_URL"): self.assertEqual(
del settings.MEETECHO_SESSION_RECORDING_URL f"IETF-ACRO-{session_time:%Y%m%d-%H%M}", # n.b., time in label is UTC
self.assertIsNone(session.session_recording_url()) session._session_recording_url_label())
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"))