def test_delete_job(self, mock_print, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) commands.delete_job(job_id=3) self.assertFalse(mock_bespin_api.return_value.authorize_job.called) mock_bespin_api.return_value.delete_job.assert_called_with(3) mock_print.assert_has_calls([call("Deleted job 3")])
def test_workflow_create(self, mock_print, mock_bespin_api, mock_config_file): mock_bespin_api.return_value.workflow_post.return_value = {'id': 4} commands = Commands(self.version_str, self.user_agent_str) commands.workflow_create(name='myname', tag='mytag') mock_bespin_api.return_value.workflow_post.assert_called_with( 'myname', 'mytag') mock_print.assert_has_calls([call("Created workflow 4.")])
def test_start_job_no_token(self, mock_print, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) commands.start_job(job_id=1) self.assertFalse(mock_bespin_api.return_value.authorize_job.called) mock_bespin_api.return_value.start_job.assert_called_with(1) mock_print.assert_has_calls([call("Started job 1")])
def test_workflow_version_validate_raises_without_path(self): commands = Commands(self.version_str, self.user_agent_str) with self.assertRaises(UserInputException) as context: commands.workflow_version_validate(url='someurl', workflow_type='not-direct', workflow_path=None, expected_tag='workflow-tag', expected_version='v1.2.3') self.assertIn('path is required', str(context.exception))
def test_jobs_list(self, mock_print, mock_table, mock_jobs_list, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) commands.jobs_list() mock_jobs_list.assert_called_with(mock_bespin_api.return_value) mock_table.assert_called_with( mock_jobs_list.return_value.column_names, mock_jobs_list.return_value.get_column_data.return_value) mock_print.assert_called_with(mock_table.return_value)
def test_workflow_version_validate_direct_raises_if_path(self): commands = Commands(self.version_str, self.user_agent_str) with self.assertRaises(UserInputException) as context: commands.workflow_version_validate( url='someurl', workflow_type='direct', workflow_path='extracted/workflow.cwl', expected_tag='workflow-tag', expected_version='v1.2.3') self.assertIn('Do not provide path', str(context.exception))
def test_start_job_with_token(self, mock_print, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) commands.start_job(job_id=1, token='secret') mock_bespin_api.return_value.authorize_job.assert_called_with( 1, 'secret') mock_bespin_api.return_value.start_job.assert_called_with(1) mock_print.assert_has_calls( [call('Set run token for job 1'), call('Started job 1')])
def test_job_validate_exception(self, mock_print, mock_job_template_loader, mock_bespin_api, mock_config_file): mock_infile = Mock() mock_job_template = mock_job_template_loader.return_value.create_job_template.return_value mock_job_template.validate.side_effect = UserInputException("Bad data") commands = Commands(self.version_str, self.user_agent_str) with self.assertRaises(UserInputException): commands.job_validate(job_template_infile=mock_infile) mock_print.assert_called_with('ERROR: Job template is invalid.')
def main(): version_str = pkg_resources.get_distribution(APP_NAME).version user_agent_str = '{}_{}'.format(APP_NAME, version_str) arg_parser = ArgParser(version_str, Commands(version_str, user_agent_str)) try: arg_parser.parse_and_run_commands() except ConfigSetupAbandoned: pass except UserInputException as e: print(str(e)) sys.exit(1)
def test_job_template_create(self, mock_print, mock_bespin_api, mock_config_file): mock_outfile = Mock() mock_bespin_api.return_value.job_templates_init.return_value = {} commands = Commands(self.version_str, self.user_agent_str) commands.job_template_create(tag='rnaseq/v1/human', outfile=mock_outfile) mock_bespin_api.return_value.job_templates_init.assert_called_with( 'rnaseq/v1/human') mock_outfile.write.assert_called_with('{}\n')
def test_workflow_versions_list(self, mock_print, mock_table, mock_workflow_versions_list, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) commands.workflow_versions_list(workflow_tag='sometag') mock_workflow_versions_list.assert_called_with( mock_bespin_api.return_value, 'sometag') mock_table.assert_called_with( mock_workflow_versions_list.return_value.column_names, mock_workflow_versions_list.return_value.get_column_data. return_value) mock_print.assert_called_with(mock_table.return_value)
def test_job_validate(self, mock_print, mock_job_template_loader, mock_bespin_api, mock_config_file): mock_infile = Mock() commands = Commands(self.version_str, self.user_agent_str) commands.job_validate(job_template_infile=mock_infile) mock_job_template_loader.assert_called_with(mock_infile) mock_job_template = mock_job_template_loader.return_value.create_job_template.return_value mock_job_template.validate.assert_called_with( mock_bespin_api.return_value) mock_print.assert_called_with('Job file is valid.')
def test_workflows_list_all_versions(self, mock_print, mock_table, mock_workflow_details, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) commands.workflows_list(all_versions=True, short_format=False, tag=None) workflow_details = mock_workflow_details.return_value mock_table.assert_called_with( workflow_details.column_names, workflow_details.get_column_data.return_value) mock_print.assert_called_with(mock_table.return_value) mock_workflow_details.assert_called_with(mock_bespin_api.return_value, True, None)
def test_workflow_config_show_job_order(self, mock_print, mock_bespin_api, mock_config_file): mock_outfile = Mock() mock_bespin_api.return_value.workflow_configurations_list.return_value = [ { "system_job_order": { "threads": 2 } } ] commands = Commands(self.version_str, self.user_agent_str) commands.workflow_config_show_job_order(tag="human", workflow_tag="exomeseq", outfile=mock_outfile) mock_outfile.write.assert_called_with('threads: 2\n')
def test_workflow_version_validate(self, mock_cwl_workflow_version, mock_print): commands = Commands(self.version_str, self.user_agent_str) mock_cwl_workflow_version.return_value.validate_workflow.return_value = Mock( tag='workflow-tag', version='v1.2.3') commands.workflow_version_validate( url='someurl', workflow_type='zipped', workflow_path='extracted/workflow.cwl', expected_tag='workflow-tag', expected_version='v1.2.3') mock_cwl_workflow_version.assert_called_with('someurl', 'zipped', 'extracted/workflow.cwl', validate=True) mock_print.assert_has_calls( [call("Validated someurl as 'workflow-tag/v1.2.3'")])
def test_job_create(self, mock_print, mock_job_template_loader, mock_bespin_api, mock_config_file): mock_infile = Mock() mock_job_template_loader.return_value.create_job_template.return_value.create_job.return_value = { 'job': 1 } commands = Commands(self.version_str, self.user_agent_str) commands.job_create(job_template_infile=mock_infile) mock_job_template_loader.assert_called_with(mock_infile) mock_print.assert_has_calls([ call("Created job 1"), call("To start this job run `bespin job start 1` .") ]) mock_job_template = mock_job_template_loader.return_value.create_job_template.return_value mock_job_template.create_job.assert_called_with( mock_bespin_api.return_value)
def test_job_run(self, mock_print, mock_job_template_loader, mock_bespin_api, mock_config_file): mock_infile = Mock() mock_job_template_loader.return_value.create_job_template.return_value.create_job.return_value = { 'job': 1 } commands = Commands(self.version_str, self.user_agent_str) commands.job_run(job_template_infile=mock_infile, token='mytoken') mock_job_template_loader.assert_called_with(mock_infile) mock_print.assert_has_calls([ call("Created job 1"), call("Set run token for job 1"), call("Started job 1") ]) mock_job_template = mock_job_template_loader.return_value.create_job_template.return_value mock_job_template.create_job.assert_called_with( mock_bespin_api.return_value)
def test_workflow_version_create(self, mock_cwl_workflow_version, mock_print, mock_bespin_api, mock_config_file): mock_cwl_workflow_version.return_value.create.return_value = {'id': 7} commands = Commands(self.version_str, self.user_agent_str) commands.workflow_version_create(url='someurl', workflow_type='packed', workflow_path='#main', version_info_url='infourl', override_version='v3.2', override_tag='tag', validate=True) mock_cwl_workflow_version.assert_called_with('someurl', 'packed', '#main', 'infourl', override_tag='tag', override_version='v3.2', validate=True) mock_print.assert_has_calls([call("Created workflow version 7.")])
def test_workflow_version_tool_details_preview(self, mock_tool_details, mock_cwl_workflow_version, mock_json, mock_print): commands = Commands(self.version_str, self.user_agent_str) mock_cwl_workflow_version.return_value.validate_workflow.return_value = Mock( tag='workflow-tag', version='v1.2.3') commands.workflow_version_tool_details_preview( url='someurl', workflow_type='zipped', workflow_path='extracted/workflow.cwl') mock_cwl_workflow_version.assert_called_with('someurl', 'zipped', 'extracted/workflow.cwl', override_tag=None, override_version=None, validate=False) mock_tool_details.assert_called_with( mock_cwl_workflow_version.return_value) mock_json.dumps.assert_called_with( mock_tool_details.return_value.contents, indent=2) mock_print.assert_called_with(mock_json.dumps.return_value)
def test_workflow_version_tool_details_create(self, mock_tool_details, mock_cwl_workflow_version, mock_print, mock_bespin_api, mock_config_file): commands = Commands(self.version_str, self.user_agent_str) mock_create = mock_tool_details.return_value.create mock_create.return_value = {'id': '5'} commands.workflow_version_tool_details_create( url='someurl', workflow_type='zipped', workflow_path='extracted/workflow.cwl', override_tag='tagg', override_version='v1') mock_cwl_workflow_version.assert_called_with('someurl', 'zipped', 'extracted/workflow.cwl', override_tag='tagg', override_version='v1', validate=False) mock_create.assert_called_with(mock_bespin_api.return_value) mock_print.assert_called_with( "Created workflow version tool details 5.")
def test_workflow_config_create(self, mock_yaml, mock_print, mock_bespin_api, mock_config_file): mock_yaml.load.return_value = {'a': 1} mock_bespin_api.return_value.workflow_get_for_tag.return_value = { 'id': 2 } mock_bespin_api.return_value.job_strategy_get_for_name.return_value = { 'id': 3 } mock_bespin_api.return_value.share_group_get_for_name.return_value = { 'id': 4 } mock_bespin_api.return_value.workflow_configurations_post.return_value = { 'id': 5 } commands = Commands(self.version_str, self.user_agent_str) commands.workflow_config_create(workflow_tag='exome', default_job_strategy_name='default', share_group_name='myname', tag='human', joborder_infile=Mock()) mock_bespin_api.return_value.workflow_configurations_post.assert_called_with( 'human', 2, 3, 4, {'a': 1}) mock_print.assert_called_with("Created workflow config 5.")