Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

New Testrail Version Has Broken This Plugin #151

Open
glazeb opened this issue Sep 21, 2021 · 9 comments
Open

New Testrail Version Has Broken This Plugin #151

glazeb opened this issue Sep 21, 2021 · 9 comments

Comments

@glazeb
Copy link

glazeb commented Sep 21, 2021

Describe the bug
When we try to send test results to testrail using this plugin it no longer runs any tests and throws an error (below). It seems Testrail's newest version has caused this issue based on our findings as they added to their response for getting tests.

image

To Reproduce
Steps to reproduce the behavior:
Just try to send results to testrail and you should see the error.

Fix we tried locally and worked
Below is the file and method we updated to make it work. The last part is what is needed to be added when returning response (['tests']).

Plugin.py

class PyTestRailPlugin(object):

def get_tests(self, run_id):
"""
:return: the list of tests containing in a testrun.
"""
response = self.client.send_get(
GET_TESTS_URL.format(run_id),
cert_check=self.cert_check
)
error = self.client.get_error(response)
if error:
print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error))
return None
return response['tests']

@JohnOSu
Copy link

JohnOSu commented Sep 21, 2021

That won't necessarily get all the tests, for example - if there are more than 250 tests in the target.

The changes described here have now been implemented:
https://discuss.gurock.com/t/bulk-api-endpoint-changes-coming-soon/19537

These calls now need to be able to handle the paginated responses:
get_cases
get_runs
get_results
get_tests
get_results_for_case
get_results_for_run
get_plans
get_projects
get_sections
get_milestones
get_history_for_case
get_attachments_for_case
get_attachments_for_run
Get_attachments_for_plan

@glazeb
Copy link
Author

glazeb commented Sep 21, 2021

Does anyone know if this stuff is being worked on already?

@glazeb
Copy link
Author

glazeb commented Sep 21, 2021

So for the pagination stuff it would have to be written something like this correct?

def get_tests(self, run_id):
"""
:return: the list of tests containing in a testrun.
"""
response = self.client.send_get(GET_TESTS_URL.format(run_id), cert_check=self.cert_check)
error = self.client.get_error(response)
if error:
print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error))
return None

test_cases = response["cases"]

while response["size"] == 250:
    pagination_suffix_url = (response["_links"]["next"]).replace('/api/v2/', "")
    response = self.client.send_get(pagination_suffix_url, cert_check=self.cert_check)
    if error:
        print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error))
        return None
    
    test_cases = test_cases + response["cases"]

return test_cases

@JohnOSu
Copy link

JohnOSu commented Sep 21, 2021

I have no idea if this is still being maintained. This worked for me:

`

def get_tests(self, run_id):
    """
    :return: the list of tests containing in a testrun.

    """
    from urllib.parse import parse_qsl, urlencode

    master_test_list = []
    repeat = True
    params = None

    while repeat:
        uri = GET_TESTS_URL.format(run_id)
        if params:
            uri = uri+params
        response = self.client.send_get(uri, cert_check=self.cert_check)

        error = self.client.get_error(response)
        if error:
            print('[{}] Failed to get tests: "{}"'.format(TESTRAIL_PREFIX, error))
            return None

        test_list = [item for item in response['tests']]
        master_test_list.extend(test_list)

        repeat = response['_links']['next']
        if repeat:
            params = f'&{urlencode(parse_qsl(repeat))}'

    return master_test_list

`

@chayanmazumder-cpi
Copy link

This is a blocker, and anyone looking at it? Cause we have virtual env in prod, and cannot create hot fix to run this.

@AudioLeaf
Copy link

@chayanmazumder-cpi
I implemented the solution outlined by @JohnOSu in my own pip package.

I've noticed there are lingering pull requests on this repo so I'm not sure if a PR for this would ever make it in as I cannot tell if the project is still being maintained.

So if you need an immediate solution I'd try what John did. Hope this helps.

@allankp
Copy link
Owner

allankp commented Oct 21, 2021

Hi, I don't have a massive amount of spare time. But a PR would certainly be looked at.

@chayanmazumder-cpi
Copy link

@allankp what test to run and how-to, before raising a PR?

@Miracle05
Copy link

@allankp repo now obsoleted and unsupported?

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

No branches or pull requests

6 participants