Skip to content

Commit cc96709

Browse files
committed
✅ Add tests for survey return code
1 parent 5157ce5 commit cc96709

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

tests/data/doctest_project.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:redcap="https://projectredcap.org" xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 schema/odm/ODM1-3-1.xsd" ODMVersion="1.3.1" FileOID="000-00-0000" FileType="Snapshot" Description="doctest project" AsOfDateTime="2025-05-01T15:40:49" CreationDateTime="2025-05-01T15:40:49" SourceSystem="REDCap" SourceSystemVersion="15.2.1">
2+
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:redcap="https://projectredcap.org" xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 schema/odm/ODM1-3-1.xsd" ODMVersion="1.3.1" FileOID="000-00-0000" FileType="Snapshot" Description="doctest project" AsOfDateTime="2025-05-02T12:06:31" CreationDateTime="2025-05-02T12:06:31" SourceSystem="REDCap" SourceSystemVersion="15.2.1">
33
<Study OID="Project.DoctestProject">
44
<GlobalVariables>
55
<StudyName>doctest project</StudyName>
@@ -52,7 +52,7 @@
5252
<redcap:SurveysGroup>
5353
<redcap:Surveys form_name="form_1" title="Form 1" instructions="&lt;p&gt;&lt;strong&gt;Please complete the survey below.&lt;/strong&gt;&lt;/p&gt;
5454
&lt;p&gt;Thank you!&lt;/p&gt;" offline_instructions="" acknowledgement="&lt;p&gt;&lt;strong&gt;Thank you for taking the survey.&lt;/strong&gt;&lt;/p&gt;
55-
&lt;p&gt;Have a nice day!&lt;/p&gt;" stop_action_acknowledgement="" stop_action_delete_response="0" question_by_section="0" display_page_number="0" question_auto_numbering="1" survey_enabled="1" save_and_return="0" save_and_return_code_bypass="0" logo="" hide_title="0" view_results="0" min_responses_view_results="10" check_diversity_view_results="0" end_survey_redirect_url="" survey_expiration="" promis_skip_question="0" survey_auth_enabled_single="0" edit_completed_response="0" hide_back_button="0" show_required_field_text="1" confirmation_email_subject="" confirmation_email_content="" confirmation_email_from="" confirmation_email_from_display="" confirmation_email_attach_pdf="0" confirmation_email_attachment="" text_to_speech="0" text_to_speech_language="en" end_survey_redirect_next_survey="0" end_survey_redirect_next_survey_logic="" theme="" text_size="1" font_family="16" theme_text_buttons="" theme_bg_page="" theme_text_title="" theme_bg_title="" theme_text_sectionheader="" theme_bg_sectionheader="" theme_text_question="" theme_bg_question="" enhanced_choices="0" repeat_survey_enabled="0" repeat_survey_btn_text="" repeat_survey_btn_location="HIDDEN" response_limit="" response_limit_include_partials="1" response_limit_custom_text="&lt;p&gt;Thank you for your interest; however, the survey is closed because the maximum number of responses has been reached.&lt;/p&gt;" survey_time_limit_days="" survey_time_limit_hours="" survey_time_limit_minutes="" email_participant_field="" end_of_survey_pdf_download="0" pdf_save_to_field="" pdf_save_to_event_id="" pdf_save_translated="0" pdf_auto_archive="0" pdf_econsent_version="" pdf_econsent_type="" pdf_econsent_firstname_field="" pdf_econsent_firstname_event_id="" pdf_econsent_lastname_field="" pdf_econsent_lastname_event_id="" pdf_econsent_dob_field="" pdf_econsent_dob_event_id="" pdf_econsent_allow_edit="1" pdf_econsent_signature_field1="" pdf_econsent_signature_field2="" pdf_econsent_signature_field3="" pdf_econsent_signature_field4="" pdf_econsent_signature_field5="" survey_width_percent="" survey_show_font_resize="1" survey_btn_text_prev_page="" survey_btn_text_next_page="" survey_btn_text_submit="" survey_btn_hide_submit="0" survey_btn_hide_submit_logic=""/>
55+
&lt;p&gt;Have a nice day!&lt;/p&gt;" stop_action_acknowledgement="" stop_action_delete_response="0" question_by_section="0" display_page_number="0" question_auto_numbering="1" survey_enabled="1" save_and_return="1" save_and_return_code_bypass="0" logo="" hide_title="0" view_results="0" min_responses_view_results="10" check_diversity_view_results="0" end_survey_redirect_url="" survey_expiration="" promis_skip_question="0" survey_auth_enabled_single="0" edit_completed_response="0" hide_back_button="0" show_required_field_text="1" confirmation_email_subject="" confirmation_email_content="" confirmation_email_from="" confirmation_email_from_display="" confirmation_email_attach_pdf="0" confirmation_email_attachment="" text_to_speech="0" text_to_speech_language="en" end_survey_redirect_next_survey="0" end_survey_redirect_next_survey_logic="" theme="" text_size="1" font_family="16" theme_text_buttons="" theme_bg_page="" theme_text_title="" theme_bg_title="" theme_text_sectionheader="" theme_bg_sectionheader="" theme_text_question="" theme_bg_question="" enhanced_choices="0" repeat_survey_enabled="0" repeat_survey_btn_text="" repeat_survey_btn_location="HIDDEN" response_limit="" response_limit_include_partials="1" response_limit_custom_text="&lt;p&gt;Thank you for your interest; however, the survey is closed because the maximum number of responses has been reached.&lt;/p&gt;" survey_time_limit_days="" survey_time_limit_hours="" survey_time_limit_minutes="" email_participant_field="" end_of_survey_pdf_download="0" pdf_save_to_field="" pdf_save_to_event_id="" pdf_save_translated="0" pdf_auto_archive="0" pdf_econsent_version="" pdf_econsent_type="" pdf_econsent_firstname_field="" pdf_econsent_firstname_event_id="" pdf_econsent_lastname_field="" pdf_econsent_lastname_event_id="" pdf_econsent_dob_field="" pdf_econsent_dob_event_id="" pdf_econsent_allow_edit="1" pdf_econsent_signature_field1="" pdf_econsent_signature_field2="" pdf_econsent_signature_field3="" pdf_econsent_signature_field4="" pdf_econsent_signature_field5="" survey_width_percent="" survey_show_font_resize="1" survey_btn_text_prev_page="" survey_btn_text_next_page="" survey_btn_text_submit="" survey_btn_hide_submit="0" survey_btn_hide_submit_logic=""/>
5656
</redcap:SurveysGroup>
5757
<redcap:SurveysQueueGroup>
5858
<redcap:SurveysQueue active="1" auto_start="0" condition_surveycomplete_survey_id="form_1" condition_surveycomplete_event_id="event_1_arm_1" condition_andor="AND" condition_logic="" event_id="event_1_arm_1" survey_id="form_1"/>
@@ -64,7 +64,7 @@
6464
<redcap:Reports title="Example Report" unique_report_name="R-139MKP9FXE" report_order="1" user_access="ALL" user_edit_access="ALL" description="&lt;p&gt;Example report for testing purposes&lt;/p&gt;" combine_checkbox_values="0" output_dags="0" output_survey_fields="0" output_missing_data_codes="0" remove_line_breaks_in_values="1" orderby_field1="record_id" orderby_sort1="ASC" orderby_field2="" orderby_sort2="" orderby_field3="" orderby_sort3="" advanced_logic=" ([event-name][field_1] = &quot;1&quot;)" filter_type="RECORD" dynamic_filter1="" dynamic_filter2="" dynamic_filter3="" hash="" short_url="" is_public="0" report_display_include_repeating_fields="1" report_display_header="BOTH" report_display_data="BOTH" limiter_logic=" ([event-name][field_1] = &quot;1&quot;)" redcap_reports_fields="record_id,checkbox_field" redcap_reports_filter_dags="" redcap_reports_filter_events="" ID="7bf21611f58ba575b08c16aa72a79f267d29309d"/>
6565
</redcap:ReportsGroup>
6666
</GlobalVariables>
67-
<MetaDataVersion OID="Metadata.DoctestProject_2025-05-01_1540" Name="doctest project" redcap:RecordIdField="record_id">
67+
<MetaDataVersion OID="Metadata.DoctestProject_2025-05-02_1206" Name="doctest project" redcap:RecordIdField="record_id">
6868
<Protocol>
6969
<StudyEventRef StudyEventOID="Event.event_1_arm_1" OrderNumber="1" Mandatory="No"/>
7070
<StudyEventRef StudyEventOID="Event.event_2_arm_1" OrderNumber="2" Mandatory="No"/>
@@ -148,7 +148,7 @@
148148
</CodeList>
149149
</MetaDataVersion>
150150
</Study>
151-
<ClinicalData StudyOID="Project.DoctestProject" MetaDataVersionOID="Metadata.DoctestProject_2025-05-01_1540">
151+
<ClinicalData StudyOID="Project.DoctestProject" MetaDataVersionOID="Metadata.DoctestProject_2025-05-02_1206">
152152
<SubjectData SubjectKey="1" redcap:RecordIdField="record_id">
153153
<StudyEventData StudyEventOID="Event.event_1_arm_1" StudyEventRepeatKey="1" redcap:UniqueEventName="event_1_arm_1">
154154
<FormData FormOID="Form.form_1" FormRepeatKey="1">

