Unit Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
The unit testing strategy for flext-tap-ldap focuses on verifying the core logic of LDAP directory interactions, LDIF processing, and Singer tap behavior in isolation. The strategy employs a mix of mocking LDAP server responses, validating data transformations, and ensuring structural compliance with the FLEXT framework.
Tests are organized into logical domains including client interactions, data processing utilities, and tap-level orchestration. The strategy leverages canonical test namespace patterns (e.g., u.TapLdap.*, m.TapLdap.Tests.*) to ensure consistency and reusability across the test suite.
Sources: tests/unit/init.py:1-25, tests/utilities.py:1-20
Core Test Architecture
The testing architecture relies on the pytest framework and utilizes specific markers to categorize test types such as unit, integration, and e2e. A centralized configuration in pyproject.toml defines strict markers and collection rules to maintain high quality gates.
Sources: pyproject.toml:440-470
Test Component Organization
| Component | Test File | Description |
|---|---|---|
| LDAP Client | test_client.py, test_client_quick.py | Validates URI building, search execution, and Oracle OID support. |
| LDIF Processor | test_ldif_processor.py | Tests LDIF file parsing, entry validation, and attribute transformations. |
| Tap Orchestration | test_tap.py | Verifies stream discovery and record mapping for Singer standard compliance. |
| Integration | test_integration.py | Tests end-to-end CLI behavior with mocked external dependencies. |
Sources: tests/unit/test_client.py:1-15, tests/unit/test_ldif_processor.py:1-20, tests/unit/test_tap.py:1-20, tests/e2e/test_integration.py:30-45
LDAP Client Testing
The LDAP client testing strategy ensures that the FlextTapLdapClient.LDAPClient correctly handles connection parameters and search operations. Tests use unittest.mock.patch to intercept calls to the underlying flext_api and simulate various server responses.
Connection and URI Validation
Tests verify that the server_uri property correctly identifies the protocol based on the use_ssl flag, supporting both ldap:// and ldaps:// schemes.
Sources: tests/unit/test_client.py:40-50, tests/unit/test_client_quick.py:68-80
Oracle OID Support
Specific tests target the enrichment of LDAP entries for Oracle OID environments, ensuring orclPassword values are mapped to userPassword and container object classes are normalized.
Sources: tests/unit/test_client_quick.py:165-210, tests/unit/test_client.py:90-110
The diagram shows the logic for handling Oracle OID searches, which requires specific event loop management and attribute mapping as defined in the client support utilities.
Sources: tests/unit/test_client.py:90-130, tests/unit/test_client_quick.py:270-290
LDIF Processor and Transformation Strategy
The Processor, Validator, and Transformer classes within the u.TapLdap namespace are tested for their ability to handle raw LDIF data. The strategy includes testing for strict error handling versus failure-tolerant parsing.
Sources: src/flext_tap_ldap/_utilities/_processor.py:130-160, tests/unit/test_ldif_processor.py:80-100
Transformation Rule Validation
Tests for the Transformer class verify that attribute mappings, value mappings, and additions/removals are applied correctly to u.TapLdap.Entry objects.
Sources: tests/unit/test_ldif_processor.py:48-75, src/flext_tap_ldap/_utilities/_processor.py:425-480
This sequence illustrates the data flow within the processing utilities, from raw LDIF ingestion to the final transformed record ready for Singer output.
Sources: src/flext_tap_ldap/_utilities/_processor.py:130-360, tests/unit/test_ldif_processor.py:48-75
Integration and CLI Testing
Integration tests use click.testing.CliRunner to simulate command-line execution of the tap. The strategy focuses on validating the three primary modes of operation:
- Discovery Mode: Validates that all expected streams (users, groups, schema, etc.) are present in the catalog output.
- Sync Mode: Ensures that schema messages and records are correctly emitted to standard output.
- Incremental Sync: Verifies that state is correctly utilized to construct timestamp-based search filters.
Sources: tests/e2e/test_integration.py:80-150
CLI Parameter Handling
| Command Option | Testing Focus |
|---|---|
--config | Validation of LDAP connection settings and custom stream definitions. |
--discover | Structural validation of the emitted JSON catalog. |
--catalog | Filtering of search results based on stream selection. |
--state | Correct application of bookmarks to search filters. |
Sources: tests/e2e/test_integration.py:38-75, tests/e2e/test_integration.py:155-180
Summary of Testing Utilities
The project employs a robust set of utilities to facilitate testing, including a Docker-based infrastructure for LDAP admin credentials resolution.
Sources: tests/utilities.py:35-70
- FileLock: Used for managing concurrent access to shared resources during tests.
- admin_credentials(): Resolves credentials by checking environment variables (
FLEXT_LDAP_BIND_DN) before falling back to known defaults. - create_bare_server(): Facilitates connection testing against local LDAP instances.