File tree Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change @@ -1268,26 +1268,27 @@ def delete(cls, processed_data_id):
1268
1268
1269
1269
Raises
1270
1270
------
1271
- QiitaDBUnknownIDError
1272
- If the processed data id doesn't exist
1273
1271
QiitaDBStatusError
1274
1272
If the processed data status is not sandbox
1273
+ QiitaDBError
1274
+ If the processed data has (meta)analyses
1275
1275
"""
1276
1276
if cls (processed_data_id ).status != 'sandbox' :
1277
1277
raise QiitaDBStatusError (
1278
1278
"Illegal operation on non sandbox processed data" )
1279
1279
1280
1280
conn_handler = SQLConnectionHandler ()
1281
1281
1282
- analysis_ids = [str (_id [0 ]) for _id in conn_handler .execute_fetchall (
1283
- "SELECT DISTINCT analysis_id FROM qiita.analysis_sample WHERE "
1284
- "processed_data_id = {0} ORDER BY "
1285
- "analysis_id " .format (processed_data_id ))]
1282
+ analyses = [str (n [0 ]) for n in conn_handler .execute_fetchall (
1283
+ "SELECT DISTINCT name FROM qiita.analysis JOIN "
1284
+ "qiita.analysis_sample USING (analysis_id) WHERE "
1285
+ "processed_data_id = {0} ORDER BY name " .format (processed_data_id ))]
1286
1286
1287
- if analysis_ids :
1287
+ if analyses :
1288
1288
raise QiitaDBError (
1289
- "Processed data %d is linked to (meta)analyses: %s" %
1290
- (processed_data_id , ", " .join (analysis_ids )))
1289
+ "Processed data %d cannot be removed because it is linked to "
1290
+ "the following (meta)analysis: %s" % (processed_data_id ,
1291
+ ', ' .join (analyses )))
1291
1292
1292
1293
# delete
1293
1294
queue = "delete_processed_data_%d" % processed_data_id
Original file line number Diff line number Diff line change @@ -786,20 +786,28 @@ def test_create(self):
786
786
self .assertEqual (obs , [[1 , 2 ]])
787
787
788
788
def test_delete (self ):
789
- """Correctly deletes a processed data and raises an error if it has
790
- been used in a (meta)analysis or if it's public"""
789
+ """Correctly deletes a processed data"""
790
+ # testing regular delete
791
791
pd = ProcessedData .create (self .params_table , self .params_id ,
792
792
self .filepaths ,
793
793
preprocessed_data = self .preprocessed_data ,
794
794
processed_date = self .date )
795
795
ProcessedData .delete (pd .id )
796
796
797
+ # testing that it raises an error if ID doesn't exist
797
798
with self .assertRaises (QiitaDBUnknownIDError ):
798
799
ProcessedData .delete (pd .id )
799
800
801
+ # testing that we can not remove cause the processed data != sandbox
800
802
with self .assertRaises (QiitaDBStatusError ):
801
803
ProcessedData .delete (1 )
802
804
805
+ # testing that we can not remove cause processed data has analyses
806
+ pd = ProcessedData (1 )
807
+ pd .status = 'sandbox'
808
+ with self .assertRaises (QiitaDBError ):
809
+ ProcessedData .delete (1 )
810
+
803
811
def test_create_no_date (self ):
804
812
"""Correctly adds a processed data with no date on it"""
805
813
# All the other settings have been already tested on test_create
You can’t perform that action at this time.
0 commit comments