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

Chore: add new test using source-pokeapi and custom components.py #317

Merged
merged 4 commits into from
Feb 6, 2025

Conversation

aaronsteers
Copy link
Contributor

@aaronsteers aaronsteers commented Feb 5, 2025

Resolves: https://github.com/airbytehq/airbyte-internal-issues/issues/11582

Adds a modified version of source-pokeapi. This leverages a custom components.py file without changing any behavior. This removes the need for the creds that previously were needed by our the-guardian-api test that this one replaces.

Summary by CodeRabbit

  • New Features

    • Introduced a configurable Pokémon API integration with enhanced testing features that run quickly and without credentials.
  • Documentation

    • Updated guidance for the new Pokémon API testing setup.
    • Removed documentation related to the former Guardian API integration.
  • Chores

    • Cleaned up legacy components and configurations associated with the Guardian API.
  • Tests

    • Streamlined unit tests by simplifying configuration inputs and improving error simulation.

@aaronsteers aaronsteers changed the title Aj/chore/use-custom-pokeapi-components-py Create new test using source-pokeapi and custom components.py Feb 5, 2025
@aaronsteers
Copy link
Contributor Author

aaronsteers commented Feb 5, 2025

/autofix

Auto-Fix Job Info

This job attempts to auto-fix any linting or formating issues. If any fixes are made,
those changes will be automatically committed and pushed back to the PR.

Note: This job can only be run by maintainers. On PRs from forks, this command requires
that the PR author has enabled the Allow edits from maintainers option.

PR auto-fix job started... Check job output.

✅ Changes applied successfully.

Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new integration for the Pokémon API using custom components and update the associated test suite. Two custom component modules are added—one for normal execution and one to simulate failure—along with a new declarative manifest and configuration file. In parallel, obsolete files related to The Guardian API (including README, components, manifest, and configuration files) have been removed. Additionally, test functions have been refactored to remove the needs_secrets parameter and encapsulate message reading via a helper function.

Changes

File(s) Summary
unit_tests/.../source_pokeapi_w_components_py/README.md Added a "PokeAPI with Custom components.py API Tests" section for quick, no-credential testing.
unit_tests/.../source_pokeapi_w_components_py/components.py, components_failing.py Introduced custom components: normal components (IntentionalException, MyCustomExtractor) and a failing variant with an overridden extract_records method raising an exception.
unit_tests/.../source_pokeapi_w_components_py/manifest.yaml Created a declarative manifest for Pokémon API integration outlining streams, requester settings, schema, and connection specifications.
unit_tests/.../source_pokeapi_w_components_py/valid_config.yaml Added a configuration entry with "start_date": "2024-01-01" and "pokemon": "pikachu".
unit_tests/.../source_the_guardian_api/{README.md, components.py, components_failing.py, manifest.yaml, valid_config.yaml} Removed files related to The Guardian API integration and its test setup.
unit_tests/.../test_source_declarative_w_custom_components.py Refactored tests by removing the needs_secrets parameter and replacing direct iteration with a helper function for message reading.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant H as _read_fn
    participant S as Source Integration
    participant C as Custom Component
  
    T->>H: Initiate sync process
    H->>S: Request data extraction
    alt Successful extraction
        S->>C: Invoke extraction logic
        C-->>S: Return records
    else Failing extraction
        S->>C: Invoke extraction logic
        C-->>S: Raise IntentionalException
    end
    S-->>H: Deliver messages or error
    H-->>T: Provide output
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • maxi297 - wdyt?
  • aldogonzalez8 - wdyt?
  • bnchrch - wdyt?

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (13)
unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/components_failing.py (3)

19-24: LGTM! Well-structured implementation for testing error scenarios.

The implementation effectively simulates failure scenarios with proper type hints and clear method override.

Hey, would you like to add a docstring to the extract_records method explaining its purpose? For example:

 def extract_records(
     self,
     response: requests.Response,
 ) -> Iterable[MutableMapping[Any, Any]]:
+    """Override to simulate failure by raising IntentionalException."""
     raise IntentionalException

wdyt?


15-16: Consider sharing the exception class.

Since this exception class is identical to the one in components.py, should we consider moving it to a shared module? wdyt?


19-24: Consider adding return type hint to extract_records?

The implementation looks good for testing failure scenarios! Would you consider adding a return type hint to make the code more maintainable, wdyt?

    def extract_records(
        self,
        response: requests.Response,
-    ) -> Iterable[MutableMapping[Any, Any]]:
+    ) -> Iterable[MutableMapping[str, Any]]:
        raise IntentionalException
unit_tests/source_declarative_manifest/test_source_declarative_w_custom_components.py (3)

276-285: LGTM! Clean refactoring of message reading logic.

The helper function _read_fn nicely encapsulates the message reading logic, improving code readability.

Hey, would you like to add a docstring to the _read_fn helper function? For example:

 def _read_fn(*args, **kwargs):
+    """Helper function to read and validate messages from the source."""
     msg_iterator = source.read(
         logger=logging.getLogger(),
         config=py_components_config_dict,
         catalog=configured_catalog,
         state=None,
     )
     for msg in msg_iterator:
         assert msg
     return

wdyt?


276-285: Consider adding docstring to the helper function.

The helper function _read_fn encapsulates message reading logic nicely. Should we add a docstring to explain its purpose? wdyt?


276-291: Consider extracting the read function to improve reusability?

The _read_fn helper looks good! Would you consider extracting it to a standalone function to improve reusability across test cases, wdyt?

+def read_messages(source: ManifestDeclarativeSource, config: dict, catalog: ConfiguredAirbyteCatalog) -> None:
+    msg_iterator = source.read(
+        logger=logging.getLogger(),
+        config=config,
+        catalog=catalog,
+        state=None,
+    )
+    for msg in msg_iterator:
+        assert msg
unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/manifest.yaml (6)

976-980: Consider defining a more specific schema for Pokemon data.

The current schema allows any properties without validation. Would you like to define specific properties that you expect from the PokeAPI response? This would help catch data structure changes early.

For example:

 schemas:
   pokemon:
     type: object
     $schema: http://json-schema.org/draft-07/schema#
-    properties: {}
+    properties:
+      id:
+        type: integer
+        description: The unique identifier of the Pokemon
+      name:
+        type: string
+        description: The name of the Pokemon
+      base_experience:
+        type: integer
+        description: The base experience gained for defeating this Pokemon
+      height:
+        type: integer
+        description: The height of this Pokemon in decimetres
+      weight:
+        type: integer
+        description: The weight of this Pokemon in hectograms
     additionalProperties: true

wdyt?


37-38: Consider using HTTPS for the base URL.

The base URL is using HTTP. Would you like to update it to use HTTPS for better security?

-    url_base: https://pokeapi.co/api/v2/pokemon
+    url_base: https://pokeapi.co/api/v2/pokemon

wdyt?


36-38: Consider adding rate limiting.

Since we're using a public API, should we add rate limiting configuration to be a good API citizen? wdyt?


43-960: Consider organizing Pokemon names.

The Pokemon list is comprehensive but quite long. Should we consider moving it to a separate file for better maintainability? wdyt?


962-980: Consider defining schema properties.

The schema allows additional properties but has no defined properties. Should we define some common Pokemon properties for better documentation? wdyt?


975-980: Consider adding schema properties for better type safety?

The schema looks minimal. Would you consider adding properties to define the expected structure of Pokemon data, wdyt? This could help catch data inconsistencies early.

   pokemon:
     type: object
     $schema: http://json-schema.org/draft-07/schema#
-    properties: {}
+    properties:
+      id:
+        type: integer
+      name:
+        type: string
+      height:
+        type: integer
+      weight:
+        type: integer
+      base_experience:
+        type: integer
     additionalProperties: true
unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/components.py (1)

14-20: Consider adding type hints to improve code clarity?

The class looks good! Would you consider adding type hints to make the code more maintainable, wdyt?

-class MyCustomExtractor(DpathExtractor):
+class MyCustomExtractor(DpathExtractor[Any, Any]):
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca68c5c and b958d80.

📒 Files selected for processing (12)
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/README.md (1 hunks)
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/components.py (1 hunks)
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/components_failing.py (1 hunks)
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/manifest.yaml (1 hunks)
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/valid_config.yaml (1 hunks)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/.gitignore (0 hunks)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/README.md (0 hunks)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/components.py (0 hunks)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/components_failing.py (0 hunks)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/manifest.yaml (0 hunks)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/valid_config.yaml (0 hunks)
  • unit_tests/source_declarative_manifest/test_source_declarative_w_custom_components.py (5 hunks)
💤 Files with no reviewable changes (6)
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/valid_config.yaml
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/README.md
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/.gitignore
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/components.py
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/manifest.yaml
  • unit_tests/source_declarative_manifest/resources/source_the_guardian_api/components_failing.py
✅ Files skipped from review due to trivial changes (2)
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/README.md
  • unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/valid_config.yaml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
🔇 Additional comments (8)
unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/components_failing.py (2)

1-13: LGTM! Well-organized imports with copyright notice.

The imports are comprehensive and properly organized.


19-24: LGTM! Clear failing behavior implementation.

The failing behavior is implemented in a straightforward way by raising the exception.

unit_tests/source_declarative_manifest/test_source_declarative_w_custom_components.py (3)

89-117: LGTM! Clean config function update.

The function has been simplified by removing the needs_secrets parameter, making it more focused.


287-291: LGTM! Clear error handling.

The error handling is straightforward and matches the expected behavior.


89-117: LGTM! Clean refactor of the configuration function.

The function has been simplified by removing the needs_secrets parameter and updating the connector directory path. The implementation is clean and well-structured.

unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/manifest.yaml (2)

10-34: LGTM! Well-structured stream definition.

The stream definition is clear with proper references and configurations.


1-39: LGTM! Well-structured stream configuration.

The stream configuration is clean and properly references the custom components. The base URL and path configuration look good.

unit_tests/source_declarative_manifest/resources/source_pokeapi_w_components_py/components.py (1)

10-11: LGTM! Clear and purposeful exception class.

The docstring clearly explains the purpose of this exception class.

@aaronsteers aaronsteers changed the title Create new test using source-pokeapi and custom components.py Chore: add new test using source-pokeapi and custom components.py Feb 6, 2025
@aaronsteers aaronsteers merged commit e38f914 into main Feb 6, 2025
19 of 23 checks passed
@aaronsteers aaronsteers deleted the aj/chore/use-custom-pokeapi-components-py branch February 6, 2025 16:21
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.

1 participant