Skip to content

Commit

Permalink
Merge pull request #2 from redcap-tools/fix-tests-for-add-instrument-…
Browse files Browse the repository at this point in the history
…methods

Fix tests for add instrument methods
  • Loading branch information
patking02 authored Nov 3, 2023
2 parents 0d35698 + 155a7bb commit 4e81549
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
poetry install -E data_science
- name: Run doctests
# Forks can't run doctests, requires super user token
if: github.actor == 'pwildenhain'
if: github.triggering_actor == 'pwildenhain'
run: |
poetry run pytest --doctest-only --doctest-plus
- name: Run tests
Expand Down
6 changes: 3 additions & 3 deletions redcap/methods/instruments.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def export_instruments(
Examples:
>>> proj.export_instruments()
[{'instrument_name': 'demo', 'instrument_label': 'Demographics'}]
[{'instrument_name': 'form_1', 'instrument_label': 'Form 1'}]
"""
payload = self._initialize_payload(
content="instrument", format_type=format_type
Expand Down Expand Up @@ -69,11 +69,11 @@ def export_pdf(
If True, then the PDF will be exported in compact display mode.
Returns:
Content of the file
Content of the file and dictionary of useful metadata
Examples:
>>> proj.export_pdf()
b'%PDF-1.3\n3 0 obj\n...'
(b'%PDF-1.3\\n3 0 obj\\n..., {...})
"""
# load up payload
payload = self._initialize_payload(content="pdf", return_format_type="json")
Expand Down
17 changes: 13 additions & 4 deletions tests/integration/test_long_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,12 @@ def test_arms_delete(long_project):

@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()
# Cache current events, so they can be restored for subsequent tests, because arms, events,
# and mappings are deleted when the 'override' parameter is used.
state_dict = {
"events": long_project.export_events(),
"form_event_map": long_project.export_instrument_event_mappings(),
}

new_arms = [{"arm_num": 3, "name": "Drug C"}]
response = long_project.import_arms(new_arms)
Expand All @@ -206,9 +210,14 @@ def test_arms_import_override(long_project):
with pytest.raises(RedcapError):
response = long_project.export_arms()

response = long_project.import_events(current_events)
response = long_project.import_events(state_dict["events"])
assert response == 16

response = long_project.import_instrument_event_mappings(
state_dict["form_event_map"]
)
assert response == 44

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

Expand Down Expand Up @@ -252,7 +261,7 @@ def test_events_delete(long_project):

@pytest.mark.integration
def test_export_instruments(long_project):
response = long_project.export_events()
response = long_project.export_instruments()
assert len(response) == 9


Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_simple_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def test_export_field_names_df(simple_project):

@pytest.mark.integration
def test_export_instruments(simple_project):
events = simple_project.export_events()
assert len(events) == 1
instruments = simple_project.export_instruments()
assert len(instruments) == 1


@pytest.mark.integration
Expand Down

0 comments on commit 4e81549

Please sign in to comment.