1414from django .core .exceptions import ValidationError
1515from django .core .files .uploadedfile import SimpleUploadedFile
1616from django .urls import reverse
17- from django .utils import timezone
17+ from django .utils import timezone , text
1818from guardian .shortcuts import assign_perm
1919import numpy as np
2020from specutils import Spectrum1D
@@ -171,14 +171,22 @@ def test_no_path_overide(self):
171171 """Test that the default path is used if no overide is set"""
172172 filename = 'afile.fits'
173173 path = data_product_path (self .data_product , filename )
174- self .assertIn (f'FakeRoboticFacility/{ filename } ' , path )
174+ self .assertIn (f'{ text . slugify ( FakeRoboticFacility . name ) } /{ filename } ' , path )
175175
176176 @override_settings (DATA_PRODUCT_PATH = 'tom_dataproducts.tests.tests.dp_path' )
177177 def test_path_overide (self ):
178178 """Test that the overide path is used if set"""
179179 path = data_product_path (self .data_product , 'afile.fits' )
180180 self .assertIn ('new_path/afile.fits' , path )
181181
182+ def test_target_name_with_slashes (self ):
183+ """Test that a target with a name such as C/2021 G2 (ATLAS) doesn't create
184+ mutiple directories in the filesystem. TOMToolkit/tom_base #1185"""
185+ self .target .name = 'C/2021 G2 (ATLAS)'
186+ self .target .save ()
187+ path = data_product_path (self .data_product , 'afile.fits' )
188+ self .assertEqual ('c2021-g2-atlas/fakeroboticfacility/afile.fits' , path )
189+
182190
183191@override_settings (TOM_FACILITY_CLASSES = ['tom_observations.tests.utils.FakeRoboticFacility' ],
184192 TARGET_PERMISSIONS_ONLY = False )
@@ -309,7 +317,9 @@ def test_upload_data_for_target(self, run_data_processor_mock):
309317 },
310318 follow = True
311319 )
312- self .assertContains (response , 'Successfully uploaded: {0}/none/afile.fits' .format (self .target .name ))
320+ self .assertContains (response , 'Successfully uploaded: {0}/none/afile.fits' .format (
321+ text .slugify (self .target .name )
322+ ))
313323
314324 def test_upload_data_for_observation (self , run_data_processor_mock ):
315325 response = self .client .post (
@@ -326,8 +336,8 @@ def test_upload_data_for_observation(self, run_data_processor_mock):
326336 follow = True
327337 )
328338 self .assertContains (response , 'Successfully uploaded: {0}/{1}/bfile.fits' .format (
329- self .target .name , FakeRoboticFacility .name )
330- )
339+ text . slugify ( self .target .name ), text . slugify ( FakeRoboticFacility .name )
340+ ))
331341
332342
333343class TestDeleteDataProducts (TestCase ):
0 commit comments