From cf61159921a2aa7022c513aeaecea9e43beac5d3 Mon Sep 17 00:00:00 2001 From: Paul Wildenhain Date: Thu, 17 Nov 2022 10:15:13 -0500 Subject: [PATCH] :bug: Make user role doctest deterministic The way the docstring is currently set up, it will randomly delete either "Test role" or "New Role". I assumed the list of roles was the same order everytime, when it fact it's random. This ensures that it's "new role" that acutally gets deleted --- redcap/methods/user_roles.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/redcap/methods/user_roles.py b/redcap/methods/user_roles.py index 6c82497..ca829b3 100644 --- a/redcap/methods/user_roles.py +++ b/redcap/methods/user_roles.py @@ -47,7 +47,7 @@ def export_user_roles( Examples: >>> proj.export_user_roles() - [{'unique_role_name': ..., 'role_label': 'New Role', 'design': '0', 'user_rights': '0', + [{'unique_role_name': ..., 'role_label': 'Test role', 'design': '0', 'user_rights': '0', 'data_access_groups': '0', 'reports': '0', 'stats_and_charts': '0', 'manage_survey_participants': '0', 'calendar': '0', 'data_import_tool': '0', 'data_comparison_tool': '0', 'logging': '0', 'file_repository': '0', @@ -55,7 +55,7 @@ def export_user_roles( 'api_import': '0', 'mobile_app': '0', 'mobile_app_download_data': '0', 'record_create': '0', 'record_rename': '0', 'record_delete': '0', 'lock_records_customization': '0', 'lock_records': '0', ..., - 'forms': {'form_1': 0}, 'forms_export': {'form_1': 0}}] + 'forms': {'form_1': 2}, 'forms_export': {'form_1': 0}}] """ payload = self._initialize_payload(content="userRole", format_type=format_type) return_type = self._lookup_return_type(format_type, request_type="export") @@ -162,9 +162,12 @@ def delete_user_roles( 1 We don't know what the 'unique_role_name' is for the newly created role, - so we have to find that out. Since it's the last role created, it should - be the last one in the export result - >>> new_role_id = proj.export_user_roles()[-1]["unique_role_name"] + so we have to look it up by 'role_label' + >>> roles = proj.export_user_roles() + >>> new_role_id = [ + ... role for role in roles + ... if role["role_label"] == "New Role" + ... ][0]["unique_role_name"] Delete the role >>> proj.delete_user_roles([new_role_id])