Skip to content

refactor(pipelines/cdp): modularize test suite to mirror pipeline structure - #275

Merged
iht merged 2 commits into
GoogleCloudPlatform:mainfrom
iht:refactor/cdp-modular-tests
Sep 9, 2026
Merged

refactor(pipelines/cdp): modularize test suite to mirror pipeline structure#275
iht merged 2 commits into
GoogleCloudPlatform:mainfrom
iht:refactor/cdp-modular-tests

Conversation

@iht

@iht iht commented Sep 9, 2026

Copy link
Copy Markdown
Member

Description

The test suite for the Customer Data Platform (CDP) pipeline currently consolidated all tests into a single monolithic 443-line file (pipelines/cdp/tests/test_customer_data_platform.py). While the main pipeline was previously refactored into cohesive submodules in pipelines/cdp/cdp_pipeline/, the tests did not mirror this structure.

This PR modularizes pipelines/cdp/tests/ to establish exact 1:1 parity with pipelines/cdp/cdp_pipeline/:

  • test_models.py: unit tests for TransactionItem, CouponRedemption, DeadLetterRecord, CustomerInteractionEvent, UnifiedTransactionRecord, CustomerSessionProfile, and Beam schema compatibility
  • test_options.py: tests for MyPipelineOptions defaults, CLI flag parsing, and GCP options
  • test_schemas.py: tests for default and custom BigQuery schema loading and missing file handling
  • test_parsing.py: tests for ParseRecordDoFn (transactions, coupons, malformed payloads, missing keys) and AssignEventTimestampDoFn (ISO strings, micros fallback, UTC now fallback)
  • test_sessionization.py: tests for ProcessCustomerSessionDoFn window aggregation, session profiling, and multi-coupon joins
  • test_sinks.py: tests for Storage Write API timestamp conversions (_to_beam_timestamp), row dict formatters, and BigQuery sink graph attachment
  • test_pipeline.py: tests for build_pipeline DAG assembly and in-memory execution using TestPipeline

Verification

  • Automated Tests: 41/41 tests passing with pytest tests/ -v (up from 21 tests previously)
  • Formatting: Google Python Style verified with yapf
  • Linting: 10.00/10 rating with pylint --rcfile ../pylintrc cdp_pipeline tests
  • Packaging: Verified with python setup.py sdist

TAG=agy
CONV=59306c7c-80e2-4454-9ec5-e496e3b85156

…ucture

- Decompose monolithic test_customer_data_platform.py into dedicated test modules:
  - test_models.py: tests for NamedTuple data models, payload parsing, and Beam schema compatibility
  - test_options.py: tests for pipeline and GCP options parsing and defaults
  - test_schemas.py: tests for packaged and custom BigQuery table schema loading
  - test_parsing.py: tests for ParseRecordDoFn and AssignEventTimestampDoFn
  - test_sessionization.py: tests for ProcessCustomerSessionDoFn aggregation and metrics
  - test_sinks.py: tests for Storage Write API timestamp formatting and BigQuery sink attachment
  - test_pipeline.py: tests for build_pipeline DAG assembly and in-memory execution
- Expand unit test coverage for sinks and timestamp assignment (41 tests passing, up from 21)
- Verify full compliance with Google Python style (yapf) and PyLint (10.00/10)

TAG=agy
CONV=59306c7c-80e2-4454-9ec5-e496e3b85156
Comment thread pipelines/cdp/tests/test_sessionization.py Outdated
Comment thread pipelines/cdp/tests/test_parsing.py Outdated
Comment thread pipelines/cdp/tests/test_sinks.py Outdated
…uites

- Refactor test_sessionization.py to run ProcessCustomerSessionDoFn inside TestPipeline with Sessions windowing and GroupByKey
- Refactor test_parsing.py to execute ParseRecordDoFn and AssignEventTimestampDoFn inside TestPipeline with assert_that
- Update test_sinks.py to use TestPipeline for DAG construction tests
- Set TestPipeline.__test__ = False to ensure seamless pytest discovery

TAG=agy
CONV=59306c7c-80e2-4454-9ec5-e496e3b85156
@iht
iht merged commit 90e8d8f into GoogleCloudPlatform:main Sep 9, 2026
12 checks passed
@iht
iht deleted the refactor/cdp-modular-tests branch September 9, 2026 08:24
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