Skip to content

Commit

Permalink
Merge pull request #1 from redcap-tools/arms-events-pr-fixes
Browse files Browse the repository at this point in the history
Arms & Events PR fixes
  • Loading branch information
patking02 authored Oct 31, 2023
2 parents 6611f3b + 2d7a672 commit 46bbf78
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions redcap/methods/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def export_events(
Examples:
>>> proj.export_events()
[{"event_name": "Event 1", "arm_num": 1, "unique_event_name": "event_1_arm_1",
"custom_event_label": null, "event_id": 1}]
[{'event_name': 'Event 1', 'arm_num': 1, 'unique_event_name': 'event_1_arm_1',
'custom_event_label': '', 'event_id': ...}, {'event_name': 'Event 2', ...}]
"""
# pylint:enable=line-too-long
payload = self._initialize_payload(content="event", format_type=format_type)
Expand Down
4 changes: 2 additions & 2 deletions redcap/methods/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def export_user_roles(
Examples:
>>> proj.export_user_roles()
[{'unique_role_name': ..., 'role_label': 'Test role', 'design': '0', 'user_rights': '0',
'data_access_groups': '0', 'reports': '0', 'stats_and_charts': '0',
[{'unique_role_name': ..., 'role_label': 'Test role', 'design': '0', 'alerts': '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',
Expand Down
4 changes: 2 additions & 2 deletions redcap/methods/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def export_users(
Examples:
>>> proj.export_users()
[{'username': ..., 'email': ..., 'expiration': '', 'data_access_group': '',
'data_access_group_id': '', 'design': 1, 'user_rights': 1, 'data_access_groups': 1,
'reports': 1, ...}]
'data_access_group_id': '', 'design': 1, 'alerts': 1, 'user_rights': 1,
'data_access_groups': 1, 'reports': 1, ...}]
"""
payload = self._initialize_payload(content="user", format_type=format_type)
return_type = self._lookup_return_type(format_type, request_type="export")
Expand Down
38 changes: 25 additions & 13 deletions tests/integration/test_long_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

from redcap import RedcapError


if not os.getenv("REDCAPDEMO_SUPERUSER_TOKEN"):
pytest.skip(
Expand Down Expand Up @@ -115,8 +117,8 @@ def test_arms_export(long_project):

assert len(response) == 2

arm_nums = list(response.keys())
arm_names = list(response.values())
arm_nums = [arm["arm_num"] for arm in response]
arm_names = [arm["name"] for arm in response]

assert arm_nums == [1, 2]
assert arm_names == ["Drug A", "Drug B"]
Expand All @@ -137,8 +139,8 @@ def test_arms_import(long_project):
response = long_project.export_arms()
assert len(response) == 3

arm_nums = list(response.keys())
arm_names = list(response.values())
arm_nums = [arm["arm_num"] for arm in response]
arm_names = [arm["name"] for arm in response]

assert arm_nums == [1, 2, 3]
assert arm_names == ["Drug A", "Drug B", "Drug C"]
Expand All @@ -155,8 +157,8 @@ def test_arms_import_rename(long_project):

assert len(response) == 3

arm_nums = list(response.keys())
arm_names = list(response.values())
arm_nums = [arm["arm_num"] for arm in response]
arm_names = [arm["name"] for arm in response]

assert arm_nums == [1, 2, 3]
assert arm_names == ["Drug Alpha", "Drug B", "Drug C"]
Expand All @@ -173,19 +175,24 @@ def test_arms_delete(long_project):

assert len(response) == 2

arm_nums = list(response.keys())
arm_names = list(response.values())
arm_nums = [arm["arm_num"] for arm in response]
arm_names = [arm["name"] for arm in response]

assert arm_nums == [1, 2]
assert arm_names == ["Drug Alpha", "Drug B"]


@pytest.mark.integration
def test_arms_import_override(long_project):
# Cache current events, so they can be restored for subsequent tests
current_events = long_project.export_events()

new_arms = [{"arm_num": 3, "name": "Drug C"}]
response = long_project.import_arms(new_arms)

assert response == 1
# Add event for new arm
new_event = [{"event_name": "new_event", "arm_num": "3"}]
response = long_project.import_events(new_event)

response = long_project.export_arms()

Expand All @@ -195,13 +202,18 @@ def test_arms_import_override(long_project):
response = long_project.import_arms(new_arms, override=1)

assert response == 2
# Confirm that there are no events associated with new override arms
with pytest.raises(RedcapError):
response = long_project.export_arms()

response = long_project.export_arms()
response = long_project.import_events(current_events)
assert response == 16

response = long_project.export_arms()
assert len(response) == 2

arm_nums = list(response.keys())
arm_names = list(response.values())
arm_nums = [arm["arm_num"] for arm in response]
arm_names = [arm["name"] for arm in response]

assert arm_nums == [1, 2]
assert arm_names == ["Drug A", "Drug B"]
Expand Down Expand Up @@ -233,6 +245,6 @@ def test_events_delete(long_project):

assert response == 1

response = long_project.export_arms()
response = long_project.export_events()

assert len(response) == 16

0 comments on commit 46bbf78

Please sign in to comment.