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

Add infrastructure for test-helper methods #773

Merged
merged 10 commits into from
Mar 25, 2022
Merged

Conversation

pakrym-stripe
Copy link
Contributor

@pakrym-stripe pakrym-stripe commented Feb 24, 2022

When generating test_helper methods on a resource we group them into a TestHelpers nested class:

        @test_helpers
        @custom_method("pdf", http_verb="get")
        class Foo(CreateableAPIResource):
          OBJECT_NAME = "foo"
          def pdf(self, idempotency_key=None, **params):
               #...

          @custom_method("boop", http_verb="post")
          class TestHelpers(APIResourceTestHelpers):
            def boop(self, idempotency_key=None, **params):
              url = self.instance_url() + "/boop"
              headers = util.populate_headers(idempotency_key)
              self.resource.refresh_from(self.resource.request("post", url, params, headers))
              return self.resource

We need a few changes to infrastructure to get this working:

  1. APIResourceTestHelpers that contains class_url and instance_url generation logic (so test_helpers is included in URLs).
  2. test_helpers decorator to add test_helpers property to the resource class.
  3. custom_method logic adjusted to support having static method on a nested class.

@pakrym-stripe pakrym-stripe marked this pull request as ready for review February 24, 2022 18:42
@pakrym-stripe
Copy link
Contributor Author

pakrym-stripe commented Feb 24, 2022

re-r? @richardm-stripe

Copy link
Contributor

@richardm-stripe richardm-stripe left a comment

Choose a reason for hiding this comment

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

This looks good - let's wait to merge until the first test_helper method is released.

@dcr-stripe dcr-stripe self-requested a review March 25, 2022 17:15
Copy link
Contributor

@dcr-stripe dcr-stripe left a comment

Choose a reason for hiding this comment

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

Thanks Pavel! Mainly all minor comments about adding documentation, otherwise this LGTM!

PTAL @pakrym-stripe

@pakrym-stripe
Copy link
Contributor Author

PTAL @dcr-stripe ?

Copy link
Contributor

@dcr-stripe dcr-stripe left a comment

Choose a reason for hiding this comment

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

LGTM, this looks great! Thanks Pavel!

@pakrym-stripe pakrym-stripe merged commit 3c7be4b into master Mar 25, 2022
@remi-stripe remi-stripe deleted the pakrym/test-helpers branch September 28, 2023 23:12
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

Successfully merging this pull request may close these issues.

3 participants