From 253f2cee388568ac162e31bbfb10eb7a688fdc90 Mon Sep 17 00:00:00 2001 From: Paul Wildenhain Date: Thu, 31 Mar 2022 14:00:01 -0400 Subject: [PATCH 1/2] :memo: Add missing definition for return_format_type --- redcap/methods/records.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/redcap/methods/records.py b/redcap/methods/records.py index 1b96df4..8c260f6 100644 --- a/redcap/methods/records.py +++ b/redcap/methods/records.py @@ -426,6 +426,8 @@ def delete_records( Args: records: List of record IDs to delete from the project + return_format_type: + Response format. By default, response will be json-decoded. Returns: Union[int, str]: Number of records deleted From cf3b5d8722afec40c8289c0298b860edb6a2060c Mon Sep 17 00:00:00 2001 From: Paul Wildenhain Date: Thu, 31 Mar 2022 14:20:02 -0400 Subject: [PATCH 2/2] :white_check_mark: Add return_format_type tests --- tests/integration/test_simple_project.py | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/integration/test_simple_project.py b/tests/integration/test_simple_project.py index 4c08f9d..468e8d7 100644 --- a/tests/integration/test_simple_project.py +++ b/tests/integration/test_simple_project.py @@ -2,6 +2,8 @@ # pylint: disable=missing-function-docstring import os +from io import StringIO + import pandas as pd import pytest import semantic_version @@ -57,6 +59,32 @@ def test_import_and_delete_records(simple_project): assert res == 3 +@pytest.mark.integration +@pytest.mark.parametrize( + ["return_format_type", "import_output", "delete_output"], + [ + ("csv", "3", "3"), + ("xml", '3', "3"), + ], +) +def test_import_and_delete_records_non_json( + simple_project, return_format_type, import_output, delete_output +): + new_record_ids = ["4", "5", "6"] + test_records_csv = "record_id\n" + "\n".join(new_record_ids) + test_records_df = pd.read_csv(StringIO(test_records_csv)) + + res = simple_project.import_records( + test_records_df, import_format="df", return_format_type=return_format_type + ) + assert res == import_output + + res = simple_project.delete_records( + new_record_ids, return_format_type=return_format_type + ) + assert res == delete_output + + @pytest.mark.integration def test_import_df_no_index(simple_project): # declare df_kwargs without specifying index, which returns a df with no index