Skip to content

Fix the test suite - #241

Open
joelhaasnoot wants to merge 1 commit into
masterfrom
fix/tests
Open

Fix the test suite#241
joelhaasnoot wants to merge 1 commit into
masterfrom
fix/tests

Conversation

@joelhaasnoot

Copy link
Copy Markdown
Contributor

The suite has not run in a long time. Test discovery itself was broken: openebs/tests/__init__.py and kv1/tests/__init__.py imported their modules by hand through loader.find_module(...).load_module(...), and Python 3.12 removed find_module — so the whole suite died at import and zero tests ran. Django has discovered test*.py on its own since 1.6, so the initialisers can simply be empty.

With discovery working, 24 of 36 tests failed. 40 tests now run and pass.

Five real bugs the tests could not report

Where Bug
openebs/models.py:345 Kv15Scenario.delete_all() filtered on messageendtime__gt=now — the function, never called. Deleting a planned scenario raised TypeError.
ferry/.../sendkv6.py:49,69 msg.delay > 0 on a nullable field, so a ferry message without a delay crashed the command. The init branch at line 32 already guarded for None; two of three places forgot.
utils/views.py:88 get_pushers() raised ImproperlyConfigured when any subscriber lacked the message type, and ndovloket_rig has no KV6 endpoint — so Kv6PushMixin could not even be imported. Now skips subscribers that do not take the type.
templates/xml/kv17journey.xml:50 mutation > 0 or shorten > 0 and not is_recoveredand binds tighter than or, so the not is_recovered guard never applied to mutation messages and a recover still emitted a mutation-message block.
.../verify_messages.py:99 KV8 deletes were matched with get_or_create() on the KV8 identity, but updating a message leaves the superseded version behind carrying that same identity, so the lookup raised MultipleObjectsReturned. Now matches the most recent one.

The last two change what goes out to subscribers, so they deserve a careful look. For the KV17 one the expected-output fixture already documented the intended behaviour (no mutation block on recover), which is what convinced me the precedence was accidental.

The rest is fixture rot

Tests written against behaviour that has since moved on:

  • stops are matched by QuayCode now, not timingpointcode, and message identity moved to OriginalMessageCode* — the KV8 rows in test_command_verify predate both
  • mutation messages moved to their own Kv17MutationMessage model; the tests still built Kv17StopChange(type=5), which no longer feeds the template
  • KV17 cancels gained showcancelledtrip and autorecover (Features showcancelled & autorecover #214) — added to the expected XML
  • import_rid reads bison_id and quaycoderef; the test CSV still used operator_id and omitted the quay column
  • SUBREASONTYPE gained an entry, so SUBREASONTYPE[1][0] no longer matched the literal in the expected XML — pinned to the literal instead
  • assertEquals and unittest.test are gone in Python 3.12

Testing

manage.py test40 tests, OK, run twice. Also re-ran the app smoke checks afterwards, since this touches the KV17 template and three commands: login plus /bericht, /kaart, /haltes.geojson, /stop/search.json, /scenario, /ritaanpassing and /admin/ all still return 200.

🤖 Generated with Claude Code

The suite has not run in a while. Test discovery itself was broken:
openebs/tests and kv1/tests imported their modules by hand through
loader.find_module(), which Python 3.12 removed, so nothing ran at all.
Django discovers test*.py by itself, so the initialisers can be empty.

With discovery working, 24 of 36 tests failed. Most were stale fixtures,
but five were real bugs the tests had been unable to report:

- Kv15Scenario.delete_all() filtered on messageendtime__gt=now, passing
  the function instead of calling it, so deleting a planned scenario
  raised TypeError
- sendkv6 compared msg.delay > 0 on a nullable field in two of the three
  places it checks it, so a ferry message without a delay crashed the
  command. The init branch already guarded for None
- get_pushers() raised ImproperlyConfigured when any subscriber lacked
  the message type, and ndovloket_rig has no KV6 endpoint - so KV6 could
  not even be imported. Skip subscribers that do not take the type
- the KV17 journey template read
  "mutation > 0 or shorten > 0 and not is_recovered", and "and" binds
  tighter than "or", so a recover still emitted a mutation message block
- verify_messages matched KV8 deletes with get_or_create() on the KV8
  identity, but an updated message leaves the superseded version behind
  carrying that same identity, so the lookup raised
  MultipleObjectsReturned. Match the most recent one

The rest is fixture rot: stops are matched by QuayCode rather than
timingpointcode, message identity moved to OriginalMessageCode*, mutation
messages moved to their own model, KV17 cancels gained showcancelledtrip
and autorecover, import_rid reads bison_id, and assertEquals is gone in
Python 3.12.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant