Skip to content

Commit

Permalink
Ensure that the submission alias is still unique when a project was m…
Browse files Browse the repository at this point in the history
…anually created using the ELOAD id
  • Loading branch information
tcezard committed Oct 23, 2023
1 parent ee152ce commit 248a233
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 10 additions & 2 deletions eva_submission/ENA_submission/xlsx_to_ENA_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,12 @@ def _add_analysis(self, root, analysis_row, project_row, sample_rows, file_rows)

def _create_submission_xml(self, files_to_submit, action, project_row, eload):
root = Element('SUBMISSION_SET')
if self.is_existing_project:
submission_alias = self.existing_project + '_' + eload
else:
submission_alias = eload
submission_elemt = add_element(root, 'SUBMISSION',
alias=eload,
alias=submission_alias,
center_name=project_row.get('Center'))
actions_elemt = add_element(submission_elemt, 'ACTIONS')
for file_dict in files_to_submit:
Expand All @@ -315,8 +319,12 @@ def _create_submission_xml(self, files_to_submit, action, project_row, eload):

def _create_submission_single_xml(self, action, project_row, eload):
root = Element('SUBMISSION_SET')
if self.is_existing_project:
submission_alias = self.existing_project + '_' + eload
else:
submission_alias = eload
submission_elemt = add_element(root, 'SUBMISSION',
alias=eload,
alias=submission_alias,
center_name=project_row.get('Center'))
actions_elemt = add_element(submission_elemt, 'ACTIONS')
action_elemt = add_element(actions_elemt, 'ACTION')
Expand Down
8 changes: 5 additions & 3 deletions tests/test_xlsx_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from datetime import datetime
from unittest import TestCase
import xml.etree.ElementTree as ET
from unittest.mock import patch, Mock

from unittest.mock import patch, Mock, PropertyMock
from eva_submission import ROOT_DIR
from eva_submission.ENA_submission.xlsx_to_ENA_xml import EnaXlsxConverter

Expand Down Expand Up @@ -250,12 +249,15 @@ def test_create_submission_files(self):

def test_create_submission_files_for_existing_project(self):
# When the project already exist not PROJECT XML will be generated
with patch.object(EnaXlsxConverter, 'is_existing_project', return_value=True):
with patch.object(EnaXlsxConverter, 'existing_project', new_callable=PropertyMock(return_value='PRJEB00001')):
submission_file, project_file, analysis_file = self.converter.create_submission_files('ELOAD_1')
assert os.path.exists(submission_file)
assert project_file is None
assert os.path.exists(analysis_file)
assert not os.path.exists(self.converter.project_file)
with open(submission_file) as open_file:
root = ET.fromstring(open_file.read())
assert list(root)[0].attrib['alias'] == 'PRJEB00001_ELOAD_1'

def test_create_single_submission_files(self):
self.converter.create_single_submission_file('ELOAD_1')
Expand Down

0 comments on commit 248a233

Please sign in to comment.