Skip to content

Add tests for study state transitions #1833

@becky-gilbert

Description

@becky-gilbert

Description

We don't have a full set of tests to cover study state transitions and monitoring fields. While adding a feature to automatically pause studies when the response limit is reach, I wrote tests that revealed that studies can be auto-rejected even when the user did not change any of the monitoring fields. This is because our current tests that set study.state = "active" also all use G() and explicitly provide image=SimpleUploadedFile(...). With a real file, both the in-memory and DB-loaded ImageFieldFile have the same non-empty .name string, so the comparison works fine. But when a test uses minimal study creation (Study.objects.create() with only name, lab, study_type, and max_responses — leaving image unset), this triggers a mismatch due to Image = None (the in-memory default) vs '' (loaded from database).

This bug isn't a major practical issue since the image field is required in the form (even though Null is allowed in the model). But the fact that it went unnoticed shows that we don't have optimal test coverage for the check_modification_of_approved_study method and possibly other study states/transitions.

Metadata

Metadata

Assignees

Labels

Bug[Work Type] An issue with the program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions