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

Create Stripe customer factories, use in tests #634

Merged
merged 6 commits into from
Apr 27, 2023

Conversation

grahamalama
Copy link
Contributor

Ref: #633

Deletes these fixtures:

  • stripe_customer_data
  • raw_stripe_customer_data
  • contact_with_stripe_customer

In favor of factory usage in tests

Deletes these fixtures:
- stripe_customer_data
- raw_stripe_customer_data
- contact_with_stripe_customer

In favor of factory usage in tests
@grahamalama grahamalama requested a review from a team as a code owner April 14, 2023 19:42
@grahamalama grahamalama changed the title Stripe customer factories Create Stripe customer factories, use in tests Apr 14, 2023
@grahamalama grahamalama added the dev Enhancements to development environment label Apr 14, 2023
Copy link
Contributor

@bsieber-mozilla bsieber-mozilla left a comment

Choose a reason for hiding this comment

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

The job running on runner GitHub Actions 16 has exceeded the maximum execution time of 5 minutes.

Seems like the tests might've ran a little longer than normal? (Or maybe this was a CI-hiccup?)


Does this run long on local as well? If not we can maybe just up the CI-build time?

if not create:
return
if extracted:
FirefoxAccountFactory(email=self, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

missing return?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope -- since this is the EmailFactory, all we're doing here is creating the FirefoxAccount and associating it with this Email object. In a test, this would work fine:

email = EmailFactory()
dbsession.commit()
assert email.fxa ...

Unless you're saying that we should avoid the implicit return of None, in which case I could make that fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

I get it, email=self does it. Sorry for the confusion

model = models.FirefoxAccount

fxa_id = factory.LazyFunction(lambda: uuid4().hex)
primary_email = factory.SelfAttribute("email.primary_email")
Copy link
Contributor

Choose a reason for hiding this comment

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

👌
Shall we add a comment that this simulates the DB relationship?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious what you mean by "simulates"? By using this factory, we'll create an Email and FirefoxAccount object, and they'll be related through fxa_instance.email.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused by my own comment...

I didn't know about SelfAttribute and looked up its docs to understand how it was leveraged. I first understood that we were linking the two fields using this lazy attribute, as if they were linked by foreign keys in the DB.

But actually, I see that primary_email in the FirefoxAccount model is not linked to email.primary_email at all, they can be different AFAIU. So scratch that

tests/factories/models.py Outdated Show resolved Hide resolved
):
"""A Stripe Invoice and related objects can return the related email_id."""
customer = stripe_customer_factory(stripe_id=FAKE_STRIPE_CUSTOMER_ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we set the id here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While we're in the middle of conversion, there are still a few places where we have "magic" object IDs. In this case, the way we use raw_stripe_invoice_data assumes that there's a a customer whose ID is FAKE_STRIPE_CUSTOMER_ID. So for now, that's what we specify when we generate the Stripe customer, but in a follow-up PR, we'll hopefully be able to remove this.

@grahamalama
Copy link
Contributor Author

The job running on runner GitHub Actions 16 has exceeded the maximum execution time of 5 minutes.

Seems like the tests might've ran a little longer than normal? (Or maybe this was a CI-hiccup?)

Does this run long on local as well? If not we can maybe just up the CI-build time?

@bsieber-mozilla there does seem to be something wrong with the integration tests. I'll investigate further (#638)

@grahamalama grahamalama merged commit 364b2f0 into main Apr 27, 2023
@grahamalama grahamalama deleted the stripe-customer-factories branch April 27, 2023 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev Enhancements to development environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants