Skip to content

feat(dataconnect): Implementation and Testing of the _DataConnectApiClient class#965

Merged
mk2023 merged 12 commits into
winefrom
champagne
Jul 20, 2026
Merged

feat(dataconnect): Implementation and Testing of the _DataConnectApiClient class#965
mk2023 merged 12 commits into
winefrom
champagne

Conversation

@mk2023

@mk2023 mk2023 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Implemented three helper functions in _DataConnectApiClient along with their corresponding implementations:

  • _validate_inputs: Validates the query structure, options, variables types, and custom impersonation claims.
  • _prepare_graphql_payload: Prepares the JSON payload for GraphQL calls, serializing variables (including nested dataclasses) and configuring optional extensions like impersonation.
  • _get_firebase_dataconnect_service_url: Formats the endpoint URL for execution, supporting both production host formats and local emulator host formats.
    Added comprehensive unit tests covering standard cases, invalid options, missing configurations, and emulator environments for each of the helper functions.

Added comprehensive unit tests to TestDataConnectApiClient covering client constructor, inputs validation, variables and impersonation serialization, and service URL construction.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a comprehensive suite of unit tests for the _DataConnectApiClient class, covering its constructor, input validation, payload preparation, and service URL generation. The review feedback identifies critical issues in the tests, including a missing import for the dataclass decorator and references to undefined classes and attributes in the dataconnect module, both of which will cause runtime errors during test execution.

Comment thread tests/test_data_connect.py
Comment thread tests/test_data_connect.py
mk2023 added 2 commits July 9, 2026 14:54
Implemented _validate_inputs to validate queries, options, variables, and impersonation, and _prepare_graphql_payload to construct GraphQL JSON payloads. Implemented _get_firebase_dataconnect_service_url to build production and emulator service endpoint URLs. Added full unit test coverage for input validation, payload construction, and URL formatting.
…uilder

Implemented three helper functions in _DataConnectApiClient along with their corresponding implementations:
- _validate_inputs: Validates the query structure, options, variables types, and custom impersonation claims.
- _prepare_graphql_payload: Prepares the JSON payload for GraphQL calls, serializing variables (including nested dataclasses) and configuring optional extensions like impersonation.
- _get_firebase_dataconnect_service_url: Formats the endpoint URL for execution, supporting both production host formats and local emulator host formats.
Added comprehensive unit tests covering standard cases, invalid options, missing configurations, and emulator environments for each of the helper functions.
This completes the first half of milestone 3.
@mk2023 mk2023 changed the title feat(dataconnect): Added unit tests for DataConnect API Client helpers feat(dataconnect): Implementation and Testing of the _DataConnectApiClient class Jul 10, 2026
mk2023 added 2 commits July 10, 2026 10:22
Implemented `_get_headers` inside `_DataConnectApiClient` to build standard telemetry headers for outgoing HTTP requests. Specifically, it populates:
- X-Firebase-Client: The current Python SDK version header.
- x-goog-api-client: The Google telemetry metrics header.
Added the `TestDataConnectApiClientGetHeaders` unit test suite to verify the return type and values.
Fixed formatting and style issues highlighted by pylint:
- Removed trailing whitespace in TestDataConnectApiClientGetHeaders test class.
- Resolved missing final newline warning at the end of the test file.

@stephenarosaj stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Partial review - just dropping comments early

Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated

@stephenarosaj stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Further partial review

Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated

@itsrakhil itsrakhil left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Left some comments.

@stephenarosaj stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

partial review of main file - now for tests

Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/dataconnect.py
Comment thread firebase_admin/dataconnect.py Outdated
…ost utility

- Inherited Impersonation from dict to resolve the type-checking mismatch for static methods while maintaining dictionary behavior at runtime.

- Updated GraphqlOptions.impersonate type annotation to accept Union[Impersonation, Dict[str, Any]] to support both helper and raw dictionary inputs.

- Extracted generic variable and impersonate validation into separate helper methods _validate_variables_type and _validate_impersonation_options.

- Shared emulator host extraction and validation logic in _utils.get_emulator_host and reused it across dataconnect and functions.

- Removed AuthClaims and FirebaseClaim TypedDicts to keep them as raw dicts for now.

- Renamed generic TypeVars to private naming conventions (_Data and _Variables).

@stephenarosaj stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

some minor changes but i think this looks good!

Comment thread tests/test_data_connect.py Outdated
Comment thread tests/test_data_connect.py Outdated
Comment thread tests/test_data_connect.py Outdated
Comment thread tests/test_data_connect.py
Comment thread tests/test_data_connect.py Outdated
…te variable_type

- Updated _validate_variables_type to validate that if variables are provided, they must be either a collections.abc.Mapping or a dataclass.

- Type-annotated the variable_type parameter as Optional[Type[Any]] = None in both validation helper signatures.

- Refactored variable unit tests to use a realistic CreateUserVariables (nesting a UserProfile dataclass) instead of response-like shapes.

- Added a test case confirming that standard dictionaries (Mapping) are accepted as valid variables.
Comment thread firebase_admin/dataconnect.py Outdated
mk2023 added 2 commits July 15, 2026 12:39
- Fallback to str(variable_type) if variable_type lacks a __name__ attribute to prevent AttributeError crashes.

- Added a unit test validating this fallback behavior for a tuple of types.

@stephenarosaj stephenarosaj left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM - ready for Lahiru

@mk2023
mk2023 requested a review from lahirumaramba July 15, 2026 20:26

@lahirumaramba lahirumaramba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! Overall LGTM!
Added a few comments/questions.

Comment thread firebase_admin/_utils.py Outdated
Comment thread firebase_admin/dataconnect.py Outdated
Comment thread firebase_admin/_utils.py
mk2023 added 3 commits July 17, 2026 12:59
…in emulator hostnames

Refactored GraphqlOptions operationName validation and serialization to avoid mutating the original options object. Updated emulator hostname regex validation to support underscores in hostnames, and added/updated corresponding unit tests.
Updated _validate_variables_type to use typing.get_origin() to unwrap subscripted generics (e.g. Dict, Mapping) for runtime type checks. Added corresponding unit tests to verify generic type validation and mismatch scenarios.

@lahirumaramba lahirumaramba left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks!

@mk2023
mk2023 merged commit 602a2eb into wine Jul 20, 2026
15 checks passed
@mk2023
mk2023 deleted the champagne branch July 20, 2026 20:56
mk2023 added a commit that referenced this pull request Jul 20, 2026
…ataConnectApiClient class (#965)

*Core API Client Helpers*

- Implemented `_validate_inputs` to enforce strict validation on query structures, options, variables, and custom impersonation claims.

- Implemented `_prepare_graphql_payload` to construct the GraphQL JSON payload, seamlessly serializing variables (including nested dataclasses) and optional extensions.

- Implemented `_get_firebase_dataconnect_service_url` to dynamically build endpoint URLs for both production and local emulator hosts.

- Implemented `_get_headers` to inject standard telemetry metrics (X-Firebase-Client and x-goog-api-client).

*Validation & Serialization Refinements*

- Enforced that GraphQL variables must be either a Mapping (like standard dicts) or a dataclass.
- Added support for runtime validation of subscripted generic types (e.g., Dict, Mapping) using typing.get_origin().
- Refactored `Impersonation` to inherit from `dict`, resolving type-checking mismatches while maintaining runtime dictionary behavior. Extracted variable and impersonation validation into dedicated helper methods.

*Testing & Code Health*

- Added comprehensive unit test coverage for the client constructor, input validation, headers, and payload serialization (using realistic nested dataclasses).
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.

4 participants