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

Add further workflow run support - create, find, and all #47

Merged

Conversation

peggalex
Copy link
Contributor

@peggalex peggalex commented Dec 1, 2023

While there exists a WorkflowRuns resource for Onfido Studio support, it only has the method evidence(). Some other actions, such as create, list, and retrieve are not yet added to this SDK. This PR adds those actions in.

I performed validation using the following code, although depending on your Onfido settings you may have different required applicant fields and other configuration differences. There are also new unit tests for the added methods.

import onfido
from onfido.regions import Region

ONFIDO_API_KEY = "" # TODO: populate with secret
ONFIDO_WORKFLOW_ID = "" # TODO: populate with value


if __name__ == "__main__":
    onfido_api = onfido.Api(ONFIDO_API_KEY, region=Region.CA)

    applicant_id = onfido_api.applicant.create({            
        "first_name": "FIRST_NAME",
        "last_name": "LAST_NAME",
        "dob": "2000-01-01"
    })["id"]

    create_resp = onfido_api.workflowrun.create({
        "applicant_id": applicant_id,
        "workflow_id": ONFIDO_WORKFLOW_ID
    })
    print("Create:")
    print(create_resp)

    workflow_run_id = create_resp["id"]
    find_resp = onfido_api.workflowrun.find(workflow_run_id)
    print("\nFind:")
    print(find_resp)

    all_resp = onfido_api.workflowrun.all()
    print("\nAll:")
    print(all_resp)


"created_at_gt": ["2023-11-17T16:39:04Z"],
"created_at_lt": ["2008-02-29T02:56:37Z"],
"sort": ['asc']
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other tests simply compare the fully-formed url with query parameters, such as:

assert history[0].url == "https://api.eu.onfido.com/v3.6/applicants?include_deleted=True&per_page=5&page=2"

in test_applicants.py > test_list_applicants.

However, this is a slightly different case because there are more params, and there are url-escaped values such as commas in properties like tags and status:

tags (optional): a list of comma separated tags to filter the results.
(docs)

Comparing the parsed url query params as a dict might be more readable and maintainable than something like:

assert history[0].url == "https://api.eu.onfido.com/v3.6/workflow_runs?page=2&sort=asc&status=approved%2Cdeclined&tags=dummy_tag1%2Cdummy_tag2&created_at_gt=2023-11-17T16%3A39%3A04Z&created_at_lt=2008-02-29T02%3A56%3A37Z

@peggalex peggalex force-pushed the add-workflow-run-create-find-all branch from 6d2db52 to e80eb95 Compare December 1, 2023 14:18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the existing onfido/resources/applicants.py

@peggalex
Copy link
Contributor Author

peggalex commented Dec 4, 2023

@DavidMealha hi David, was wondering if you would be able to review my PR

Copy link
Contributor

@dvacca-onfido dvacca-onfido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me, thanks for your contribution.

@DavidMealha-Onfido
Copy link
Contributor

Hey @peggalex, the changes look good but CI is failing, can you please fix it

@peggalex
Copy link
Contributor Author

peggalex commented Dec 5, 2023

hey @DavidMealha, I was using str.removesuffix() that was introduced in python3.9. I've made some updates and tested with python3.7 -- it should work now. Could I ask you to rerun the CI?

@DavidMealha-Onfido DavidMealha-Onfido merged commit 5a1c685 into onfido:master Dec 5, 2023
4 checks passed
@DavidMealha-Onfido
Copy link
Contributor

DavidMealha-Onfido commented Dec 5, 2023

Hey @peggalex, this has been released as part of v2.10.0. Thank you again for your contribution!

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

Successfully merging this pull request may close these issues.

3 participants