Skip to content

Commit

Permalink
🐛 Make user role doctest deterministic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pwildenhain committed Nov 17, 2022
1 parent 0bb11b9 commit cf61159
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions redcap/methods/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ 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',
'data_quality_create': '0', 'data_quality_execute': '0', 'api_export': '0',
'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")
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit cf61159

Please sign in to comment.