Skip to content

Conversation

@grahamalama
Copy link
Contributor

Factoryboy is a slight improvement over our DIY factory setup because it makes it easier to set "deep" attributes of objects.

Before

@pytest.fixture
def context_comment_example(
    webhook_user_factory,
    bug_factory,
    webhook_event_factory,
    action_context_factory,
    jira_context_factory,
) -> ActionContext:
    user = webhook_user_factory(login="[email protected]")
    comment = BugzillaWebhookComment.parse_obj({"number": 2, "body": "hello"})
    bug = bug_factory(
        see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
        comment=comment,
    )
    event = webhook_event_factory(target="comment", user=user)
    context = action_context_factory(
        operation=Operation.COMMENT,
        bug=bug,
        event=event,
        jira=jira_context_factory(issue=bug.extract_from_see_also()),
    )
    return context

After

@pytest.fixture
def context_comment_example(action_context_factory) -> ActionContext:
    return action_context_factory(
        operation=Operation.COMMENT,
        bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
        bug__with_comment=True,
        bug__comment__number=2,
        bug__comment__body="hello",
        event__target="comment",
        event__user__login="[email protected]",
        jira__issue="JBI-234",
    )

My hope is that this more ergonomic API will encourage using factories directly more often, rather than creating many one-off fixtures with slightly different attributes.

@grahamalama grahamalama requested a review from a team as a code owner July 28, 2023 12:08
Copy link
Contributor

@leplatrem leplatrem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat 💯

@grahamalama grahamalama merged commit 9964d28 into main Jul 28, 2023
@grahamalama grahamalama deleted the factoryboy branch July 28, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants