You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#4505 ensures that if a template is missing a variable, and if that template's SimpleTemplateResponse is rendered in a test (.render() or .rendered_content), then the test will fail 💥
There are, undoubtedly, cases where a template is really missing a variable (true positives). However, there are also cases where a template is missing a variable simply because the test context doesn't reflect the production context (false positives). Many of these cases involve the relationship between Project and Org through Project.org:
Yes, that's correct: the relationship isn't a ForeignKey on Project. Consequently, factory_boy, which we use to create the test context, doesn't instantiate an Org when it instantiates a Project. Brace yourself:
This means that to cajole factory_boy into instantiating an Org and a Project, we have to do something like ProjectFactory(org=OrgFactory()) or ProjectFactory(orgs=[OrgFactory()]). And this is both easy to forget and, when the tests fail, hard to interpret.
It would be much cleaner 🪥 if every time a Project was instantiated, then an Org was instantiated too.
The text was updated successfully, but these errors were encountered:
#4505 ensures that if a template is missing a variable, and if that template's
SimpleTemplateResponse
is rendered in a test (.render()
or.rendered_content
), then the test will fail 💥There are, undoubtedly, cases where a template is really missing a variable (true positives). However, there are also cases where a template is missing a variable simply because the test context doesn't reflect the production context (false positives). Many of these cases involve the relationship between
Project
andOrg
throughProject.org
:job-server/jobserver/models/project.py
Lines 201 to 203 in 8656ca1
Yes, that's correct: the relationship isn't a
ForeignKey
onProject
. Consequently, factory_boy, which we use to create the test context, doesn't instantiate anOrg
when it instantiates aProject
. Brace yourself:job-server/tests/factories/project.py
Line 33 in 8656ca1
job-server/tests/factories/project.py
Lines 8 to 19 in 8656ca1
This means that to cajole factory_boy into instantiating an
Org
and aProject
, we have to do something likeProjectFactory(org=OrgFactory())
orProjectFactory(orgs=[OrgFactory()])
. And this is both easy to forget and, when the tests fail, hard to interpret.It would be much cleaner 🪥 if every time a
Project
was instantiated, then anOrg
was instantiated too.The text was updated successfully, but these errors were encountered: