def test_display_set_permissions_signal(client, reverse): ds1, ds2 = DisplaySetFactory.create_batch(2) im1, im2, im3, im4 = ImageFactory.create_batch(4) civ1, civ2, civ3, civ4 = ( ComponentInterfaceValueFactory(image=im1), ComponentInterfaceValueFactory(image=im2), ComponentInterfaceValueFactory(image=im3), ComponentInterfaceValueFactory(image=im4), ) with capture_on_commit_callbacks(execute=True): if reverse: for civ in [civ1, civ2, civ3, civ4]: civ.display_sets.add(ds1, ds2) for civ in [civ3, civ4]: civ.display_sets.remove(ds1, ds2) for civ in [civ1, civ2]: civ.display_sets.remove(ds2) else: # Test that adding images works ds1.values.add(civ1, civ2, civ3, civ4) # Test that removing images works ds1.values.remove(civ3, civ4) assert get_groups_with_set_perms(im1) == { ds1.reader_study.editors_group: {"view_image"}, ds1.reader_study.readers_group: {"view_image"}, } assert get_groups_with_set_perms(im2) == { ds1.reader_study.editors_group: {"view_image"}, ds1.reader_study.readers_group: {"view_image"}, } assert get_groups_with_set_perms(im3) == {} assert get_groups_with_set_perms(im4) == {} # Test clearing with capture_on_commit_callbacks(execute=True): if reverse: civ1.display_sets.clear() civ2.display_sets.clear() else: ds1.values.clear() assert get_groups_with_set_perms(im1) == {} assert get_groups_with_set_perms(im2) == {}
def test_deleting_display_set_removes_permissions(): ds1, ds2 = DisplaySetFactory.create_batch(2) im = ImageFactory() civ = ComponentInterfaceValueFactory(image=im) with capture_on_commit_callbacks(execute=True): ds1.values.set([civ]) ds2.values.set([civ]) assert get_groups_with_set_perms(im) == { ds1.reader_study.editors_group: {"view_image"}, ds1.reader_study.readers_group: {"view_image"}, ds2.reader_study.editors_group: {"view_image"}, ds2.reader_study.readers_group: {"view_image"}, } with capture_on_commit_callbacks(execute=True): ds1.delete() assert get_groups_with_set_perms(im) == { ds2.reader_study.editors_group: {"view_image"}, ds2.reader_study.readers_group: {"view_image"}, }