export_import: snapshots on application import (#87653)

This commit is contained in:
Lauréline Guérin 2024-03-01 10:51:35 +01:00
parent 07512150e8
commit df0e356e75
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 17 additions and 0 deletions

View File

@ -260,6 +260,11 @@ class BundleImport(GenericAPIView):
self.application, existing_component
)
self.application_elements.add(element.content_object)
if self.install is True:
existing_component.take_snapshot(
comment=_('Application (%s)') % self.application,
application=self.application,
)
def unlink_obsolete_objects(self):
known_elements = ApplicationElement.objects.filter(application=self.application)

View File

@ -506,6 +506,12 @@ def test_bundle_import(app, admin_user):
assert application.editable is False
assert application.visible is True
assert ApplicationElement.objects.count() == 8
for model in [Agenda, Category, EventsType, Resource, UnavailabilityCalendar]:
for instance in model.objects.all():
last_snapshot = model.get_snapshot_model().objects.filter(instance=instance).latest('pk')
assert last_snapshot.comment == 'Application (Test)'
assert last_snapshot.application_slug == 'test'
assert last_snapshot.application_version == '42.0'
# check editable flag is kept on install
application.editable = True
@ -535,6 +541,12 @@ def test_bundle_import(app, admin_user):
).exists()
is False
)
for model in [Agenda, Category, EventsType, Resource, UnavailabilityCalendar]:
for instance in model.objects.all():
last_snapshot = model.get_snapshot_model().objects.filter(instance=instance).latest('pk')
assert last_snapshot.comment == 'Application (Test)'
assert last_snapshot.application_slug == 'test'
assert last_snapshot.application_version == '42.1'
def test_bundle_declare(app, admin_user):