Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion redcap/methods/data_access_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def export_dags(
format_type: Literal["json", "csv", "xml", "df"] = "json",
df_kwargs: Optional[Dict[str, Any]] = None,
):
# pylint: disable=line-too-long
"""
Export the DAGs of the Project

Expand All @@ -44,8 +45,9 @@ def export_dags(

Examples:
>>> proj.export_dags()
[{'data_access_group_name': 'Test DAG', 'unique_group_name': 'test_dag'}]
[{'data_access_group_name': 'Test DAG', 'unique_group_name': 'test_dag', 'data_access_group_id': ...}]
"""
# pylint:enable=line-too-long
payload = self._initialize_payload(content="dag", format_type=format_type)
return_type = self._lookup_return_type(format_type, request_type="export")
response = self._call_api(payload, return_type)
Expand Down
5 changes: 2 additions & 3 deletions redcap/methods/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ def _backfill_fields(self, fields: List[str], forms: List[str]):
Returns: A list of all fields to request, including
self.def_field (record_id) and the "form_complete" fields
"""
form_complete_fields = [f"{ form }_complete" for form in self.forms]
if forms and not fields:
return form_complete_fields + [self.def_field]
return [f"{ form }_complete" for form in forms] + [self.def_field]

if fields and self.def_field not in fields:
return fields + [self.def_field]

if not fields:
return self.field_names + form_complete_fields
return self.field_names + [f"{ form }_complete" for form in self.forms]

return fields

Expand Down
2 changes: 1 addition & 1 deletion redcap/methods/user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def export_user_role_assignment(

Examples:
>>> proj.export_user_role_assignment()
[{'username': ..., 'unique_role_name': ''}]
[{'username': ..., 'unique_role_name': '', 'data_access_group': ''}]
"""
payload = self._initialize_payload(
content="userRoleMapping", format_type=format_type
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/test_long_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,28 @@ def test_import_export_repeating_forms(long_project):
to_import=rep, import_format=format_type
)
assert res == 1


@pytest.mark.integration
def test_limit_export_records_forms_and_fields(long_project):
# only request forms
records_df = long_project.export_records(
forms=["demographics", "baseline_data"], format_type="df"
)
complete_cols = [col for col in records_df.columns if col.endswith("_complete")]

assert long_project.def_field in records_df.index.names
assert complete_cols == ["demographics_complete", "baseline_data_complete"]
# only request fields
records_df = long_project.export_records(
fields=["study_comments"], format_type="df"
)
assert long_project.def_field in records_df.index.names
# request forms and fields
records_df = long_project.export_records(
forms=["baseline_data"], fields=["study_comments"], format_type="df"
)
complete_cols = [col for col in records_df.columns if col.endswith("_complete")]

assert long_project.def_field in records_df.index.names
assert complete_cols == ["baseline_data_complete"]