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

For every Project instance, create an Org instance #4613

Open
iaindillingham opened this issue Sep 18, 2024 · 0 comments
Open

For every Project instance, create an Org instance #4613

iaindillingham opened this issue Sep 18, 2024 · 0 comments

Comments

@iaindillingham
Copy link
Member

#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:

@functional.cached_property
def org(self):
return self.orgs.filter(collaborations__is_lead=True).first()

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:

org = factory.PostGeneration(_project_collaboration_factory)

def _project_collaboration_factory(obj, create, extracted, **kwargs):
from . import ProjectCollaborationFactory
if not create or not extracted:
# Simple build, or nothing to add, do nothing.
return
extracted = extracted if isinstance(extracted, abc.Iterable) else [extracted]
# Add the iterable of groups using bulk addition
for org in extracted:
ProjectCollaborationFactory(org=org, project=obj, is_lead=True)

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.

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

No branches or pull requests

1 participant