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

[ITAS] As a tester, I want to easily be able to create API responses from the API doc so that I don't have to craft fake response myself #32869

Closed
1 task
maxi297 opened this issue Nov 28, 2023 · 0 comments
Assignees

Comments

@maxi297
Copy link
Contributor

maxi297 commented Nov 28, 2023

Problem

Creating responses for the HTTP mock to return is cumbersome because most of the content of the response is not relevant to the tests and having this big blob of text in the test hinders readability. Having those in separate files is not that much better because you either end up with one file per test to manage (imagine if the response changes!!) or the specifics of the content of the file is not readable from the test. Hence, we want a expose only what is relevant to a test without having too much maintenance.

Proposed solution

Have an interface that only expose the important things. Domain wise for sources, it means where the records are in the response. For stripe specifically, there are other things:

  • how pagination is enabled
  • what are the ids of the records (this is important for pagination as well)

Hence, proposed interface is:

class RecordBuilder:
    def with_id(self, identifier: Any) -> "RecordBuilder":
        pass

    def with_cursor(self, cursor_value: Any) -> "RecordBuilder":
        pass

    def build(self) -> Dict[str, Any]:
        pass


class ResponseBuilder:
    def with_record(self, record: RecordBuilder) -> "ResponseBuilder":
        pass

    def with_pagination(self) -> "ResponseBuilder":
        pass

    def build(self) -> Dict[str, Any]:
        pass

In order to create those builders, the user should only have to

  • copy/paste a response (either from the API doc or from the actual server if our dataset allows it) in a file. Note that the response should have one record
  • provide the path to the records
  • provide the path of the id within the record
  • provide to logic with which the API defines is there are more pages (only if this logic is not based on the number of records)

It is fine to take a couple assumptions like "the files will always be in the same folder" (in the PoC, I used airbyte-integrations/connectors/source-<source name>/unit_tests/http/responses/<resource>.json)

Note on pagination

We could decide to be more generic by using with_field("key", "value"). It would probably also be more explicit in the tests as it would show exactly which field is impacted. However,

  • It is more flaky as if pagination change for an API, all those with_field will need to be updated (which should be almost all covered with a search and replace so I'm not support worried about this)
  • It allows for the devs to do more shenanigans

Acceptance Criteria

@maxi297 maxi297 self-assigned this Nov 29, 2023
maxi297 added a commit that referenced this issue Nov 30, 2023
maxi297 added a commit that referenced this issue Dec 5, 2023
maxi297 added a commit that referenced this issue Dec 5, 2023
… builder (#32983)

Co-authored-by: octavia-approvington <octavia-approvington@users.noreply.github.com>
@maxi297 maxi297 closed this as completed Dec 5, 2023
rishabh-cldcvr pushed a commit to ollionorg/datapipes-airbyte that referenced this issue Dec 14, 2023
…airbytehq#32869] response builder (airbytehq#32983)

Co-authored-by: octavia-approvington <octavia-approvington@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant