Skip to content

Tests: app-level test harness with fixtures #71

Closed

Description

@uniqueg

Why?

The FOCA upgrade (#65) and the access control work (#62) change how requests are routed, validated and authorized. The current tests cannot catch regressions there:

  • All tests call the controller functions or classes directly inside a bare Flask app context with a hand-built FOCA config. No test goes through the app, so OpenAPI validation, status codes, authentication and the error handlers in cloud_registry/exceptions.py are never exercised. app.py has no tests at all (Test: Write test cases for app.py #32), and [tool.coverage.run] omits it from coverage.
  • The same setup (build a Config, swap in a mongomock collection) is repeated in almost every test in tests/ga4gh/registry/ instead of using fixtures.
  • test_register_metadata_duplicate_keys_repeated (tests/ga4gh/registry/test_service.py:149-174) does not test what it says. It modifies a copy custom_config (setting length twice) but builds the app from the unmodified CUSTOM_CONFIG, and the mongomock collection has no unique index on id. It passes only because the first register_metadata() call adds an _id to the shared data dict, so the second call fails on a duplicate _id. This is how the ID-retry bug in Bug: service ID retry never generates a new ID #72 went unnoticed.

How?

  1. Add tests/conftest.py with fixtures for the base config, a mongomock database (with the unique indexes from config.yaml), and an app built with Foca(...).create_app() using connexion's test client.
  2. Mock token validation in the fixture (the same pattern as tests/test_access_control.py in feat!: add owner-based access control #66), so authenticated and unauthenticated requests can both be tested without a real identity provider.
  3. Add app-level tests for every endpoint: success paths, 404 for unknown IDs, an empty database, PUT create vs. replace, request validation errors (400), missing or invalid token (401), and the error response format.
  4. Test app.py startup (config loading, service-info registration) and remove it from the coverage omit list.
  5. Rewrite the duplicate-ID test so it actually exhausts the ID space (one-character IDs with a unique index), together with the fix in Bug: service ID retry never generates a new ID #72.
  6. Convert the existing unit tests to the shared fixtures.

Acceptance criteria

Closes #32 and #40.

Dependencies: #69. Do together with #72.


Part of the ELIXIR Compute Platform WP4 sprint (M&Ds due end of December 2026).

Activity

  1. added
    priority: high
    type: testing
    workload: days
    ecp-wp4: M4.1
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ecp-wp4: M4.1priority: hightype: testingworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions