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

Overhaul test suite with fixtures #2675

Commits on Sep 24, 2024

  1. Replace create-db.sh with PostgreSQL fixtures

    This creates a PostgreSQL fixture that can be depended on by tests that
    require a running PostgreSQL server with the NAV database to be present.
    
    The fixture will work with externally set up PostgreSQL servers, like in
    the case of GitHub Actions, while it can also provision a PostgreSQL
    server with the NAV schema using Docker if run locally.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    45ac3c3 View commit details
    Browse the repository at this point in the history
  2. Make other database fixtures dependent on Postgres

    This ensures any tests that rely on the various pre-existing db-related
    fixtures will have a running PostgreSQL server available.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    b1dd6ea View commit details
    Browse the repository at this point in the history
  3. Make DjangoTransactionTestCase depend on postgres

    This ensures the postgres fixture is started for all tests that inherit
    from DjangoTransactionTestCase
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    1e040a7 View commit details
    Browse the repository at this point in the history
  4. Inherit DjangoTransactionTestCase

    Change TestCase implementations that should really be transactional test
    cases (which in turn ensures they have PostgreSQL available through the
    postgres fixture, and that transactions are properly rolled back after
    the tests have run)
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    572ca4d View commit details
    Browse the repository at this point in the history
  5. Make tests properly depend on postgresql

    Declares a dependency on the postgresql fixture to ensure the NAV
    database is actually available for these tests
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    90020f9 View commit details
    Browse the repository at this point in the history
  6. Make client test fixture depend on postgresql

    This ensures that any test that depends on a logged in web client also
    automatically depends on having the NAV database running.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    03113bc View commit details
    Browse the repository at this point in the history
  7. Make snmpsim fixture work portably

    This ensure the snmpsim fixture can run both on Linux and MacOS, by
    replacing Linux specific parts (like looking at /proc/net/udp).
    
    This slightly changes the logic of verifying whether the snmpsimd
    process is up and running before yielding the fixture value: Instead of
    waiting for something to appear to listen to port 1024, this verifies
    the presence of the SNMP agent by performing an actual SNMP query.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    12eee6e View commit details
    Browse the repository at this point in the history
  8. Move imports from global to local

    These imports made the entire test module depend on the PostgreSQL
    database actually running. Moving the imports to be local to the
    tests (that depend directly or indirectly) on the postgresql fixture
    ensures that the imports only take place after PostgreSQL is actually
    running.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    449c586 View commit details
    Browse the repository at this point in the history
  9. Add TODO for the admin_navlet fixture

    The admin_navlet fixture is dynamic/parametrized, which is why its
    implementation is a bit weird. Unfortunately, the tests that depend on
    it currently fail under the new regime of the postgresql fixture. Adding
    this note so we know where to go back and fix it.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    cf45515 View commit details
    Browse the repository at this point in the history
  10. "Un-parametrize" test_get_navlet_should_return_200

    While pytest can accomplish a lot of exciting things, it cannot use
    fixtures as input to test parametrization.  While can make a test
    depend on a fixture for getting a postgresql instance, the test
    discovery phase that generates the tests cannot.
    
    I.e. we cannot get our test parameters from a database unless the
    database was already up and running when the test discovery phase
    started.  Sad, but true,.
    
    This changes the navlet test to iterate over the available admin navlets
    itself.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    9f09f5a View commit details
    Browse the repository at this point in the history
  11. Properly mark tests as wanting postgresql

    These tests would only work incidentally; i.e. if they ran after
    another test that depended on the postgresql fixture
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    1088529 View commit details
    Browse the repository at this point in the history
  12. Add usage tips to docstring

    The postgresql fixture is fine to depend on if you just need a
    database to be present.  But if you need to write data during the test,
    you should probably use the db fixture.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    ea7c700 View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    4a0198e View commit details
    Browse the repository at this point in the history
  14. Leave out optional requirements from test env

    For now, at least.  If the Open-LDAP libraries aren't available locally,
    the test suite will fail because python-ldap will not build.
    lunkwill42 committed Sep 24, 2024
    Configuration menu
    Copy the full SHA
    ee65d2c View commit details
    Browse the repository at this point in the history