tests/data/test_long_project.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:redcap="https://projectredcap.org" xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 schema/odm/ODM1-3-1.xsd" ODMVersion="1.3.1" FileOID="000-00-0000" FileType="Snapshot" Description="Test Long Project" AsOfDateTime="2025-05-01T15:11:58" CreationDateTime="2025-05-01T15:11:58" SourceSystem="REDCap" SourceSystemVersion="15.2.1">
3-
<Study OID="Project.TestLongProject">
2+
<ODM xmlns="http://www.cdisc.org/ns/odm/v1.3" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:redcap="https://projectredcap.org" xsi:schemaLocation="http://www.cdisc.org/ns/odm/v1.3 schema/odm/ODM1-3-1.xsd" ODMVersion="1.3.1" FileOID="000-00-0000" FileType="Snapshot" Description="New Test Long Project" AsOfDateTime="2025-05-02T12:12:29" CreationDateTime="2025-05-02T12:12:29" SourceSystem="REDCap" SourceSystemVersion="15.2.1">
3+
<Study OID="Project.NewTestLongProject">
44
<GlobalVariables>
5-
<StudyName>Test Long Project</StudyName>
6-
<StudyDescription>This file contains the metadata, events, and data for REDCap project "Test Long Project".</StudyDescription>
7-
<ProtocolName>Test Long Project</ProtocolName>
5+
<StudyName>New Test Long Project</StudyName>
6+
<StudyDescription>This file contains the metadata, events, and data for REDCap project "New Test Long Project".</StudyDescription>
7+
<ProtocolName>New Test Long Project</ProtocolName>
88
<redcap:RecordAutonumberingEnabled>0</redcap:RecordAutonumberingEnabled>
99
<redcap:CustomRecordLabel></redcap:CustomRecordLabel>
1010
<redcap:SecondaryUniqueField></redcap:SecondaryUniqueField>
@@ -51,14 +51,14 @@
5151
<redcap:SurveysGroup>
5252
<redcap:Surveys form_name="contact_info" title="Contact Info" instructions="&lt;p&gt;&lt;strong&gt;Please complete the survey below.&lt;/strong&gt;&lt;/p&gt;
5353
&lt;p&gt;Thank you!&lt;/p&gt;" offline_instructions="" acknowledgement="&lt;p&gt;&lt;strong&gt;Thank you for taking the survey.&lt;/strong&gt;&lt;/p&gt;
54-
&lt;p&gt;Have a nice day!&lt;/p&gt;" stop_action_acknowledgement="" stop_action_delete_response="0" question_by_section="0" display_page_number="0" question_auto_numbering="1" survey_enabled="1" save_and_return="0" save_and_return_code_bypass="0" logo="" hide_title="0" view_results="0" min_responses_view_results="10" check_diversity_view_results="0" end_survey_redirect_url="" survey_expiration="" promis_skip_question="0" survey_auth_enabled_single="0" edit_completed_response="0" hide_back_button="0" show_required_field_text="1" confirmation_email_subject="" confirmation_email_content="" confirmation_email_from="" confirmation_email_from_display="" confirmation_email_attach_pdf="0" confirmation_email_attachment="" text_to_speech="0" text_to_speech_language="en" end_survey_redirect_next_survey="0" end_survey_redirect_next_survey_logic="" theme="" text_size="1" font_family="16" theme_text_buttons="" theme_bg_page="" theme_text_title="" theme_bg_title="" theme_text_sectionheader="" theme_bg_sectionheader="" theme_text_question="" theme_bg_question="" enhanced_choices="0" repeat_survey_enabled="0" repeat_survey_btn_text="" repeat_survey_btn_location="HIDDEN" response_limit="" response_limit_include_partials="1" response_limit_custom_text="&lt;p&gt;Thank you for your interest; however, the survey is closed because the maximum number of responses has been reached.&lt;/p&gt;" survey_time_limit_days="" survey_time_limit_hours="" survey_time_limit_minutes="" email_participant_field="" end_of_survey_pdf_download="0" pdf_save_to_field="" pdf_save_to_event_id="" pdf_save_translated="0" pdf_auto_archive="0" pdf_econsent_version="" pdf_econsent_type="" pdf_econsent_firstname_field="" pdf_econsent_firstname_event_id="" pdf_econsent_lastname_field="" pdf_econsent_lastname_event_id="" pdf_econsent_dob_field="" pdf_econsent_dob_event_id="" pdf_econsent_allow_edit="1" pdf_econsent_signature_field1="" pdf_econsent_signature_field2="" pdf_econsent_signature_field3="" pdf_econsent_signature_field4="" pdf_econsent_signature_field5="" survey_width_percent="" survey_show_font_resize="1" survey_btn_text_prev_page="" survey_btn_text_next_page="" survey_btn_text_submit="" survey_btn_hide_submit="0" survey_btn_hide_submit_logic=""/>
54+
&lt;p&gt;Have a nice day!&lt;/p&gt;" stop_action_acknowledgement="" stop_action_delete_response="0" question_by_section="0" display_page_number="0" question_auto_numbering="1" survey_enabled="1" save_and_return="1" save_and_return_code_bypass="0" logo="" hide_title="0" view_results="0" min_responses_view_results="10" check_diversity_view_results="0" end_survey_redirect_url="" survey_expiration="" promis_skip_question="0" survey_auth_enabled_single="0" edit_completed_response="0" hide_back_button="0" show_required_field_text="1" confirmation_email_subject="" confirmation_email_content="" confirmation_email_from="" confirmation_email_from_display="" confirmation_email_attach_pdf="0" confirmation_email_attachment="" text_to_speech="0" text_to_speech_language="en" end_survey_redirect_next_survey="0" end_survey_redirect_next_survey_logic="" theme="" text_size="1" font_family="16" theme_text_buttons="" theme_bg_page="" theme_text_title="" theme_bg_title="" theme_text_sectionheader="" theme_bg_sectionheader="" theme_text_question="" theme_bg_question="" enhanced_choices="0" repeat_survey_enabled="0" repeat_survey_btn_text="" repeat_survey_btn_location="HIDDEN" response_limit="" response_limit_include_partials="1" response_limit_custom_text="&lt;p&gt;Thank you for your interest; however, the survey is closed because the maximum number of responses has been reached.&lt;/p&gt;" survey_time_limit_days="" survey_time_limit_hours="" survey_time_limit_minutes="" email_participant_field="" end_of_survey_pdf_download="0" pdf_save_to_field="" pdf_save_to_event_id="" pdf_save_translated="0" pdf_auto_archive="0" pdf_econsent_version="" pdf_econsent_type="" pdf_econsent_firstname_field="" pdf_econsent_firstname_event_id="" pdf_econsent_lastname_field="" pdf_econsent_lastname_event_id="" pdf_econsent_dob_field="" pdf_econsent_dob_event_id="" pdf_econsent_allow_edit="1" pdf_econsent_signature_field1="" pdf_econsent_signature_field2="" pdf_econsent_signature_field3="" pdf_econsent_signature_field4="" pdf_econsent_signature_field5="" survey_width_percent="" survey_show_font_resize="1" survey_btn_text_prev_page="" survey_btn_text_next_page="" survey_btn_text_submit="" survey_btn_hide_submit="0" survey_btn_hide_submit_logic=""/>
5555
</redcap:SurveysGroup>
5656
<redcap:SurveysQueueGroup>
5757
<redcap:SurveysQueue active="1" auto_start="0" condition_surveycomplete_survey_id="contact_info" condition_surveycomplete_event_id="enrollment_arm_1" condition_andor="AND" condition_logic="" event_id="enrollment_arm_1" survey_id="contact_info"/>
5858
<redcap:SurveysQueue active="1" auto_start="0" condition_surveycomplete_survey_id="contact_info" condition_surveycomplete_event_id="enrollment_arm_2" condition_andor="AND" condition_logic="" event_id="enrollment_arm_2" survey_id="contact_info"/>
5959
</redcap:SurveysQueueGroup>
6060
</GlobalVariables>
61-
<MetaDataVersion OID="Metadata.TestLongProject_2025-05-01_1511" Name="Test Long Project" redcap:RecordIdField="study_id">
61+
<MetaDataVersion OID="Metadata.NewTestLongProject_2025-05-02_1212" Name="New Test Long Project" redcap:RecordIdField="study_id">
6262
<Protocol>
6363
<StudyEventRef StudyEventOID="Event.enrollment_arm_1" OrderNumber="1" Mandatory="No"/>
6464
<StudyEventRef StudyEventOID="Event.dose_1_arm_1" OrderNumber="2" Mandatory="No"/>
@@ -1180,7 +1180,7 @@
11801180
</CodeList>
11811181
</MetaDataVersion>
11821182
</Study>
1183-
<ClinicalData StudyOID="Project.TestLongProject" MetaDataVersionOID="Metadata.TestLongProject_2025-05-01_1511">
1183+
<ClinicalData StudyOID="Project.NewTestLongProject" MetaDataVersionOID="Metadata.NewTestLongProject_2025-05-02_1212">
11841184
<SubjectData SubjectKey="1" redcap:RecordIdField="study_id">
11851185
<StudyEventData StudyEventOID="Event.enrollment_arm_1" StudyEventRepeatKey="1" redcap:UniqueEventName="enrollment_arm_1">
11861186
<FormData FormOID="Form.demographics" FormRepeatKey="1">

