Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests should be stateless and repeatable #76

Open
samamorgan opened this issue Sep 1, 2023 · 1 comment
Open

Tests should be stateless and repeatable #76

samamorgan opened this issue Sep 1, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@samamorgan
Copy link
Collaborator

samamorgan commented Sep 1, 2023

In its current form, the test suite requires some state to function. Patient IDs for instance live as strings in tests. This makes generating new VCR cassettes difficult. In the unfortunate event of a breaking API change, fixing this library would represent a significant amount of test refactoring.

The key indicator here is one should be able to delete all cassettes, run the entire test suite, and all new cassettes are regenerated without errors.

I propose that several fixtures be introduced to either get or create the necessary state on a Welkin test instance. For example, a Patient fixture could be made that records its own cassette:

conftest.py

# Note: This is not necessarily functional code, just illustrating an idea.
@pytest.fixture
def patient(client, vcr):
    create_kwargs = {
        "firstName": "Foo",
        "lastName": "Bar",
        "externalId": "welkin-health-test",
    }
    with vcr.use_cassette("patient_id"):
        for patient in client.Patients().get(paginate=True, size=2000):
            if patient.externalId == create_kwargs["externalId"]:
                return patient

        return client.Patient(**create_kwargs).create()


@pytest.fixture
def patient_id(patient):
    return patient.id

test_patients.py

# Refactored to use the new "patient_id" fixture
@pytest.mark.vcr
def test_patient_read(client, patient_id, vcr_cassette):
    patient = client.Patient(id=patient_id).get()

    assert isinstance(patient, Patient)
    assert patient.id == patient_id
    assert len(vcr_cassette) == 1
@samamorgan samamorgan added the enhancement New feature or request label Sep 1, 2023
@gone
Copy link
Member

gone commented Sep 1, 2023

I think this is a great idea - it acts as a test against the api as well since if that breaks the fixture would fall apart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants