Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runs _session.runs.add_run() for POST index.php?/api/v2/add_run/{project_id} not working as expected #92

Open
shenhong29 opened this issue Jul 30, 2023 · 8 comments

Comments

@shenhong29
Copy link

Error message:

[2023-07-29 16:58:07,930][ERROR][_session]: Code: 400, reason: Bad Request url: https://hp-testrail.external.hp.com/index.php?/api/v2/add_run/466, content: b'{"error":"Field :suite_id is a required field."}'

The issue is the suite_id is not required parameter based on https://support.testrail.com/hc/en-us/articles/7077874763156-Runs#addrun, parameter. And the suite_id is provided in the payload. See the payload information next.

The payload is:
project id: 466
suite id: 65398
[2023-07-29 16:58:07,720][INFO ][tr_helper]: Create test run: TR Unit test 2023-07-29_16_58_07.715584-07_00 with payload {"suite_id": 65398, "name": "TR Unit test 2023-07-29_16_58_07.715584-07_00", "description": "Test run TR Unit test 2023-07-29_16_58_07.715584-07_00 with defined testcases", "include_all": false, "case_ids": [35076905, 35076906, 35076907, 35076908, 35076909, 35076910, 35076911, 35076912, 35076913, 35076914, 35076915, 35076916, 35076917, 35092638, 35092639, 35092640, 35092641, 35092642]}

The response is:
[2023-07-29 16:58:07,930][DEBUG][_session]: Response header: {'Date': 'Sat, 29 Jul 2023 23:58:07 GMT', 'Set-Cookie': 'tr_rememberme=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0, notificationbar=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/index, TS0104937c=01cc51d60f65ceaac8ccb9113c7ed2af29392e494590650e88f91f2816c687d5d132fa55b50c7630762e56a721ee5fd8b5fe216e01ac7687e66780f86fa40eaf200a3288354f4ee1b49b8a875c83435ec1f23f71ab; Path=/, TS01dcc28e=01cc51d60f0e31948020e5072e2a097b000496617890650e88f91f2816c687d5d132fa55b50c7630762e56a721ee5fd8b5fe216e01ac7687e66780f86fa40eaf200a3288356735f90794a3000489e519ab9613244003875726c359c8555bee4dc23636d04a; path=/index, TS98d9ab12029=08bf25d8b7ab2800d8d1f2bc61bed64729797a338741fd022c197bd5e265ad183568f1e636ead9949d74b04b7841d7a5; Max-Age=30; Path=/', 'Content-Length': '48', 'Connection': 'close', 'Content-Type': 'application/json; charset=utf-8', 'P3P': 'CP="{}"'}

FYI, the post request of add_run with the same endpoint and payload documented above works in the POSTMAN session.
image

@shenhong29 shenhong29 changed the title Runs endpoint POST index.php?/api/v2/add_run/{project_id} not working as expected Runs _session.runs.add_run() for POST index.php?/api/v2/add_run/{project_id} not working as expected Jul 30, 2023
@dsayling
Copy link
Contributor

So, add_run only has one positional argument, project_id, but suite_id is allowed as a keyword argument.

Are you providing the suite ID in the add_run method call?

@shenhong29
Copy link
Author

shenhong29 commented Jul 30, 2023 via email

@dsayling
Copy link
Contributor

Can you please provide a complete stack trace?

@shenhong29
Copy link
Author

Run completed, parsing output
./tests/test_runs.py::test_add_run_with_real_data Failed: [undefined]testrail_api._exception.StatusCodeError: (400, 'Bad Request', 'https://hp-testrail.external.hp.com/index.php?/api/v2/add_run/466', b'{"error":"Field :suite_id is a required field."}')
def test_add_run_with_real_data() -> None:
"""test add run
"""
# mock.add_callback(
# responses.POST,
# url('add_run/12'),
# add_run
# )
api = TestRailAPI(
url="https://hp-testrail.external.hp.com",
email="removed",
password="removed")
payload = {
"suite_id": 65398,
"name": "TR Unit test 2023-07-29_16_58_09-07_00",
"description": "Test run TR Unit test 2023-07-29_16_58_07.715584-07_00 with defined testcases",
"include_all": False,
"case_ids": [
35076905,
35076906,
35076907,
35076908,
35076909,35076910, 35076911, 35076912, 35076913, 35076914, 35076915, 35076916, 35076917, 35092638, 35092639, 35092640, 35092641, 35092642
]
}

  resp = api.runs.add_run(project_id=466, kwargs=payload)

tests\test_runs.py:93:


testrail_api_category.py:1748: in add_run
return self.s.post(endpoint=f"add_run/{project_id}", json=kwargs)
testrail_api_session.py:171: in post
return self.request(
testrail_api_session.py:215: in request
return response if raw else self.__response_handler(response)


self = <testrail_api._testrail_api.TestRailAPI object at 0x000001A5B9880B20>
response = <Response [400]>

def __default_response_handler(self, response: requests.Response):
    if not response.ok:
        logger.error(
            "Code: %s, reason: %s url: %s, content: %s",
            response.status_code,
            response.reason,
            response.url,
            response.content,
        )
        if not self.__exc:
          raise StatusCodeError(
                response.status_code,
                response.reason,
                response.url,
                response.content,
            )

E testrail_api._exception.StatusCodeError: (400, 'Bad Request', 'https://hp-testrail.external.hp.com/index.php?/api/v2/add_run/466', b'{"error":"Field :suite_id is a required field."}')

testrail_api_session.py:122: StatusCodeError

Total number of tests expected to run: 1
Total number of tests run: 1
Total number of tests passed: 0
Total number of tests failed: 1
Total number of tests failed with errors: 0
Total number of tests skipped: 0
Total number of tests with no result data: 0
Finished running tests!

@shenhong29
Copy link
Author

just wondering if I need to provide more information or not. and appreciate if any update is available. thanks.

@dsayling
Copy link
Contributor

dsayling commented Aug 1, 2023

I attempted to fix your formatting, and your request looks right, but now that I inspect the documentation it has this very weird type for "suite_id",

image

I don't have access to a TestRail instance at the moment, so I cant verify what's correct.


 Run completed, parsing output ./tests/test_runs.py::test_add_run_with_real_data
 Failed: [undefined]testrail_api._exception.StatusCodeError: (400, 'Bad Request', 'https://hp-testrail.external.hp.com/index.php?/api/v2/add_run/466', b'{"error":"Field :suite_id is a required field."}') def test_add_run_with_real_data() - None: """test add run """
 # mock.add_callback( 
 # responses.POST, 
# url('add_run/12'), 
# add_run # ) 
 api = TestRailAPI( url="https://hp-testrail.external.hp.com", email="removed", password="removed") 
 payload = { "suite_id": 65398, "name": "TR Unit test 2023-07-29_16_58_09-07_00", "description": "Test run TR Unit test 2023-07-29_16_58_07.715584-07_00 with defined testcases", "include_all": False, "case_ids": [ 35076905, 35076906, 35076907, 35076908, 35076909,35076910, 35076911, 35076912, 35076913, 35076914, 35076915, 35076916, 35076917, 35092638, 35092639, 35092640, 35092641, 35092642 ] }
 resp = api.runs.add_run(project_id=466, kwargs=payload)
 tests\test_runs.py:93:
 testrail_api_category.py:1748: in add_run return self.s.post(endpoint=f"add_run/{project_id}", json=kwargs) testrail_api_session.py:171: in post return self.request( testrail_api_session.py:215: in request return response if raw else self.__response_handler(response)
 self = <testrail_api._testrail_api.TestRailAPI object at 0x000001A5B9880B20 response = <Response [400]
 def __default_response_handler(self, response: requests.Response):
     if not response.ok:
         logger.error(
             "Code: %s, reason: %s url: %s, content: %s",
             response.status_code,
             response.reason,
             response.url,
             response.content,
         )
         if not self.__exc:
            raise StatusCodeError(
                 response.status_code,
                 response.reason,
                 response.url,
                 response.content,
             )
 
 E testrail_api._exception.StatusCodeError: (400, 'Bad Request', 'https://hp-testrail.external.hp.com/index.php?/api/v2/add_run/466', b'{"error":"Field :suite_id is a required field."}')

testrail_api_session.py:122: StatusCodeError
Total number of tests expected to run: 1 Total number of tests run: 1 Total number of tests passed: 0 Total number of tests failed: 1 Total number of tests failed with errors: 0 Total number of tests skipped: 0 Total number of tests with no result data: 0 Finished running tests!

@shenhong29
Copy link
Author

I can help with that, just let me know what you want me to try on the testrail instance.

@tolstislon
Copy link
Owner

Send

...
"suite_id": [65398],
...

Please report the result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants