[3543] adding unit test for delete aggregation
@@ -14,7 +14,7 @@ from hs_file_types.views import set_file_type, add_metadata_element, update_meta
update_key_value_metadata, delete_key_value_metadata, add_keyword_metadata, \
delete_keyword_metadata, update_netcdf_file, update_dataset_name, update_refts_abstract, \
update_sqlite_file, update_timeseries_abstract, get_timeseries_metadata, remove_aggregation, \
- delete_coverage_element, update_aggregation_coverage, move_aggregation
+ delete_coverage_element, update_aggregation_coverage, move_aggregation, delete_aggregation
from hs_file_types.models import GeoRasterLogicalFile, NetCDFLogicalFile, NetCDFFileMetaData, \
RefTimeseriesLogicalFile, TimeSeriesLogicalFile, GenericLogicalFile, FileSetLogicalFile
from hs_file_types.tests.utils import CompositeResourceTestMixin
@@ -335,6 +335,48 @@ class TestFileTypeViewFunctions(MockIRODSTestCaseMixin, TestCase, CompositeResou
self.composite_resource.delete()
+ def test_delete_aggregation(self):
+ # here we are testing the delete_aggregation view function
+
+ self.create_composite_resource()
+ # new_folder = 'my_folder'
+ # ResourceFile.create_folder(self.composite_resource, new_folder)
+ # add the the nc file to the resource at the above folder
+ self.add_file_to_resource(file_to_add=self.netcdf_file)
+ self.assertEqual(self.composite_resource.files.all().count(), 1)
+ res_file = self.composite_resource.files.first()
+
+ # set the nc file to NetCDFLogicalFile (aggregation)
+ NetCDFLogicalFile.set_file_type(self.composite_resource, self.user, res_file.id)
+
+ # test that we have one logical file of type NetCDFLogicalFile
+ self.assertEqual(NetCDFLogicalFile.objects.count(), 1)
+ self.assertEqual(NetCDFFileMetaData.objects.count(), 1)
+ logical_file = NetCDFLogicalFile.objects.first()
+ self.assertEqual(logical_file.files.all().count(), 2)
+ self.assertEqual(self.composite_resource.files.all().count(), 2)
+
+ url_params = {'resource_id': self.composite_resource.short_id,
+ 'file_type_id': logical_file.id,
+ 'hs_file_type': 'NetCDFLogicalFile'
+ }
+ url = reverse('delete_aggregation', kwargs=url_params)
+ request = self.factory.post(url)
+ request.user = self.user
+ # this is the view function we are testing
+ response = delete_aggregation(request, resource_id=self.composite_resource.short_id,
+ file_type_id=logical_file.id,
+ hs_file_type='NetCDFLogicalFile')
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ # test there is no NetCDFLogicalFile object
+ self.assertEqual(NetCDFLogicalFile.objects.count(), 0)
+ # test there is no NetCDFFileMetaData object
+ self.assertEqual(NetCDFFileMetaData.objects.count(), 0)
+ # check the files are deleted
+ self.assertEqual(self.composite_resource.files.all().count(), 0)
+
+ self.composite_resource.delete()
+
def test_move_aggregation(self):
# here we are testing the move_aggregation view function
