chore(api): rename schedule models fields

This commit is contained in:
jo 2022-07-17 22:27:57 +02:00 committed by Kyle Robbertze
parent 8ceb1419a0
commit 57046e2a9d
8 changed files with 224 additions and 334 deletions

View file

@ -9,49 +9,49 @@ class TestSchedule(TestCase):
@classmethod
def setUpTestData(cls):
cls.show_instance = ShowInstance(
created=datetime(year=2021, month=10, day=1, hour=12),
starts=datetime(year=2021, month=10, day=2, hour=1),
ends=datetime(year=2021, month=10, day=2, hour=2),
created_at=datetime(year=2021, month=10, day=1, hour=12),
starts_at=datetime(year=2021, month=10, day=2, hour=1),
ends_at=datetime(year=2021, month=10, day=2, hour=2),
)
cls.length = timedelta(minutes=10)
cls.cue_in = timedelta(seconds=1)
cls.cue_out = cls.length - timedelta(seconds=4)
def create_schedule(self, starts):
def create_schedule(self, starts_at):
return Schedule(
starts=starts,
ends=starts + self.length,
starts_at=starts_at,
ends_at=starts_at + self.length,
cue_in=self.cue_in,
cue_out=self.cue_out,
instance=self.show_instance,
)
def test_get_cueout(self):
def test_get_cue_out(self):
# No overlapping schedule datetimes, normal usecase:
item1_starts = datetime(year=2021, month=10, day=2, hour=1, minute=30)
item1 = self.create_schedule(item1_starts)
self.assertEqual(item1.get_cueout(), self.cue_out)
self.assertEqual(item1.get_ends(), item1_starts + self.length)
self.assertEqual(item1.get_cue_out(), self.cue_out)
self.assertEqual(item1.get_ends_at(), item1_starts + self.length)
# Mixed overlapping schedule datetimes (only ends is overlapping):
item_2_starts = datetime(year=2021, month=10, day=2, hour=1, minute=55)
item_2 = self.create_schedule(item_2_starts)
self.assertEqual(item_2.get_cueout(), timedelta(minutes=5))
self.assertEqual(item_2.get_ends(), self.show_instance.ends)
self.assertEqual(item_2.get_cue_out(), timedelta(minutes=5))
self.assertEqual(item_2.get_ends_at(), self.show_instance.ends_at)
# Fully overlapping schedule datetimes (starts and ends are overlapping):
item3_starts = datetime(year=2021, month=10, day=2, hour=2, minute=1)
item3 = self.create_schedule(item3_starts)
self.assertEqual(item3.get_cueout(), self.cue_out)
self.assertEqual(item3.get_ends(), self.show_instance.ends)
self.assertEqual(item3.get_cue_out(), self.cue_out)
self.assertEqual(item3.get_ends_at(), self.show_instance.ends_at)
def test_is_valid(self):
def test_overbooked(self):
# Starts before the schedule ends
item1_starts = datetime(year=2021, month=10, day=2, hour=1, minute=30)
item1 = self.create_schedule(item1_starts)
self.assertTrue(item1.is_valid)
self.assertFalse(item1.overbooked)
# Starts after the schedule ends
item_2_starts = datetime(year=2021, month=10, day=2, hour=3)
item_2 = self.create_schedule(item_2_starts)
self.assertFalse(item_2.is_valid)
self.assertTrue(item_2.overbooked)

View file