tests/integration/test_long_project.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def test_export_survey_access_code(long_project):
3939
assert len(code) == 9
4040

4141

42+
@pytest.mark.integration
43+
def test_export_survey_return_code(long_project):
44+
code = long_project.export_survey_return_code(
45+
record="1", instrument="contact_info", event="enrollment_arm_1"
46+
)
47+
assert len(code) == 8
48+
49+
4250
@pytest.mark.integration
4351
def test_survey_participant_export(long_project):
4452
data = long_project.export_survey_participant_list(

tests/unit/callback_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,22 @@ def handle_long_project_survey_access_code_request(**kwargs) -> Any:
825825
return (201, headers, resp)
826826

827827

828+
def handle_long_project_survey_return_code_request(**kwargs) -> Any:
829+
"""Get the survey return code for a record and instrument and event"""
830+
data = kwargs["data"]
831+
headers = kwargs["headers"]
832+
resp = None
833+
834+
if (
835+
"test" in data.get("instrument")
836+
and "raw" in data.get("event")
837+
and "1" in data.get("record")
838+
):
839+
resp = "AAAAAAAA"
840+
841+
return (201, headers, resp)
842+
843+
828844
def get_simple_project_request_handler(request_type: str) -> Callable:
829845
"""Given a request type, extract the handler function"""
830846
handlers_dict = {
@@ -870,6 +886,7 @@ def get_long_project_request_handler(request_type: str) -> Callable:
870886
"surveyLink": handle_long_project_survey_link_request,
871887
"surveyQueueLink": handle_long_project_survey_queue_link_request,
872888
"surveyAccessCode": handle_long_project_survey_access_code_request,
889+
"surveyReturnCode": handle_long_project_survey_return_code_request,
873890
"version": handle_long_project_version_request,
874891
}
875892

tests/unit/test_long_project.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ def test_export_survey_access_code(long_project):
8888
assert len(res) == 9
8989

9090

91+
def test_export_survey_return_code(long_project):
92+
res = long_project.export_survey_return_code(
93+
instrument="test", record="1", event="raw"
94+
)
95+
assert len(res) == 8
96+
97+
9198
def test_metadata_import_handles_api_error(long_project):
9299
metadata = long_project.export_metadata()
93100

0 commit comments

Comments
 (0)