Skip to content

Commit c195dad

Browse files
committed
addressing new comments from @josenavas @squirrelo
1 parent 99f196f commit c195dad

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

qiita_db/data.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,26 +1268,27 @@ def delete(cls, processed_data_id):
12681268
12691269
Raises
12701270
------
1271-
QiitaDBUnknownIDError
1272-
If the processed data id doesn't exist
12731271
QiitaDBStatusError
12741272
If the processed data status is not sandbox
1273+
QiitaDBError
1274+
If the processed data has (meta)analyses
12751275
"""
12761276
if cls(processed_data_id).status != 'sandbox':
12771277
raise QiitaDBStatusError(
12781278
"Illegal operation on non sandbox processed data")
12791279

12801280
conn_handler = SQLConnectionHandler()
12811281

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))]
12861286

1287-
if analysis_ids:
1287+
if analyses:
12881288
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)))
12911292

12921293
# delete
12931294
queue = "delete_processed_data_%d" % processed_data_id

qiita_db/test/test_data.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,20 +786,28 @@ def test_create(self):
786786
self.assertEqual(obs, [[1, 2]])
787787

788788
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
791791
pd = ProcessedData.create(self.params_table, self.params_id,
792792
self.filepaths,
793793
preprocessed_data=self.preprocessed_data,
794794
processed_date=self.date)
795795
ProcessedData.delete(pd.id)
796796

797+
# testing that it raises an error if ID doesn't exist
797798
with self.assertRaises(QiitaDBUnknownIDError):
798799
ProcessedData.delete(pd.id)
799800

801+
# testing that we can not remove cause the processed data != sandbox
800802
with self.assertRaises(QiitaDBStatusError):
801803
ProcessedData.delete(1)
802804

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+
803811
def test_create_no_date(self):
804812
"""Correctly adds a processed data with no date on it"""
805813
# All the other settings have been already tested on test_create

0 commit comments

Comments
 (0)