Skip to content

Use test client in tests#88

Merged
Pierlou merged 4 commits intomainfrom
refactor/tests-fake-client
Jan 8, 2026
Merged

Use test client in tests#88
Pierlou merged 4 commits intomainfrom
refactor/tests-fake-client

Conversation

@Pierlou
Copy link
Copy Markdown
Contributor

@Pierlou Pierlou commented Jan 8, 2026

Instead of running the app in the background, we start the app using TestServer and TestClient, which will allow us to patch the config before starting the app

@Pierlou Pierlou changed the title Use fake client in tests Use test client in tests Jan 8, 2026
Copy link
Copy Markdown
Contributor

@maudetes maudetes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very neat 👌

Comment thread tests/test_api.py
Comment on lines 334 to 337
rmock.head(
f"{PGREST_ENDPOINT}/migrations_csv",
f"{config.PGREST_ENDPOINT}/migrations_csv",
status=postgrest_resp_code,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this rmock?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say yes, we want to pretend Postgrest has not started, but we could stop mocking the case where Postgrest is in place, as it actually is. I'll try that

Copy link
Copy Markdown
Contributor Author

@Pierlou Pierlou Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning on:

@pytest.mark.parametrize(
    "params",
    [
        (False, ["errors"]),
        (True, ["status", "version", "uptime_seconds"]),
    ],
)
async def test_health(client, rmock, params):
    has_postgrest_started, expected_keys = params
    if not has_postgrest_started:
        rmock.head(
            f"{config.PGREST_ENDPOINT}/migrations_csv",
            status=503,
        )
    res = await client.get("/health/")
    assert res.status == 200 if has_postgrest_started else 503
    res_json = await res.json()
    assert all(key in res_json for key in expected_keys)

but the migrations_csv table is not set up in this project's container, so the case has_postgrest_started=True fails. So we either:

  • create the migrations_csv table in this project's setup
  • keep the current syntax with two mocks

(it also means that the /health/ endpoint is currently only working when tabular is ran on a "real" hydra db)
We can decide and potentially make these changes in a second PR as it would be quite a change on its own.

@Pierlou Pierlou merged commit db87c7e into main Jan 8, 2026
4 checks passed
@Pierlou Pierlou deleted the refactor/tests-fake-client branch January 8, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants