diff --git a/testit-adapter-behave/setup.py b/testit-adapter-behave/setup.py index 88c59b0..18b7951 100644 --- a/testit-adapter-behave/setup.py +++ b/testit-adapter-behave/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.0.0" +VERSION = "4.1.0" setup( name='testit-adapter-behave', diff --git a/testit-adapter-behave/src/testit_adapter_behave/listener.py b/testit-adapter-behave/src/testit_adapter_behave/listener.py index 6f16a17..ed5a342 100644 --- a/testit-adapter-behave/src/testit_adapter_behave/listener.py +++ b/testit-adapter-behave/src/testit_adapter_behave/listener.py @@ -7,7 +7,8 @@ from .models.test_result_step import get_test_result_step_model from .scenario_parser import ( parse_scenario, - parse_status) + parse_step_status, + parse_status_type) from .utils import ( convert_step_to_step_result_model, convert_executable_test_to_test_result_model) @@ -77,7 +78,7 @@ def get_step_result(self, result): logging.debug("get_step_result") self.__adapter_manager.on_running_started() scope = self.get_scope() - outcome = parse_status(result.status) + outcome = parse_step_status(result.status) self.__executable_test[scope][-1]['title'] = result.name self.__executable_test[scope][-1]['outcome'] = outcome @@ -96,7 +97,8 @@ def get_step_result(self, result): if outcome != OutcomeType.PASSED: self.__executable_test['traces'] = result.error_message - self.__executable_test['outcome'] = outcome + self.__executable_test['outcome'] = result.status + self.__executable_test['status_type'] = parse_status_type(result.status) self.set_scenario() return @@ -107,7 +109,8 @@ def get_step_result(self, result): self.__steps_count -= 1 if self.__steps_count == 0: - self.__executable_test['outcome'] = outcome + self.__executable_test['outcome'] = result.status + self.__executable_test['status_type'] = parse_status_type(result.status) self.set_scenario() def get_scope(self): diff --git a/testit-adapter-behave/src/testit_adapter_behave/scenario_parser.py b/testit-adapter-behave/src/testit_adapter_behave/scenario_parser.py index 932ba14..5c2fcee 100644 --- a/testit-adapter-behave/src/testit_adapter_behave/scenario_parser.py +++ b/testit-adapter-behave/src/testit_adapter_behave/scenario_parser.py @@ -2,11 +2,20 @@ from enum import Enum from testit_python_commons.models.outcome_type import OutcomeType +from testit_python_commons.models.status_type import StatusType from .models.tags import TagType from .tags_parser import parse_test_tags -STATUS = { +STATUS_TYPE = { + 'passed': StatusType.SUCCEEDED, + 'failed': StatusType.FAILED, + 'error': StatusType.FAILED, + 'skipped': StatusType.INCOMPLETE, + 'untested': StatusType.INCOMPLETE, + 'undefined': StatusType.INCOMPLETE +} +STEP_STATUS = { 'passed': OutcomeType.PASSED, 'failed': OutcomeType.FAILED, 'error': OutcomeType.FAILED, @@ -26,6 +35,7 @@ def parse_scenario(scenario): 'autoTestName': tags[TagType.DISPLAY_NAME] if TagType.DISPLAY_NAME in tags and tags[TagType.DISPLAY_NAME] else get_scenario_name(scenario), 'outcome': None, + 'status_type': None, 'steps': [], 'stepResults': [], 'setUp': [], @@ -82,8 +92,12 @@ def parse_scenario(scenario): return executable_test -def parse_status(status): - return STATUS[status.name] +def parse_step_status(status): + return STEP_STATUS[status.name] + + +def parse_status_type(status): + return STATUS_TYPE[status.name] def get_scenario_name(scenario): @@ -124,9 +138,9 @@ def get_step_status(result): return get_status(result.exception) else: if isinstance(result.status, Enum): - return STATUS.get(result.status.name, None) + return STEP_STATUS.get(result.status.name, None) else: - return STATUS.get(result.status, None) + return STEP_STATUS.get(result.status, None) def get_status(exception): diff --git a/testit-adapter-behave/src/testit_adapter_behave/utils.py b/testit-adapter-behave/src/testit_adapter_behave/utils.py index a077326..6642b18 100644 --- a/testit-adapter-behave/src/testit_adapter_behave/utils.py +++ b/testit-adapter-behave/src/testit_adapter_behave/utils.py @@ -132,6 +132,7 @@ def convert_executable_test_to_test_result_model(executable_test: dict) -> TestR .set_teardown_results(executable_test['tearDownResults'])\ .set_duration(executable_test['duration'])\ .set_outcome(executable_test['outcome'])\ + .set_status_type(executable_test['status_type'])\ .set_traces(executable_test['traces'])\ .set_attachments(executable_test['attachments'])\ .set_parameters(executable_test['parameters'])\ @@ -141,7 +142,7 @@ def convert_executable_test_to_test_result_model(executable_test: dict) -> TestR .set_title(executable_test['title'])\ .set_description(executable_test['description'])\ .set_links(executable_test['links'])\ - .set_result_links(executable_test['resultLinks']) \ + .set_result_links(executable_test['resultLinks'])\ .set_labels(executable_test['labels']) \ .set_tags(executable_test['tags'])\ .set_work_item_ids(executable_test['workItemsID'])\ diff --git a/testit-adapter-nose/setup.py b/testit-adapter-nose/setup.py index a373c90..081485e 100644 --- a/testit-adapter-nose/setup.py +++ b/testit-adapter-nose/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -VERSION = "4.0.0" +VERSION = "4.1.0" setup( name='testit-adapter-nose', diff --git a/testit-adapter-nose/src/testit_adapter_nose/listener.py b/testit-adapter-nose/src/testit_adapter_nose/listener.py index 2b13248..2e81acb 100644 --- a/testit-adapter-nose/src/testit_adapter_nose/listener.py +++ b/testit-adapter-nose/src/testit_adapter_nose/listener.py @@ -5,7 +5,8 @@ from .utils import ( form_test, get_outcome, - convert_executable_test_to_test_result_model + convert_executable_test_to_test_result_model, + STATUS_TYPE, ) @@ -38,6 +39,7 @@ def set_outcome(self, event): outcome, message, trace = get_outcome(event) self.__executable_test['outcome'] = outcome + self.__executable_test['status_type'] = STATUS_TYPE[outcome] self.__executable_test['traces'] = trace if not self.__executable_test['message']: diff --git a/testit-adapter-nose/src/testit_adapter_nose/utils.py b/testit-adapter-nose/src/testit_adapter_nose/utils.py index cf77d16..b9fbfc9 100644 --- a/testit-adapter-nose/src/testit_adapter_nose/utils.py +++ b/testit-adapter-nose/src/testit_adapter_nose/utils.py @@ -12,11 +12,16 @@ from testit_python_commons.models.link import Link from testit_python_commons.models.test_result import TestResult -from testit_python_commons.models.outcome_type import OutcomeType +from testit_python_commons.models.status_type import StatusType __ARRAY_TYPES = (frozenset, list, set, tuple,) - +STATUS_TYPE = { + result.PASS: StatusType.SUCCEEDED, + result.FAIL: StatusType.FAILED, + result.ERROR: StatusType.FAILED, + result.SKIP: StatusType.INCOMPLETE, +} def status_details(event): message, trace = None, None @@ -31,23 +36,17 @@ def status_details(event): def get_outcome(event): - outcome = None + outcome = event.outcome message = None trace = None - if event.outcome == result.PASS and event.expected: - outcome = OutcomeType.PASSED - elif event.outcome == result.PASS and not event.expected: - outcome = OutcomeType.PASSED + if outcome == result.PASS and not event.expected: message = "test passes unexpectedly" - elif event.outcome == result.FAIL and not event.expected: - outcome = OutcomeType.FAILED + elif outcome == result.FAIL and not event.expected: message, trace = status_details(event) - elif event.outcome == result.ERROR: - outcome = OutcomeType.BLOCKED + elif outcome == result.ERROR: message, trace = status_details(event) - elif event.outcome == result.SKIP: - outcome = OutcomeType.SKIPPED + elif outcome == result.SKIP: message, trace = status_details(event) return outcome, message, trace @@ -73,6 +72,7 @@ def form_test(item, top_level_directory): 'resultLinks': [], 'duration': 0, 'outcome': None, + 'status_type': None, 'failureReasonName': None, 'traces': None, 'attachments': [], @@ -387,6 +387,7 @@ def convert_executable_test_to_test_result_model(executable_test: dict) -> TestR .set_teardown_results(executable_test['tearDownResults'])\ .set_duration(executable_test['duration'])\ .set_outcome(executable_test['outcome'])\ + .set_status_type(executable_test['status_type'])\ .set_traces(executable_test['traces'])\ .set_attachments(executable_test['attachments'])\ .set_parameters(executable_test['parameters'])\ @@ -396,8 +397,8 @@ def convert_executable_test_to_test_result_model(executable_test: dict) -> TestR .set_title(executable_test['title'])\ .set_description(executable_test['description'])\ .set_links(executable_test['links'])\ - .set_result_links(executable_test['resultLinks']) \ - .set_labels(executable_test['labels']) \ + .set_result_links(executable_test['resultLinks'])\ + .set_labels(executable_test['labels'])\ .set_tags(executable_test['tags'])\ .set_work_item_ids(executable_test['workItemsID'])\ .set_message(executable_test['message'])\ diff --git a/testit-adapter-pytest/setup.py b/testit-adapter-pytest/setup.py index b18e744..c70f3c6 100644 --- a/testit-adapter-pytest/setup.py +++ b/testit-adapter-pytest/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.0.0" +VERSION = "4.1.0" setup( name='testit-adapter-pytest', diff --git a/testit-adapter-pytest/src/testit_adapter_pytest/listener.py b/testit-adapter-pytest/src/testit_adapter_pytest/listener.py index 11165c0..661fb23 100644 --- a/testit-adapter-pytest/src/testit_adapter_pytest/listener.py +++ b/testit-adapter-pytest/src/testit_adapter_pytest/listener.py @@ -8,6 +8,7 @@ import testit_python_commons.services as adapter from testit_python_commons.models.outcome_type import OutcomeType +from testit_python_commons.models.status_type import StatusType from testit_python_commons.models.fixture import FixtureResult, FixturesContainer from testit_python_commons.services import AdapterManager, StepManager, FixtureManager from testit_python_commons.services.logger import adapter_logger @@ -15,10 +16,17 @@ import testit_adapter_pytest.utils as utils from testit_adapter_pytest.fixture_context import FixtureContext -STATUS = { + +STATUS_TYPE = { + 'passed': StatusType.SUCCEEDED, + 'failed': StatusType.FAILED, + 'xfailed': StatusType.FAILED, + 'skipped': StatusType.INCOMPLETE, +} +STEP_STATUS = { 'passed': OutcomeType.PASSED, 'failed': OutcomeType.FAILED, - 'skipped': OutcomeType.SKIPPED + 'skipped': OutcomeType.SKIPPED, } @@ -233,16 +241,25 @@ def pytest_fixture_post_finalizer(self, fixturedef): def pytest_runtest_logreport(self, report): if self.__executable_test: if report.when == 'setup': - self.__executable_test.outcome = STATUS.get(report.outcome, None) + self.__executable_test.outcome = report.outcome + self.__executable_test.status_type = STATUS_TYPE.get(report.outcome, None) if report.longreprtext: self.__executable_test.message = report.longreprtext if report.when == 'call': - self.__executable_test.outcome = STATUS.get(report.outcome, None) + self.__executable_test.outcome = report.outcome + self.__executable_test.status_type = STATUS_TYPE.get(report.outcome, None) + + if report.failed or report.outcome == 'rerun': + self.__executable_test.outcome = 'failed' + self.__executable_test.status_type = STATUS_TYPE.get('failed', None) + + if report.longreprtext: + self.__executable_test.traces = report.longreprtext - if report.failed or hasattr(report, 'wasxfail') \ - and not report.passed or report.outcome == 'rerun': - self.__executable_test.outcome = STATUS.get('failed', None) + if hasattr(report, 'wasxfail') and not report.passed: + self.__executable_test.outcome = 'xfailed' + self.__executable_test.status_type = STATUS_TYPE.get('xfailed', None) if report.longreprtext: self.__executable_test.traces = report.longreprtext diff --git a/testit-adapter-pytest/src/testit_adapter_pytest/models/executable_test.py b/testit-adapter-pytest/src/testit_adapter_pytest/models/executable_test.py index a0d4109..6647599 100644 --- a/testit-adapter-pytest/src/testit_adapter_pytest/models/executable_test.py +++ b/testit-adapter-pytest/src/testit_adapter_pytest/models/executable_test.py @@ -15,6 +15,7 @@ class ExecutableTest: result_links = attrib(default=Factory(list)) duration = attrib(default=None) outcome = attrib(default=None) + status_type = attrib(default=None) failure_reason_names = attrib(default=Factory(list)) traces = attrib(default=None) attachments = attrib(default=Factory(list)) diff --git a/testit-adapter-pytest/src/testit_adapter_pytest/utils.py b/testit-adapter-pytest/src/testit_adapter_pytest/utils.py index db5a319..a93a979 100644 --- a/testit-adapter-pytest/src/testit_adapter_pytest/utils.py +++ b/testit-adapter-pytest/src/testit_adapter_pytest/utils.py @@ -12,6 +12,7 @@ from testit_python_commons.models.link import Link from testit_python_commons.models.test_result import TestResult from testit_python_commons.models.test_result_with_all_fixture_step_results_model import TestResultWithAllFixtureStepResults +from testit_python_commons.models.outcome_type import OutcomeType from testit_adapter_pytest.models.executable_test import ExecutableTest @@ -47,6 +48,8 @@ def __set_outcome_and_message_from_markers(executable_test: ExecutableTest, mark for marker in markers: if marker.name in ('skip', 'skipif'): executable_test.outcome = 'Skipped' + if marker.name == 'xfail': + executable_test.outcome = 'Xfailed' if marker.name in ('skip', 'skipif', 'xfail'): if len(marker.args) == 1 and isinstance(marker.args, str): executable_test.message = marker.args[0] @@ -337,6 +340,7 @@ def convert_executable_test_to_test_result_model(executable_test: ExecutableTest .set_teardown_results(executable_test.teardown_step_results)\ .set_duration(executable_test.duration)\ .set_outcome(executable_test.outcome)\ + .set_status_type(executable_test.status_type)\ .set_traces(executable_test.traces)\ .set_attachments(executable_test.attachments)\ .set_parameters(executable_test.parameters)\ @@ -404,10 +408,10 @@ def fixtures_containers_to_test_results_with_all_fixture_step_results( def get_status(exception): if exception: if isinstance(exception, pytest.skip.Exception): - return "Skipped" - return "Failed" + return OutcomeType.SKIPPED + return OutcomeType.FAILED else: - return "Passed" + return OutcomeType.PASSED def get_outcome_status(outcome): diff --git a/testit-adapter-robotframework/setup.py b/testit-adapter-robotframework/setup.py index c51fead..308089d 100644 --- a/testit-adapter-robotframework/setup.py +++ b/testit-adapter-robotframework/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.0.0" +VERSION = "4.1.0" setup( name='testit-adapter-robotframework', diff --git a/testit-adapter-robotframework/src/testit_adapter_robotframework/listeners.py b/testit-adapter-robotframework/src/testit_adapter_robotframework/listeners.py index 06acac4..02f11d7 100644 --- a/testit-adapter-robotframework/src/testit_adapter_robotframework/listeners.py +++ b/testit-adapter-robotframework/src/testit_adapter_robotframework/listeners.py @@ -4,7 +4,7 @@ from robot.libraries.BuiltIn import BuiltIn from .models import Autotest -from .utils import STATUSES, convert_time, convert_executable_test_to_test_result_model, get_hash +from .utils import STEP_STATUSES, STATUS_TYPES, convert_time, convert_executable_test_to_test_result_model, get_hash class AutotestAdapter: @@ -54,13 +54,14 @@ def end_keyword(self, name, attributes): start = convert_time(attributes['starttime']) end = convert_time(attributes['endtime']) duration = attributes['elapsedtime'] - outcome = STATUSES[attributes['status']] + outcome = STEP_STATUSES[attributes['status']] self.active_test.add_step_result(title, start, end, duration, outcome, self.active_test.attachments) self.active_test.attachments = [] def end_test(self, name, attributes): if self.active_test: - self.active_test.outcome = STATUSES[attributes['status']] + self.active_test.outcome = attributes['status'] + self.active_test.status_type = STATUS_TYPES[attributes['status']] self.active_test.started_on = convert_time(attributes['starttime']) self.active_test.completed_on = convert_time(attributes['endtime']) if not self.active_test.message and self.active_test.outcome == 'Failed': diff --git a/testit-adapter-robotframework/src/testit_adapter_robotframework/models.py b/testit-adapter-robotframework/src/testit_adapter_robotframework/models.py index 7d79dce..192b1eb 100644 --- a/testit-adapter-robotframework/src/testit_adapter_robotframework/models.py +++ b/testit-adapter-robotframework/src/testit_adapter_robotframework/models.py @@ -74,6 +74,7 @@ class Autotest(Default): failureReasonNames = attrib(default=Factory(list)) # noqa: N815 traces = attrib(default=None) outcome = attrib(default=None) + status_type = attrib(default=None) namespace = attrib(default=None) attachments = attrib(default=Factory(list)) parameters = attrib(default=Factory(dict)) diff --git a/testit-adapter-robotframework/src/testit_adapter_robotframework/utils.py b/testit-adapter-robotframework/src/testit_adapter_robotframework/utils.py index 1409570..ce9f7ed 100644 --- a/testit-adapter-robotframework/src/testit_adapter_robotframework/utils.py +++ b/testit-adapter-robotframework/src/testit_adapter_robotframework/utils.py @@ -4,6 +4,8 @@ from testit_python_commons.models.step_result import StepResult from testit_python_commons.models.test_result import TestResult +from testit_python_commons.models.outcome_type import OutcomeType +from testit_python_commons.models.status_type import StatusType def convert_time(time): @@ -24,6 +26,7 @@ def convert_executable_test_to_test_result_model(executable_test: dict) -> TestR step_results_to_autotest_steps_model(executable_test['tearDownResults']))\ .set_duration(executable_test['duration'])\ .set_outcome(executable_test['outcome'])\ + .set_status_type(executable_test['status_type'])\ .set_traces(executable_test['traces'])\ .set_attachments(executable_test['attachments'])\ .set_parameters(executable_test['parameters'])\ @@ -33,7 +36,7 @@ def convert_executable_test_to_test_result_model(executable_test: dict) -> TestR .set_title(executable_test['title'])\ .set_description(executable_test['description'])\ .set_links(executable_test['links'])\ - .set_result_links(executable_test['resultLinks']) \ + .set_result_links(executable_test['resultLinks'])\ .set_labels(executable_test['labels']) \ .set_tags(executable_test['tags'])\ .set_work_item_ids(executable_test['workItemsID'])\ @@ -69,4 +72,15 @@ def get_hash(value: str): return md.hexdigest() -STATUSES = {'FAIL': 'Failed', 'PASS': 'Passed', 'SKIP': 'Skipped', 'NOT RUN': 'Skipped'} +STEP_STATUSES = { + 'FAIL': OutcomeType.FAILED, + 'PASS': OutcomeType.PASSED, + 'SKIP': OutcomeType.SKIPPED, + 'NOT RUN': OutcomeType.SKIPPED +} +STATUS_TYPES = { + 'FAIL': StatusType.FAILED, + 'PASS': StatusType.SUCCEEDED, + 'SKIP': StatusType.INCOMPLETE, + 'NOT RUN': StatusType.INCOMPLETE +} diff --git a/testit-python-commons/setup.py b/testit-python-commons/setup.py index 4d422e9..62ef63f 100644 --- a/testit-python-commons/setup.py +++ b/testit-python-commons/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = "4.0.0" +VERSION = "4.1.0" setup( name='testit-python-commons', @@ -25,5 +25,5 @@ py_modules=['testit', 'testit_python_commons'], packages=find_packages(where='src'), package_dir={'': 'src'}, - install_requires=['pluggy', 'tomli', 'testit-api-client==7.5.3'] + install_requires=['pluggy', 'tomli', 'testit-api-client==7.5.4'] ) diff --git a/testit-python-commons/src/testit_python_commons/client/api_client.py b/testit-python-commons/src/testit_python_commons/client/api_client.py index 5c2958c..a10e6c9 100644 --- a/testit-python-commons/src/testit_python_commons/client/api_client.py +++ b/testit-python-commons/src/testit_python_commons/client/api_client.py @@ -3,7 +3,15 @@ from datetime import datetime from testit_api_client import ApiClient, Configuration -from testit_api_client.apis import AttachmentsApi, AutoTestsApi, TestRunsApi, TestResultsApi, WorkItemsApi +from testit_api_client.apis import ( + AttachmentsApi, + AutoTestsApi, + TestRunsApi, + TestResultsApi, + WorkItemsApi, + ProjectsApi, + WorkflowsApi, +) from testit_api_client.models import ( ApiV2TestResultsSearchPostRequest, AutoTestApiResult, @@ -15,6 +23,8 @@ TestRunV2ApiResult, LinkAutoTestToWorkItemRequest, AutoTestWorkItemIdentifierApiResult, + ProjectModel, + WorkflowApiResult, ) from testit_python_commons.client.client_configuration import ClientConfiguration @@ -41,7 +51,10 @@ def __init__(self, config: ClientConfiguration): self.__attachments_api = AttachmentsApi(api_client=api_client) self.__test_results_api = TestResultsApi(api_client=api_client) self.__work_items_api = WorkItemsApi(api_client=api_client) + self.__projects_api = ProjectsApi(api_client=api_client) + self.__workflows_api = WorkflowsApi(api_client=api_client) self.__config = config + self.__status_codes = self.__get_status_codes() @staticmethod @adapter_logger @@ -179,7 +192,8 @@ def write_tests(self, test_results: List[TestResult], fixture_containers: dict) test_result_model = Converter.test_result_to_testrun_result_post_model( test_result, - self.__config.get_configuration_id()) + self.__config.get_configuration_id(), + self.__status_codes) work_item_ids_for_link_with_auto_test = self.__get_work_item_uuids_for_link_with_auto_test( test_result.get_work_item_ids()) @@ -385,7 +399,8 @@ def __link_test_to_work_item(self, autotest_global_id: str, work_item_id: str) - def __load_test_result(self, test_result: TestResult) -> str: model = Converter.test_result_to_testrun_result_post_model( test_result, - self.__config.get_configuration_id()) + self.__config.get_configuration_id(), + self.__status_codes) response = self.__test_run_api.set_auto_test_results_for_test_run( id=self.__config.get_test_run_id(), @@ -407,8 +422,8 @@ def update_test_results(self, fixtures_containers: dict, test_result_ids: dict) fixtures_containers, test_result_ids) for test_result in test_results: - model = Converter.convert_test_result_model_to_test_results_id_put_request( - self.get_test_result_by_id(test_result.get_test_result_id())) + test_result_response = self.get_test_result_by_id(test_result.get_test_result_id()) + model = Converter.convert_test_result_model_to_test_results_id_put_request(test_result_response) model.setup_results = Converter.step_results_to_auto_test_step_result_update_request( test_result.get_setup_results()) @@ -441,4 +456,19 @@ def load_attachments(self, attach_paths: list or tuple) -> List[AttachmentPutMod return attachments def get_configuration_id(self): - return self.__config.get_configuration_id() \ No newline at end of file + return self.__config.get_configuration_id() + + @adapter_logger + def __get_project(self) -> ProjectModel: + return self.__projects_api.get_project_by_id(id=self.__config.get_project_id()) + + @adapter_logger + def __get_workflow_by_id(self, workflow_id: str) -> WorkflowApiResult: + return self.__workflows_api.api_v2_workflows_id_get(id=workflow_id) + + @adapter_logger + def __get_status_codes(self) -> List[str]: + project: ProjectModel = self.__get_project() + workflow: WorkflowApiResult = self.__get_workflow_by_id(project.workflow_id) + + return [status.code for status in workflow.statuses] diff --git a/testit-python-commons/src/testit_python_commons/client/converter.py b/testit-python-commons/src/testit_python_commons/client/converter.py index fb0d3e3..cb44727 100644 --- a/testit-python-commons/src/testit_python_commons/client/converter.py +++ b/testit-python-commons/src/testit_python_commons/client/converter.py @@ -32,6 +32,7 @@ LinkApiResult, UpdateLinkApiModel, AssignAttachmentApiModel, +TestStatusType ) from testit_python_commons.models.link import Link @@ -197,46 +198,25 @@ def test_result_to_autotest_put_model( cls, test_result: TestResult, project_id: str) -> AutoTestUpdateApiModel: - if test_result.get_outcome() == 'Passed': - return AutoTestUpdateApiModel( - external_id=test_result.get_external_id(), - project_id=project_id, - name=test_result.get_autotest_name(), - steps=cls.step_results_to_autotest_steps_model( - test_result.get_step_results()), - setup=cls.step_results_to_autotest_steps_model( - test_result.get_setup_results()), - teardown=cls.step_results_to_autotest_steps_model( - test_result.get_teardown_results()), - namespace=test_result.get_namespace(), - classname=test_result.get_classname(), - title=test_result.get_title(), - description=test_result.get_description(), - links=cls.links_to_links_put_model(test_result.get_links()), - labels=test_result.get_labels(), - tags=test_result.get_tags(), - external_key=test_result.get_external_key() - ) - else: - return AutoTestUpdateApiModel( - external_id=test_result.get_external_id(), - project_id=project_id, - name=test_result.get_autotest_name(), - steps=cls.step_results_to_autotest_steps_model( - test_result.get_step_results()), - setup=cls.step_results_to_autotest_steps_model( - test_result.get_setup_results()), - teardown=cls.step_results_to_autotest_steps_model( - test_result.get_teardown_results()), - namespace=test_result.get_namespace(), - classname=test_result.get_classname(), - title=test_result.get_title(), - description=test_result.get_description(), - links=cls.links_to_links_put_model(test_result.get_links()), - labels=test_result.get_labels(), - tags=test_result.get_tags(), - external_key=test_result.get_external_key() - ) + return AutoTestUpdateApiModel( + external_id=test_result.get_external_id(), + project_id=project_id, + name=test_result.get_autotest_name(), + steps=cls.step_results_to_autotest_steps_model( + test_result.get_step_results()), + setup=cls.step_results_to_autotest_steps_model( + test_result.get_setup_results()), + teardown=cls.step_results_to_autotest_steps_model( + test_result.get_teardown_results()), + namespace=test_result.get_namespace(), + classname=test_result.get_classname(), + title=test_result.get_title(), + description=test_result.get_description(), + links=cls.links_to_links_put_model(test_result.get_links()), + labels=test_result.get_labels(), + tags=test_result.get_tags(), + external_key=test_result.get_external_key() + ) @classmethod @adapter_logger @@ -244,57 +224,37 @@ def test_result_to_update_autotest_request( cls, test_result: TestResult, project_id: str) -> UpdateAutoTestRequest: - if test_result.get_outcome() == 'Passed': - return UpdateAutoTestRequest( - external_id=test_result.get_external_id(), - project_id=project_id, - name=test_result.get_autotest_name(), - steps=cls.step_results_to_autotest_steps_model( - test_result.get_step_results()), - setup=cls.step_results_to_autotest_steps_model( - test_result.get_setup_results()), - teardown=cls.step_results_to_autotest_steps_model( - test_result.get_teardown_results()), - namespace=test_result.get_namespace(), - classname=test_result.get_classname(), - title=test_result.get_title(), - description=test_result.get_description(), - links=cls.links_to_links_put_model(test_result.get_links()), - labels=test_result.get_labels(), - tags=test_result.get_tags(), - external_key=test_result.get_external_key() - ) - else: - return UpdateAutoTestRequest( - external_id=test_result.get_external_id(), - project_id=project_id, - name=test_result.get_autotest_name(), - steps=cls.step_results_to_autotest_steps_model( - test_result.get_step_results()), - setup=cls.step_results_to_autotest_steps_model( - test_result.get_setup_results()), - teardown=cls.step_results_to_autotest_steps_model( - test_result.get_teardown_results()), - namespace=test_result.get_namespace(), - classname=test_result.get_classname(), - title=test_result.get_title(), - description=test_result.get_description(), - links=cls.links_to_links_put_model(test_result.get_links()), - labels=test_result.get_labels(), - tags=test_result.get_tags(), - external_key=test_result.get_external_key() - ) + return UpdateAutoTestRequest( + external_id=test_result.get_external_id(), + project_id=project_id, + name=test_result.get_autotest_name(), + steps=cls.step_results_to_autotest_steps_model( + test_result.get_step_results()), + setup=cls.step_results_to_autotest_steps_model( + test_result.get_setup_results()), + teardown=cls.step_results_to_autotest_steps_model( + test_result.get_teardown_results()), + namespace=test_result.get_namespace(), + classname=test_result.get_classname(), + title=test_result.get_title(), + description=test_result.get_description(), + links=cls.links_to_links_put_model(test_result.get_links()), + labels=test_result.get_labels(), + tags=test_result.get_tags(), + external_key=test_result.get_external_key() + ) @classmethod @adapter_logger def test_result_to_testrun_result_post_model( cls, test_result: TestResult, - configuration_id: str) -> AutoTestResultsForTestRunModel: - return AutoTestResultsForTestRunModel( + configuration_id: str, + status_codes: List[str]) -> AutoTestResultsForTestRunModel: + model = AutoTestResultsForTestRunModel( configuration_id=configuration_id, auto_test_external_id=test_result.get_external_id(), - status_code=test_result.get_outcome(), + status_type=test_result.get_status_type(), step_results=cls.step_results_to_attachment_put_model_autotest_step_results_model( test_result.get_step_results()), setup_results=cls.step_results_to_attachment_put_model_autotest_step_results_model( @@ -313,6 +273,11 @@ def test_result_to_testrun_result_post_model( completed_on=test_result.get_completed_on() ) + if test_result.get_outcome() in status_codes: + model.status_code = test_result.get_outcome() + + return model + @classmethod @adapter_logger def convert_test_result_model_to_test_results_id_put_request( diff --git a/testit-python-commons/src/testit_python_commons/models/status_type.py b/testit-python-commons/src/testit_python_commons/models/status_type.py new file mode 100644 index 0000000..6182848 --- /dev/null +++ b/testit-python-commons/src/testit_python_commons/models/status_type.py @@ -0,0 +1,6 @@ +class StatusType: + SUCCEEDED = 'Succeeded' + FAILED = 'Failed' + INCOMPLETE = 'Incomplete' + INPROGRESS = 'InProgress' + PENDING = 'Pending' diff --git a/testit-python-commons/src/testit_python_commons/models/test_result.py b/testit-python-commons/src/testit_python_commons/models/test_result.py index 6d04e5c..4ffbe91 100644 --- a/testit-python-commons/src/testit_python_commons/models/test_result.py +++ b/testit-python-commons/src/testit_python_commons/models/test_result.py @@ -10,6 +10,7 @@ class TestResult: __external_id: str = None __autotest_name: str = None __outcome: str = None + __status_type: str = None __title: str = None __description: str = None __duration: int = None @@ -65,6 +66,16 @@ def set_outcome(self, outcome: str): def get_outcome(self) -> str: return self.__outcome + @adapter_logger + def set_status_type(self, status_type: str): + self.__status_type = HtmlEscapeUtils.escape_html_tags(status_type) + + return self + + @adapter_logger + def get_status_type(self) -> str: + return self.__status_type + @adapter_logger def set_title(self, title: str): self.__title = HtmlEscapeUtils.escape_html_tags(title)