Integration Testing
Relevant source files
The following files were used as context for generating this wiki page:
The Integration Testing suite for flext-target-ldap is designed to validate the end-to-end flow of data from Singer-formatted JSONL input through the target's CLI entry point and into a mock LDAP directory. It ensures that the coordination between the Singer protocol handling, configuration management, and the LDAP client operations (add, modify, delete) functions correctly according to the project's behavioral contracts.
Sources: tests/unit/test_integration.py:1-12, src/flext_target_ldap/api.py:168-245
Testing Architecture
The integration tests utilize a mock-driven approach where the underlying LDAP API is intercepted to verify that the correct operations are dispatched based on incoming Singer messages. The core component under test is FlextTargetLdap.cli, which simulates the execution of the target in a production environment.
Components and Data Flow
The testing pipeline follows a structured path from input ingestion to LDAP operation verification:
- Input Simulation: Singer messages (
SCHEMA,RECORD,STATE) are serialized into a temporary JSONL file. - CLI Invocation: The
run_climethod is called with a path to a mock configuration file, whilesys.stdinis patched to provide the JSONL content. - API Mocking: The
FlextTargetLdapClientis monkeypatched to prevent actual network calls and to record the interactions.
This diagram illustrates the flow of a standard integration test case:
The diagram shows the transition from raw input files to the internal CLI logic and finally to the mocked LDAP client for validation.
Sources: tests/unit/test_integration.py:53-73, src/flext_target_ldap/api.py:171-240
Key Test Scenarios
The integration suite covers several critical operational paths to ensure robustness and protocol compliance.
CRUD and Upsert Logic
Tests verify that RECORD messages result in the appropriate LDAP operations. If a DN has not been seen before, an add_entry call is expected; if it is a subsequent record for the same DN, a modify_entry call is verified.
| Test Case | Objective | Expected Outcome |
|---|---|---|
test_basic_load | Verify initial record loading | add_entry is called at least once |
test_upsert_behavior | Verify update of existing entries | Both add_entry and modify_entry are called |
test_delete_records | Verify handling of deleted markers | delete_entry is called for records with _sdc_deleted_at |
Sources: tests/unit/test_integration.py:78-142
DN Construction and Templates
Integration tests specifically validate how Distinguished Names (DNs) are generated from source records. This includes testing default construction and template-based RDN attribute usage (e.g., using uid vs cn).
The sequence diagram details the internal delegation for constructing the LDAP DN before calling the API.
Sources: tests/unit/test_integration.py:144-173, src/flext_target_ldap/api.py:186-196
Mocking and Fixtures
The integration tests rely on a robust set of pytest fixtures defined in conftest.py and test_integration.py to ensure consistent state.
| Fixture | Description | Source |
|---|---|---|
mock_ldap_api | Intercepts FlextTargetLdapClient to provide a MagicMock connection. | tests/unit/test_integration.py:68 |
config_file | Creates a temporary JSON file containing mock LDAP settings. | tests/unit/test_integration.py:40 |
input_file | Generates a standard Singer JSONL stream (Schema, Record, State). | tests/unit/test_integration.py:50 |
singer_message_record | Provides a pre-serialized Singer RECORD message string. | tests/conftest.py:51 |
Sources: tests/unit/test_integration.py:38-73, tests/conftest.py:40-90
Multi-Stream Handling
The suite ensures that the target can process interleaved streams correctly. Tests verify that the target maintains the correct context when switching between different SCHEMA and RECORD messages for various LDAP object types (e.g., users and groups).
The flow shows how the internal state tracks the current_stream variable to apply correct RDN logic to incoming records.
Sources: tests/unit/test_integration.py:195-231, src/flext_target_ldap/api.py:220-230
Conclusion
Integration testing in flext-target-ldap serves as the primary gate for verifying Singer protocol compliance and LDAP client orchestration. By utilizing a combination of file-based input simulation and targeted API mocking, the suite provides high confidence in the target's ability to handle complex data synchronization tasks, including upserts, deletions, and multi-stream processing.