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

not able to get/retrieve Custom fields status #52

Open
cyrusG123 opened this issue Mar 17, 2021 · 10 comments
Open

not able to get/retrieve Custom fields status #52

cyrusG123 opened this issue Mar 17, 2021 · 10 comments

Comments

@cyrusG123
Copy link

We're able to get most of the fields from your code except the custom fields, is there any way to retrieve/get all custom fields status such as "Automation Status", "Automation Assignee", "QA-Assignee" from this api-warper?
Many thanks in advance.

@leviable
Copy link
Owner

Hi @cyrusG123. I wasn't able to implement a clean solution for the custom fields while I was developing this, and no longer have TestRail access to continue development.

That said, all of the object data is stored in the _content dict, which you can access directly with something like this:

automation_status = test._content.get('<automation status custom field key>', None)
automation_assignee = test._content.get('<automation assignee custom field key>', None)
qa_assignee = test._content.get('<qa assignee custom field key>', None)

Hope that helps. If it doesn't, let me know and I can dig in more

@cyrusG123
Copy link
Author

Thanks, Levi for your quick response. I tried but getting None for all, perhaps I'm not doing it right or don't know how to get the automaton customer fields key.
client = traw.Client(username='username', password='passwrod', url='url)

test = client.project(30)
for x in range(1, 7):
print (test._content.get(x, None))

Results:
None
None
None
None
None
None
None

Many thanks in advance.

@leviable
Copy link
Owner

Which object are you trying to get the custom fields for, test objects?

If so, try something like this:

from pprint import pprint as pp
import traw

client = traw.Client(username='username', password='passwrod', url='url)
project = client.project(30)

new_run = client.run()
new_run.name = "Example run"
new_run.include_all = True
new_run.project = project

run = client.add(new_run)

for test in client.tests(run):
    pprint(test._content)

That should print out the _content dictionary. Look in it for your custom fields, which should have keys like custom_qa_assignee.

Once you know the key names, you should be able to access them as outlined above:
qa_assignee = test._content.get('custom_qa_assignee', None)

Let me know if that helps

@cyrusG123
Copy link
Author

cyrusG123 commented Mar 18, 2021

Thank You, tried that and it returns the key value , not name, we do have these option for automation_status:
automation_status:

  • Code Reviewed
  • In Progress
  • Automated
  • etc..

I belive it returns the field key in this case
for test in client.tests(run):
automation_status = test._content.get('custom_automation_status', None)
print (automation_status)

Result:
10
7
7
7
10
10
10
8
7
7
7
7
7
7
7
7
10
7

@leviable
Copy link
Owner

Awesome, we're close. Try this:

for test in client.tests(run):
    automation_status = test._content.get('custom_automation_status', None)
    if automation_status:
        print (client.status(automation_status))

@cyrusG123
Copy link
Author

I do really appreciate it, I tried that before but it gives me the below, instead of actual value, I believe these are the keys.
Status-10
Status-7
Status-7
Status-7
Status-10
Status-10
Status-10
Status-8
...

@leviable
Copy link
Owner

Alright, getting closer, try this:

for test in client.tests(run):
    automation_status = test._content.get('custom_automation_status', None)
    if automation_status:
        status = client.status(automation_status)
        print(status.name)
        print(status.label)

@cyrusG123
Copy link
Author

the automation_status does return all other fields, not match the 'custom_automation_status' field, using the name to print the object like below, as I can see, passed, and defer status are not part of status of 'custom_automation_status' field.

for test in client.tests(run):
automation_status = test._content.get('custom_automation_status', None)
if automation_status:
x = client.status(automation_status)
print(x.name)

custom_status6
custom_status4
custom_status6
custom_status7
custom_status3
retest
defer
custom_status6
passed

@cyrusG123
Copy link
Author

cyrusG123 commented Mar 18, 2021

did not find a match, label and name are not matching the status from custom_automation_status drop down/options

for test in client.tests(run):
    automation_status = test._content.get('custom_automation_status', None)
    status = client.status(automation_status)
    txt = status.label
    match = re.search(r'Code_approved', str(txt))

    if match:
        print("find a mactch", match)  
    else:
        print('did not find match')

Result:

did not find a match
did not find a match
did not find a match
did not find a match
did not find a match
did not find a match
did not find a match
...

@cyrusG123
Copy link
Author

cyrusG123 commented Mar 18, 2021

I could not get the right text for those key, instead I used client.run() and I found out that the first option in custom_automation_status maps to 1, 2, 3 and it correspondings/maps to the text, so I've created a dictionary to map the key value to the text and retrieve them as below:

auto_run = client.run(15)
tests = list(client.tests(auto_run))  # Expand the generator to a list
dic = {1: 'Under-Code-Review', 2: 'Code-Approved', 3: 'In-Progress', 4: 'Automated'}
for case in tests:
      automation_status = case._content.get('custom_automation_status', None)
      print(dic.get(automation_status))

Results:

In-Progress
Under-Code-Review

That being said, how do I get the status from the existing Report (View Report) or Test suite if any without adding a new run?
...
Many thanks for all the help Levi, much appreciated.

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

2 participants