Skip to content
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

Use static GUIDs in the frab schedule, when possible #614

Merged
merged 3 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions wafer/schedule/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,17 @@ def get_duration_minutes(self):

@property
def guid(self):
"""Return a GUID for the ScheduleItem (for frab xml)"""
hmac = salted_hmac('wafer-event-uuid', str(self.pk))
"""Return a GUID for the ScheduleItem (for frab xml)

We return static GUIDs across re-scheduling, when possible.
"""
if self.talk:
id_ = 'talk:' + str(self.talk.pk)
elif self.page and self.page.scheduleitem_set.count() == 1:
id_ = 'page:' + str(self.page.pk)
else:
id_ = 'schedule_item:' + str(self.pk)
hmac = salted_hmac('wafer-event-uuid', id_)
return UUID(bytes=hmac.digest()[:16])


Expand Down
4 changes: 3 additions & 1 deletion wafer/schedule/templates/wafer.schedule/penta_schedule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
{# this is more than a little horrible, but will do for testing #}
{% for row_venue, items in row.items.items %}
{% if row_venue == venue and items.item %}
{# The event id is the ScheduleItem pk, which should be unique enough #}
{# The event id is the ScheduleItem pk, which should be unique #}
{# enough, but changes if the event is rescheduled. #}
{# Talks' guid will be stable across re-scheduling. #}
<event id="{{ items.item.pk }}" guid="{{ items.item.guid }}">
<date>{{ row.start_time.isoformat }}</date>
<start>{{ row.start_time|time:"H:i" }}</start>
Expand Down
31 changes: 31 additions & 0 deletions wafer/schedule/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,34 @@ def test_slot_save_prev_next(self):
# No other items should have changed, as time changes don't
# cascade that way
self.assertEqual(item.last_updated, update_times[item.pk])


class ScheduleItemGUIDTests(TestCase):
def setUp(self):
venue1 = Venue.objects.create(order=1, name='Venue 1')
self.venues = [venue1]

def test_unique_guid(self):
"""Test that the all guids are unique."""
pages = make_pages(2)
items = make_items(self.venues * 2, pages)

guids = set(item.guid for item in items)
self.assertEqual(len(guids), len(items))

def test_rescheduled_page_keeps_guid(self):
"""A page that's in the schedule once keeps its guid when rescheduled"""
pages = make_pages(2)
items = make_items(self.venues * 2, pages)
guid = items[0].guid
# Reschedule
for item in items:
item.delete()
items = make_items(self.venues, pages)
self.assertEqual(guid, items[0].guid)

def test_double_scheduled_page_has_unique_guid(self):
"""A page that's in the schedule twice has a unique GUID per instance"""
pages = make_pages(1)
items = make_items(self.venues * 2, pages * 2)
self.assertNotEqual(items[0].guid, items[1].guid)