def test_delete_release(self): self.clear() ri1 = ReleaseImage(release=self.r, archive_item=self.ima) ri1.save() ima = Image.objects.get(pk="eso0945a") self.assertEqual(ima.release_date, self.now) self.assertEqual(ima.release_date_owner, self.r.get_object_identifier()) ima_da = Image.objects.language('da').get(pk="eso0945a") self.assertEqual(ima_da.release_date, self.now) self.assertEqual(ima_da.release_date_owner, self.r.get_object_identifier()) ima_release_date_old = ima.release_date self.r.delete() ima = Image.objects.get(pk="eso0945a") self.assertEqual(ima.release_date, ima_release_date_old) self.assertEqual(ima.release_date_owner, '') ima_da = Image.objects.language('da').get(pk="eso0945a") self.assertEqual(ima_da.release_date, ima_release_date_old) self.assertEqual(ima_da.release_date_owner, '')
def test_multiple_releases_deletion_notowner(self): """ When an image has more than one related release, and you do not delete the owner but one of the others, the the release date should stay the same. """ self.clear() ri1 = ReleaseImage(release=self.r, archive_item=self.ima) ri1.save() ri2 = ReleaseImage(release=self.r2, archive_item=self.ima) ri2.save() (r, r2, _r3, ima, _imb, ima_da, _imb_da) = self._get_objects() self.assertEqual(r.release_date, self.now) self.assertEqual(r2.release_date, self.now2) self.assertEqual(ima.release_date, self.now) self.assertEqual(ima.release_date_owner, r.get_object_identifier()) self.assertEqual(ima_da.release_date, self.now) self.assertEqual(ima_da.release_date_owner, r.get_object_identifier()) ri2.delete() (r, r2, _r3, ima, _imb, ima_da, _imb_da) = self._get_objects() self.assertEqual(r.release_date, self.now) self.assertEqual(r2.release_date, self.now2) self.assertEqual(ima.release_date, self.now) self.assertEqual(ima.release_date_owner, r.get_object_identifier()) self.assertEqual(ima_da.release_date, self.now) self.assertEqual(ima_da.release_date_owner, r.get_object_identifier())
def test_rel_creation_simple(self): """ Test create new relation between source and dest """ self.clear() ri1 = ReleaseImage(release=self.r, archive_item=self.ima) ri1.save() ri2 = ReleaseImage(release=self.r, archive_item=self.imb) ri2.save() self._assert_datetimes(self.now, self.now, self.r.get_object_identifier(), self.now, self.r.get_object_identifier())
def test_many_to_many(): t = typ() # Setup i1 = Image(title='Image 1', priority=10, pk='eso1501a') i2 = Image(title='Image 2', priority=10, pk='eso1502a') i3 = Image(title='Image 3', priority=10, pk='eso1503a') i4 = Image(title='Image 4', priority=10, pk='eso1504a') ts1 = TaggingStatus(slug='ts1', name='TS1') ts2 = TaggingStatus(slug='ts2', name='TS2') ts3 = TaggingStatus(slug='ts3', name='TS3') ts4 = TaggingStatus(slug='ts4', name='TS4') _ = [x.save() for x in [i1, i2, i3, i4, ts1, ts2, ts3, ts4]] # Forward empty relations assert not i1.tagging_status.all().exists() assert not i2.tagging_status.all().exists() assert not i3.tagging_status.all().exists() assert not i4.tagging_status.all().exists() # Reverse empty relations assert not ts1.image_set.all().exists() assert not ts2.image_set.all().exists() assert not ts3.image_set.all().exists() assert not ts4.image_set.all().exists() # Setup relations i1.tagging_status.add(ts1, ts2, ts3) i2.tagging_status.add(ts2, ts3) i3.tagging_status.add(ts4) # Forward relations assert list(i1.tagging_status.all()) == [ts1, ts2, ts3] assert list(i2.tagging_status.all()) == [ts2, ts3] assert list(i3.tagging_status.all()) == [ts4] assert not i4.tagging_status.all().exists() # Reverse solutions assert list(ts1.image_set.all()) == [i1] assert list(ts2.image_set.all()) == [i1, i2] assert list(ts3.image_set.all()) == [i1, i2] assert list(ts4.image_set.all()) == [i3] # Adding to relation via translation object i1da = Image(title='Image 1da', source=i1, pk='eso1501ada') i1de = Image(title='Image 1de', source=i1, pk='eso1501ade') i4da = Image(title='Image 4da', source=i4, pk='eso1504ada') _ = [x.save() for x in [i1da, i1de, i4da]] i1da.tagging_status.add(ts4) i4da.tagging_status.add(ts1) assert list(i1.tagging_status.all()) == [ts1, ts2, ts3, ts4] assert list(i1da.tagging_status.all()) == [ts1, ts2, ts3, ts4] assert list(i1de.tagging_status.all()) == [ts1, ts2, ts3, ts4] assert list(i4.tagging_status.all()) == [ts1] assert list(i4da.tagging_status.all()) == [ts1] ts4.image_set.add(i4) assert list(i4.tagging_status.all()) == [ts1, ts4] assert list(i4da.tagging_status.all()) == [ts1, ts4] # Removing relation via translation object i1.tagging_status.remove(ts3, ts4) assert list(i1.tagging_status.all()) == [ts1, ts2] assert list(i1da.tagging_status.all()) == [ts1, ts2] assert list(i1de.tagging_status.all()) == [ts1, ts2] ts2.image_set.remove(i1de) assert list(i1.tagging_status.all()) == [ts1] assert list(i1da.tagging_status.all()) == [ts1] assert list(i1de.tagging_status.all()) == [ts1] # Clear relations i4.tagging_status.clear() assert not i4.tagging_status.all().exists() assert list(ts4.image_set.all()) == [i3] # Through relations t1 = Release(release_type=t, title='Release 1', id='eso1501') t2 = Release(release_type=t, title='Release 2', id='eso1502') t1_da = Release(title='Release 1da', source=t1, lang='da', id='eso1501da') t1_de = Release(title='Release 1de', source=t1, lang='de', id='eso1501de') _ = [x.save() for x in [t1, t2, t1_da, t1_de]] ri1 = ReleaseImage(archive_item=i1, release=t1) ri2 = ReleaseImage(archive_item=i2, release=t1) ri3 = ReleaseImage(archive_item=i3, release=t1) ri4 = ReleaseImage(archive_item=i4, release=t2) _ = [x.save() for x in [t1, t2, t1_da, t1_de, ri1, ri2, ri3, ri4]] assert list(t1.related_images.all()) == [i1, i2, i3] assert list(t1_da.related_images.all()) == [i1, i2, i3] assert list(t1_de.related_images.all()) == [i1, i2, i3] assert list(t2.related_images.all()) == [i4] assert list(i1.releaseimage_set.all()) == [ri1] assert list(i1da.releaseimage_set.all()) == [ri1] assert list(i1de.releaseimage_set.all()) == [ri1] assert list(i4.releaseimage_set.all()) == [ri4] t2.related_images.clear() assert list(i4.releaseimage_set.all()) == []
def test_multiple_releases_deletion_owner(self): """ When an image has more than one related release, and you delete the owner of the release, you must ensure that the release date is updated to the other one. """ self.clear() ri1 = ReleaseImage(release=self.r, archive_item=self.ima) ri1.save() ri2 = ReleaseImage(release=self.r2, archive_item=self.ima) ri2.save() ri3 = ReleaseImage(release=self.r3, archive_item=self.ima) ri3.save() (r, r2, _r3, ima, _imb, ima_da, _imb_da) = self._get_objects() self.assertEqual(r.release_date, self.now) self.assertEqual(r2.release_date, self.now2) self.assertEqual(ima.release_date, self.now) self.assertEqual(ima.release_date_owner, r.get_object_identifier()) self.assertEqual(ima_da.release_date, self.now) self.assertEqual(ima_da.release_date_owner, r.get_object_identifier()) ri1.delete() (r, r2, _r3, ima, _imb, ima_da, _imb_da) = self._get_objects() self.assertEqual(r.release_date, self.now) self.assertEqual(r2.release_date, self.now2) self.assertEqual(ima.release_date, self.now2) self.assertEqual(ima.release_date_owner, r2.get_object_identifier()) self.assertEqual(ima_da.release_date, self.now2) self.assertEqual(ima_da.release_date_owner, r2.get_object_identifier())
def test_multiple_releases_creation(self): """ Test that release date in archive items is not overwritten when an image is added to a new release but already have an release date. """ self.clear() ri1 = ReleaseImage(release=self.r, archive_item=self.ima) ri1.save() (r, r2, _r3, ima, imb, ima_da, imb_da) = self._get_objects() self.assertEqual(r.release_date, self.now) self.assertEqual(r2.release_date, self.now2) self.assertEqual(ima.release_date, self.now) self.assertEqual(ima.release_date_owner, r.get_object_identifier()) self.assertEqual(ima_da.release_date, self.now) self.assertEqual(ima_da.release_date_owner, r.get_object_identifier()) #self.assertEqual( imb.release_date, None ) self.assertEqual(imb.release_date_owner, None) self.assertEqual(imb_da.release_date_owner, None) # Todo: ought to be blank and not None #self.assertEqual( imb.release_date_owner, '' ) #self.assertEqual( imb_da.release_date_owner, '' ) # # Set add img a and b to rel 2, where img a is # already owned by rel 1 # ri1_new = ReleaseImage(release=self.r2, archive_item=self.ima) ri1_new.save() ri2 = ReleaseImage(release=self.r2, archive_item=self.imb) ri2.save() (r, r2, _r3, ima, imb, ima_da, imb_da) = self._get_objects() self.assertEqual(r.release_date, self.now) self.assertEqual(r2.release_date, self.now2) self.assertEqual(ima.release_date, self.now) self.assertEqual(ima.release_date_owner, r.get_object_identifier()) self.assertEqual(ima_da.release_date, self.now) self.assertEqual(ima_da.release_date_owner, r.get_object_identifier()) self.assertEqual(imb.release_date, self.now2) self.assertEqual(imb.release_date_owner, r2.get_object_identifier()) self.assertEqual(imb_da.release_date, self.now2) self.assertEqual(imb_da.release_date_owner, r2.get_object_identifier())