@@ -133,7 +133,7 @@ def test_create_next_unit_version_with_two_unpinned_components(self):
133
133
134
134
def test_create_next_unit_version_with_unpinned_and_pinned_components (self ):
135
135
"""
136
- Test creating a unit version with one unpinned and one pinned component.
136
+ Test creating a unit version with one unpinned and one pinned 📌 component.
137
137
"""
138
138
unit , unit_version = authoring_api .create_unit_and_version (
139
139
learning_package_id = self .learning_package .id ,
@@ -145,15 +145,15 @@ def test_create_next_unit_version_with_unpinned_and_pinned_components(self):
145
145
unit_version_v2 = authoring_api .create_next_unit_version (
146
146
unit = unit ,
147
147
title = "Unit" ,
148
- components = [self .component_1 , self .component_2_v1 ], # Note the "v1" pinning it to version 2
148
+ components = [self .component_1 , self .component_2_v1 ], # Note the "v1" pinning 📌 the second one to version 1
149
149
created = self .now ,
150
150
created_by = None ,
151
151
)
152
152
assert unit_version_v2 .version_num == 2
153
153
assert unit_version_v2 in unit .versioning .versions .all ()
154
154
assert authoring_api .get_components_in_draft_unit (unit ) == [
155
155
authoring_api .UnitListEntry (component_version = self .component_1_v1 , pinned = False ),
156
- authoring_api .UnitListEntry (component_version = self .component_2_v1 , pinned = True ), # Pinned to v1
156
+ authoring_api .UnitListEntry (component_version = self .component_2_v1 , pinned = True ), # Pinned 📌 to v1
157
157
]
158
158
assert authoring_api .get_components_in_published_unit (unit ) is None
159
159
@@ -318,6 +318,58 @@ def test_query_count_of_contains_unpublished_changes(self):
318
318
# Test viewing old snapshots of units and components by passing in a timestamp (or PublishLog PK) to a
319
319
# get_historic_unit() API?
320
320
321
+ def test_snapshots_of_published_unit (self ):
322
+ """
323
+ Test that we can access snapshots of the historic published version of
324
+ units and their contents.
325
+ """
326
+ # At first the unit has one component (unpinned):
327
+ unit = self .create_unit_with_components ([self .component_1 ])
328
+ self .modify_component (self .component_1 , title = "Component 1 as of checkpoint 1" )
329
+
330
+ # Publish everything, creating Checkpoint 1
331
+ checkpoint_1 = authoring_api .publish_all_drafts (self .learning_package .id , message = "checkpoint 1" )
332
+
333
+ ########################################################################
334
+
335
+ # Now we update the title of the component.
336
+ self .modify_component (self .component_1 , title = "Component 1 as of checkpoint 2" )
337
+ # Publish everything, creating Checkpoint 2
338
+ checkpoint_2 = authoring_api .publish_all_drafts (self .learning_package .id , message = "checkpoint 2" )
339
+ ########################################################################
340
+
341
+ # Now add a second component to the unit:
342
+ self .modify_component (self .component_1 , title = "Component 1 as of checkpoint 3" )
343
+ self .modify_component (self .component_2 , title = "Component 2 as of checkpoint 3" )
344
+ authoring_api .create_next_unit_version (
345
+ unit = unit ,
346
+ title = "Unit title in checkpoint 3" ,
347
+ components = [self .component_1 , self .component_2 ],
348
+ created = self .now ,
349
+ )
350
+ # Publish everything, creating Checkpoint 3
351
+ checkpoint_3 = authoring_api .publish_all_drafts (self .learning_package .id , message = "checkpoint 3" )
352
+ ########################################################################
353
+
354
+ # Modify the drafts, but don't publish:
355
+ self .modify_component (self .component_1 , title = "Component 1 draft" )
356
+ self .modify_component (self .component_2 , title = "Component 2 draft" )
357
+
358
+ # Now fetch the snapshots:
359
+ as_of_checkpoint_1 = authoring_api .get_components_in_published_unit_as_of (unit , checkpoint_1 .pk )
360
+ assert [cv .component_version .title for cv in as_of_checkpoint_1 ] == [
361
+ "Component 1 as of checkpoint 1" ,
362
+ ]
363
+ as_of_checkpoint_2 = authoring_api .get_components_in_published_unit_as_of (unit , checkpoint_2 .pk )
364
+ assert [cv .component_version .title for cv in as_of_checkpoint_2 ] == [
365
+ "Component 1 as of checkpoint 2" ,
366
+ ]
367
+ as_of_checkpoint_3 = authoring_api .get_components_in_published_unit_as_of (unit , checkpoint_3 .pk )
368
+ assert [cv .component_version .title for cv in as_of_checkpoint_3 ] == [
369
+ "Component 1 as of checkpoint 3" ,
370
+ "Component 2 as of checkpoint 3" ,
371
+ ]
372
+
321
373
def test_next_version_with_different_different_title (self ):
322
374
"""Test creating a unit version with a different title.
323
375
0 commit comments