unit test for public/shareable resource to be part of collection
@@ -448,6 +448,33 @@ class TestCollection(MockIRODSTestCaseMixin, TransactionTestCase):
self.assertIn(self.resGen2, self.resCollection.resources.all())
self.assertIn(self.resGen5, self.resCollection.resources.all())
+ # make resGen5 not shareable
+ self.resGen5.raccess.shareable = False
+ self.resGen5.raccess.save()
+ # remove all existing contained resources
+ response = self.api_client.post(url_to_update_collection,
+ {'resource_id_list': []},
+ )
+ resp_json = json.loads(response.content.decode())
+ self.assertEqual(resp_json["status"], "success")
+ self.assertEqual(self.resCollection.resources.count(), 0)
+ # trying to add resGen5 (for which user1 has vew permission) to the collection should fail as resGen5 is not
+ # shareable
+ response = self.api_client.post(url_to_update_collection,
+ {'resource_id_list': [self.resGen5.short_id]}, )
+ resp_json = json.loads(response.content.decode())
+ self.assertEqual(resp_json["status"], "error")
+ self.assertEqual(self.resCollection.resources.count(), 0)
+ # make resGen5 public
+ self.resGen5.raccess.public = True
+ self.resGen5.raccess.save()
+ # trying to add resGen5 (public resource not shareable) to the collection should be successful
+ response = self.api_client.post(url_to_update_collection,
+ {'resource_id_list': [self.resGen5.short_id]}, )
+ resp_json = json.loads(response.content.decode())
+ self.assertEqual(resp_json["status"], "success")
+ self.assertEqual(self.resCollection.resources.count(), 1)
+
# test adding resources to a collection that does not have all the required metadata
self.assertEqual(self.resCollection_with_missing_metadata.resources.count(), 0)
url_to_update_collection = self.url_to_update_collection.format(
