Beispiel #1
0
    def clean_up(self):
        """Remove qTest elements from the "Test Design" and "Test Execution" views.

        Raises:
            RuntimeError: Failed to cleanup all qTest elements.
        """

        if self._last_invocation_queue_job_id:
            test_cycle_api = swagger_client.TestcycleApi()

            self.tests.clean_up()

            try:
                for test_cycle in self.qtest_root_test_cycle.test_cycles:
                    test_cycle_api.delete_cycle(
                        project_id=self.qtest_project_id,
                        test_cycle_id=test_cycle.id,
                        force=True)
            except ApiException as e:
                raise RuntimeError("The qTest API reported an error!\n"
                                   "Status code: {}\n"
                                   "Reason: {}\n"
                                   "Message: {}".format(
                                       e.status, e.reason, e.body))

            self._last_invocation_queue_job_id = None
    def discover_root_test_cycle(self, test_cycle_name):
        """Search for a test cycle at the root of the qTest Test Execution with a matching name. (Case insensitive) If a
        matching test cycle name is not found then a test cycle will be created with the given name.

        Args:
            test_cycle_name (str): The test cycle name (e.g. queens) to search for in an case insensitive fashion.

        Returns:
            str: A qTest test cycle PID. (e.g. CL-123)

        Raises:
            RuntimeError: Failed to retrieve/create qTest test cycle(s).
        """

        auto_api = swagger_client.TestcycleApi()
        project_id = self._mediator.qtest_project_id
        test_cycle_pid = None

        try:
            test_cycles = {
                tc.to_dict()['name']: tc.to_dict()['pid']
                for tc in auto_api.get_test_cycles(project_id)
            }

            if test_cycle_name.lower() not in [
                    tcn.lower() for tcn in test_cycles.keys()
            ]:
                test_cycle_pid = auto_api.create_cycle(
                    project_id=project_id,
                    parent_id=0,
                    parent_type='root',
                    body=swagger_client.TestCycleResource(
                        name=test_cycle_name)).to_dict()['pid']
            else:
                try:
                    test_cycle_pid = test_cycles[test_cycle_name]
                except KeyError:
                    for key in list(test_cycles.keys()):
                        if key.lower() == test_cycle_name.lower():
                            # this will take the last match found
                            # once we can warn we should warn the user that we found duplicate cycles
                            test_cycle_pid = test_cycles[key]
        except ApiException as e:
            raise RuntimeError("The qTest API reported an error!\n"
                               "Status code: {}\n"
                               "Reason: {}\n"
                               "Message: {}".format(e.status, e.reason,
                                                    e.body))

        return test_cycle_pid
Beispiel #3
0
def _configure_test_environment(qtest_env_vars):
    """Configure the qTest project for testing.

    Returns:
        tuple(swagger_client.TestCycleResource, swagger_client.ModuleResource): A tuple containing the root test cycle
            and root requirement module to use for testing.

    Raises:
        RuntimeError: Failed to create or cleanup all qTest elements.
    """

    # Setup
    swagger_client.configuration.api_key['Authorization'] = qtest_env_vars['QTEST_API_TOKEN']
    project_id = qtest_env_vars['QTEST_SANDBOX_PROJECT_ID']
    test_cycle_api = swagger_client.TestcycleApi()
    module_api = swagger_client.ModuleApi()

    try:
        root_test_cycle = test_cycle_api.create_cycle(project_id=project_id,
                                                      parent_id=0,
                                                      parent_type='root',
                                                      body=swagger_client.TestCycleResource(name=str(uuid.uuid1())))
        root_req_module = module_api.create_module(project_id=project_id,
                                                   body=swagger_client.ModuleResource(name=str(uuid.uuid1())))
    except ApiException as e:
        raise RuntimeError("The qTest API reported an error!\n"
                           "Status code: {}\n"
                           "Reason: {}\n"
                           "Message: {}".format(e.status, e.reason, e.body))

    yield root_test_cycle, root_req_module

    # Teardown
    try:
        test_cycle_api.delete_cycle(project_id=project_id, test_cycle_id=root_test_cycle.id, force=True)
        module_api.delete_module(project_id=project_id, module_id=root_req_module.id, force=True)
    except ApiException as e:
        raise RuntimeError("The qTest API reported an error!\n"
                           "Status code: {}\n"
                           "Reason: {}\n"
                           "Message: {}".format(e.status, e.reason, e.body))
Beispiel #4
0
    def qtest_parent_test_cycles(self):
        """A list of qTest swagger_client test cycle models which are the direct ancestor for all associated test runs.

        Returns:
            [swagger_client.TestCycleResource]

        Raises:
            AssertionError: Associated test cycles do not exist.
            RuntimeError: General qTest API failure.
        """

        test_cycle_ids = []

        for run in self.qtest_test_runs:
            for link in run.links:
                if link.rel == 'test-cycle':
                    try:
                        test_cycle_ids.append(
                            int(
                                self._HREF_ID_REGEX.search(
                                    link.href).group(1)))
                    except (AttributeError, IndexError):
                        raise AssertionError(
                            'Test case does not have parent test cycles!')

        test_cycle_api = swagger_client.TestcycleApi()

        try:
            return [
                test_cycle_api.get_test_cycle(self._qtest_project_id, tc_id)
                for tc_id in test_cycle_ids
            ]
        except ApiException as e:
            raise RuntimeError("The qTest API reported an error!\n"
                               "Status code: {}\n"
                               "Reason: {}\n"
                               "Message: {}".format(e.status, e.reason,
                                                    e.body))