def test_get_by_name_as_table(self): result = self.cli_runner.invoke(cli, [ 'get', 'deploymentlocation', self.test_case_props['dl_A']['name'], '-e', 'default' ]) table_format = TableFormat(table=DeploymentLocationTable()) expected_output = table_format.convert_element(self._build_deployment_location_output(self.test_case_props['dl_A'])) self.assert_output(result, expected_output)
def test_get_by_name_as_table(self): result = self.cli_runner.invoke(cli, [ 'get', 'descriptor', self.test_case_props['descriptor_A']['name'], '-e', 'default' ]) table_format = TableFormat(table=DescriptorTable()) expected_output = table_format.convert_element(self.test_case_props['descriptor_A']) self.assert_output(result, expected_output)
def test_get_by_name_as_table(self): result = self.cli_runner.invoke(cli, [ 'get', 'infrastructurekey', self.test_case_props['key_A']['name'], '-e', 'default', '--include-private' ]) table_format = TableFormat(table=InfrastructureKeyTable()) expected_output = table_format.convert_element(self.test_case_props['key_A']) self.assert_output(result, expected_output)
def test_get_all_as_table(self): result = self.cli_runner.invoke(cli, ['get', 'env', 'default']) table_format = TableFormat(table=EnvironmentTable()) ctl = get_global_controller() expected_output = table_format.convert_element( ctl.config.environments.get('default', None)) self.assert_output(result, expected_output)
def test_get_by_id_as_table(self): result = self.cli_runner.invoke(cli, [ 'get', 'assemblyconfig', self.test_case_props['assembly_config_A']['id'], '-e', 'default' ]) table_format = TableFormat(table=AssemblyConfigurationTable()) expected_output = table_format.convert_element( self.test_case_props['assembly_config_A']) self.assert_output(result, expected_output)
def test_get_by_name_as_table(self): result = self.cli_runner.invoke(cli, [ 'get', 'behaviourproject', self.test_case_props['project_A']['id'], '-e', 'default' ]) table_format = TableFormat(table=ProjectTable()) expected_output = table_format.convert_element( self.test_case_props['project_A']) self.assert_output(result, expected_output)
def test_get_by_type(self): result = self.cli_runner.invoke(cli, [ 'get', 'resourcedriver', '-e', 'default', '--type', self.test_case_props['driver_B']['type'] ]) table_format = TableFormat(table=ResourceDriverTable()) expected_output = table_format.convert_element( self.test_case_props['driver_B']) self.assert_output(result, expected_output)
def test_get_by_id_as_table(self): result = self.cli_runner.invoke(cli, [ 'get', 'scenario', self.test_case_props['scenario_A']['id'], '-e', 'default' ]) table_format = TableFormat(table=ScenarioTable()) expected_output = table_format.convert_element( self.test_case_props['scenario_A']) self.assert_output(result, expected_output)
def test_query(self): assembly_name = self.tester.exec_prepended_name('process-cmd-query') process_id, assembly_id = self._create_assembly(assembly_name) result = self.cli_runner.invoke(cli, [ 'get', 'process', '-e', 'default', '--assembly-name', assembly_name ]) table_format = TableFormat(table=ProcessTable()) target_process = self.tester.default_client.processes.get(process_id) expected_output = table_format.convert_element(target_process) self.assert_output(result, expected_output) self.tester.wait_until(self._build_check_process_success(self.tester), process_id) self._delete_and_wait(assembly_name)
def test_ping(self): result = self.cli_runner.invoke(cli, ['ping', 'env', 'default']) self.assert_no_errors(result) ctl = get_global_controller() expected_results = TestResults(tests=[ TestResult('Descriptors', error=None), TestResult('Topology', error=None), TestResult('Behaviour', error=None), TestResult('Resource Manager', error=None) ]) table_format = TableFormat(table=PingTable()) address = ctl.config.environments.get('default').tnco.address expected_output = f'Pinging CP4NA orchestration: {address}' expected_output += '\n' expected_output += table_format.convert_list(expected_results.tests) expected_output += '\nCP4NA orchestration tests passed! ✅' self.assert_output(result, expected_output)
def test_ping_with_failure(self, mock_descriptors_api): mock_error = TNCOClientError('Mock error') mock_descriptors_api.return_value.all.side_effect = mock_error ctl = get_global_controller() result = self.cli_runner.invoke(cli, ['ping', 'env', 'default']) self.assert_has_system_exit(result) ctl = get_global_controller() expected_results = TestResults(tests=[ TestResult('Descriptors', error='Mock error'), TestResult('Topology', error=None), TestResult('Behaviour', error=None), TestResult('Resource Manager', error=None) ]) table_format = TableFormat(table=PingTable()) address = ctl.config.environments.get('default').tnco.address expected_output = f'Pinging CP4NA orchestration: {address}' expected_output += '\n' expected_output += table_format.convert_list(expected_results.tests) expected_output += '\nCP4NA orchestration tests failed! ❌' self.assert_output(result, expected_output)
def test_convert_list(self): test_list = [{ 'name': 'A', 'status': 'Good' }, { 'name': 'B', 'status': 'Bad' }, { 'name': 'C', 'status': 'Excellent' }, { 'name': 'D' }] output = TableFormat(table=DummyTable()).convert_list(test_list) self.assertEqual(output, EXPECTED_LIST)
def _ping(ctx: click.Context, name: str = None, pwd: str = None, client_secret: str = None, include_template_engine: bool = False): ctl = self._get_controller() env = ctl.get_environment_group(name) happy_exit = True if env.has_tnco: tnco_client = ctl.get_tnco_client(environment_group_name=name, input_pwd=pwd, input_client_secret=client_secret) ctl.io.print(f'Pinging CP4NA orchestration: {env.tnco.address}') tnco_ping_result = tnco_client.ping(include_template_engine=include_template_engine) ctl.io.print(TableFormat(table=PingTable()).convert_list(tnco_ping_result.tests)) if tnco_ping_result.passed: ctl.io.print(f'CP4NA orchestration tests passed! ✅') else: ctl.io.print_error(f'CP4NA orchestration tests failed! ❌') happy_exit = False else: ctl.io.print('No CP4NA orchestration configured (skipping)') if not happy_exit: exit(1)
def test_table_with_columns_with_no_headers(self): element = {'name': 'A', 'status': 'Good'} output = TableFormat(table=DummyTable()).convert_element(element) self.assertEqual(output, EXPECTED_ELEMENT)
def common_output_format_handler(table: Table): return output_format_handler()\ .add_choice(TABLE_VALUE, TableFormat(table=table), is_default=True)\ .add_choice(YAML_VALUE, YamlFormat())\ .add_choice(JSON_VALUE, JsonFormat())