devolo / adaptavist

python package providing functionality for Jira Test Management (tm4j)
MIT License
8 stars 11 forks source link

most of requests: via *_key parameter - doesn;t work, need to use id #5

Closed dimit999 closed 1 year ago

dimit999 commented 3 years ago

most of requests: via *_key parameter - doesn;t work, need to use id

for example:

`def create_test_run(self, project_key, test_run_name, **kwargs): ""

    Create a new test run.

    :param project_key: project key of the test run ex. "TEST"
    :type project_key: str
    :param test_run_name: name of the test run to be created
    :type test_run_name: str

    :param kwargs: Arbitrary list of keyword arguments
            folder: name of the folder where to create the new test run
            issue_key: issue key to link this test run to
            test_plan_key: test plan key to link this test run to
            test_cases: list of test case keys to be linked to the test run ex. ["TEST-T1026","TEST-T1027"]
            environment: environment to distinguish multiple executions (call get_environments() to get a list of available ones)

    :return: key of the test run created
    :rtype: str
    """
    self.logger.debug("create_test_run(\"%s\", \"%s\")", project_key, test_run_name)

    folder = kwargs.pop("folder", None)
    issue_key = kwargs.pop("issue_key", None)
    test_plan_key = kwargs.pop("test_plan_key", None)
    test_cases = kwargs.pop("test_cases", [])
    environment = kwargs.pop("environment", None)

    assert not kwargs, "Unknown arguments: %r" % kwargs

    folder = ("/" + folder).replace("//", "/") if folder else folder or None
    if folder and folder not in self.get_folders(project_key=project_key, folder_type="TEST_RUN"):
        self.create_folder(project_key=project_key, folder_type="TEST_RUN", folder_name=folder)

    test_cases_list_of_dicts = []
    for test_case_key in test_cases:
        test_cases_list_of_dicts.append({"testCaseKey": test_case_key, "environment": environment, "executedBy": get_executor(), "assignedTo": get_executor()})

    request_url = self.adaptavist_api_url + "/testrun"

    request_data = {"projectKey": project_key,
                    "testPlanKey": test_plan_key,
                    "name": test_run_name,
                    "folder": folder,
                    "issueKey": issue_key,
                    "items": test_cases_list_of_dicts}

    try:
        request = requests.post(request_url,
                                auth=self.authentication,
                                headers=self.headers,
                                data=json.dumps(request_data))
        request.raise_for_status()
    except HTTPError as ex:
        # HttpPost: in case of status 400 request.text contains error messages
        self.logger.error("request failed. %s %s", ex, request.text)
        return None
    except (requests.exceptions.ConnectionError, requests.exceptions.RequestException) as ex:
        self.logger.error("request failed. %s", ex)
        return None

    response = request.json()

    return response["key"]`

with this request_data request doesn't work, need to send with this data:

` def create_test_run(self, project_key, project_id, test_run_name, **kwargs): """ Create a new test run.

    :param project_key: project key of the test run ex. "TEST"
    :type project_key: str
    :param project_id: project id of the test run ex. "TEST"
    :type project_id: str
    :param test_run_name: name of the test run to be created
    :type test_run_name: str

    :param kwargs: Arbitrary list of keyword arguments
            folder: name of the folder where to create the new test run
            issue_key: issue key to link this test run to
            test_plan_key: test plan key to link this test run to
            test_cases: list of test case keys to be linked to the test run ex. ["TEST-T1026","TEST-T1027"]
            environment: environment to distinguish multiple executions (call get_environments() to get a list of
            available ones)

    :return: key of the test run created
    :rtype: str
    """
    self.logger.debug("create_test_run(\"%s\", \"%s\", \"%s\")", project_key, project_id, test_run_name)

    folder = kwargs.pop("folder", None)
    issue_key = kwargs.pop("issue_key", None)
    test_plan_key = kwargs.pop("test_plan_key", None)
    test_plan_id = kwargs.pop("test_plan_id", None)
    test_cases = kwargs.pop("test_cases", [])
    environment = kwargs.pop("environment", None)
    time = kwargs.pop("time", None)

    assert not kwargs, "Unknown arguments: %r" % kwargs

    folder_name = ("/" + folder).replace("//", "/") if folder else folder or None
    folder_id = self.create_folder_plan(project_id=project_id, project_key=project_key, folder_type="TEST_PLAN",
                                        folder_name=folder_name)

    test_cases_list_of_dicts = []
    for test_case_key in test_cases:
        test_cases_list_of_dicts.append({"testCaseKey": test_case_key, "environment": environment, "executedBy": get_executor(), "assignedTo": get_executor()})

    request_url = self.adaptavist_api_url + "/testrun"

    request_data = {"projectId": project_id,
                    "testPlanId": test_plan_id,
                    "name": test_run_name,
                    "folderId": folder_id if folder_id else None,
                    "issueKey": issue_key,
                    "items": test_cases_list_of_dicts,
                    "plannedEndDate": time,
                    "plannedStartDate": time,
                    }

    try:
        request = requests.post(request_url,
                                auth=self.authentication,
                                headers=self.headers,
                                data=json.dumps(request_data),
                                verify=False)
        request.raise_for_status()
    except HTTPError as ex:
        # HttpPost: in case of status 400 request.text contains error messages
        self.logger.error("request failed. %s %s", ex, request.text)
        return None
    except (requests.exceptions.ConnectionError, requests.exceptions.RequestException) as ex:
        self.logger.error("request failed. %s", ex)
        return None

    response = request.json()
    self.lint_test_case(test_cases)

    return response["key"], response["id"]`

the same for OTHER REQUESTS, where for some need to use key or ID

so for now this library is not equal. If you need other data - maybe we have old version TM4J server plugin

Shutgun commented 3 years ago

Hi @dimit999 , we are using 7.1.0 and it is working here. Which version do you use?

dimit999 commented 3 years ago

Hi @dimit999 , we are using 7.1.0 and it is working here. Which version do you use? Hi,

What version of Test Management are you using? 7.0.0 What version of Jira are you using? 8.0.2

Environment Redhat Linux - Maipo Chrome Browser: 86.0

Data Center? No

Shutgun commented 3 years ago

That should not make a difference. What's the error you see when using the original method?

dimit999 commented 3 years ago

That should not make a difference. What's the error you see when using the original method?

when I use *.key - I receive 500 Server Error

Shutgun commented 3 years ago

I checked a few ideas I had but non of them lead to a 500. Is there any additional information that could help me with reproducing?

2Fake commented 1 year ago

Closing this issue as no further information are given