@ -25,13 +25,13 @@ class TestScheduleViewSet(APITestCase):
)
show = baker.make(
"schedule.ShowInstance",
starts=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
ends=datetime.now(tz=timezone.utc) + timedelta(minutes=5),
starts_at=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
ends_at=datetime.now(tz=timezone.utc) + timedelta(minutes=5),
)
schedule_item = baker.make(
"schedule.Schedule",
starts=datetime.now(tz=timezone.utc),
ends=datetime.now(tz=timezone.utc) + file.length,
starts_at=datetime.now(tz=timezone.utc),
ends_at=datetime.now(tz=timezone.utc) + file.length,
cue_out=file.cue_out,
instance=show,
file=file,
@ -41,7 +41,7 @@ class TestScheduleViewSet(APITestCase):
self.assertEqual(response.status_code, 200)
result = response.json()
self.assertEqual(
dateparse.parse_datetime(result[0]["ends"]), schedule_item.ends
dateparse.parse_datetime(result[0]["ends_at"]), schedule_item.ends_at
)
self.assertEqual(dateparse.parse_duration(result[0]["cue_out"]), file.cue_out)
@ -56,13 +56,13 @@ class TestScheduleViewSet(APITestCase):
)
show = baker.make(
"schedule.ShowInstance",
starts=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
ends=datetime.now(tz=timezone.utc) + timedelta(seconds=20),
starts_at=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
ends_at=datetime.now(tz=timezone.utc) + timedelta(seconds=20),
)
schedule_item = baker.make(
"schedule.Schedule",
starts=datetime.now(tz=timezone.utc),
ends=datetime.now(tz=timezone.utc) + file.length,
starts_at=datetime.now(tz=timezone.utc),
ends_at=datetime.now(tz=timezone.utc) + file.length,
instance=show,
file=file,
)
@ -70,11 +70,11 @@ class TestScheduleViewSet(APITestCase):
response = self.client.get(self.path)
self.assertEqual(response.status_code, 200)
result = response.json()
self.assertEqual(dateparse.parse_datetime(result[0]["ends"]), show.ends)
expected = show.ends - schedule_item.starts
self.assertEqual(dateparse.parse_datetime(result[0]["ends_at"]), show.ends_at)
expected = show.ends_at - schedule_item.starts_at
self.assertEqual(dateparse.parse_duration(result[0]["cue_out"]), expected)
self.assertNotEqual(
dateparse.parse_datetime(result[0]["ends"]), schedule_item.ends
dateparse.parse_datetime(result[0]["ends_at"]), schedule_item.ends_at
)
def test_schedule_item_invalid(self):
@ -88,33 +88,33 @@ class TestScheduleViewSet(APITestCase):
)
show = baker.make(
"schedule.ShowInstance",
starts=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
ends=datetime.now(tz=timezone.utc) + timedelta(minutes=5),
starts_at=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
ends_at=datetime.now(tz=timezone.utc) + timedelta(minutes=5),
)
schedule_item = baker.make(
"schedule.Schedule",
starts=datetime.now(tz=timezone.utc),
ends=datetime.now(tz=timezone.utc) + file.length,
starts_at=datetime.now(tz=timezone.utc),
ends_at=datetime.now(tz=timezone.utc) + file.length,
cue_out=file.cue_out,
instance=show,
file=file,
)
invalid_schedule_item = baker.make( # pylint: disable=unused-variable
"schedule.Schedule",
starts=show.ends + timedelta(minutes=1),
ends=show.ends + timedelta(minutes=1) + file.length,
starts_at=show.ends_at + timedelta(minutes=1),
ends_at=show.ends_at + timedelta(minutes=1) + file.length,
cue_out=file.cue_out,
instance=show,
file=file,
)
self.client.credentials(HTTP_AUTHORIZATION=f"Api-Key {self.token}")
response = self.client.get(self.path, {"is_valid": True})
response = self.client.get(self.path, {"overbooked": False})
self.assertEqual(response.status_code, 200)
result = response.json()
# The invalid item should be filtered out and not returned
self.assertEqual(len(result), 1)
self.assertEqual(
dateparse.parse_datetime(result[0]["ends"]), schedule_item.ends
dateparse.parse_datetime(result[0]["ends_at"]), schedule_item.ends_at
)
self.assertEqual(dateparse.parse_duration(result[0]["cue_out"]), file.cue_out)
@ -131,21 +131,21 @@ class TestScheduleViewSet(APITestCase):
show = baker.make(
"schedule.ShowInstance",
starts=filter_point - timedelta(minutes=5),
ends=filter_point + timedelta(minutes=5),
starts_at=filter_point - timedelta(minutes=5),
ends_at=filter_point + timedelta(minutes=5),
)
schedule_item = baker.make(
"schedule.Schedule",
starts=filter_point,
ends=filter_point + file.length,
starts_at=filter_point,
ends_at=filter_point + file.length,
cue_out=file.cue_out,
instance=show,
file=file,
)
previous_item = baker.make( # pylint: disable=unused-variable
"schedule.Schedule",
starts=filter_point - timedelta(minutes=5),
ends=filter_point - timedelta(minutes=5) + file.length,
starts_at=filter_point - timedelta(minutes=5),
ends_at=filter_point - timedelta(minutes=5) + file.length,
cue_out=file.cue_out,
instance=show,
file=file,
@ -156,12 +156,13 @@ class TestScheduleViewSet(APITestCase):
)
range_end = (filter_point + timedelta(minutes=1)).isoformat(timespec="seconds")
response = self.client.get(
self.path, {"starts__range": f"{range_start},{range_end}"}
self.path,
{"starts_after": range_start, "starts_before": range_end},
)
self.assertEqual(response.status_code, 200)
result = response.json()
# The previous_item should be filtered out and not returned
self.assertEqual(len(result), 1)
self.assertEqual(
dateparse.parse_datetime(result[0]["starts"]), schedule_item.starts
dateparse.parse_datetime(result[0]["starts_at"]), schedule_item.starts_at
)