This directory contains comprehensive unit tests for the Azure Connectors Python SDK.
tests/
├── __init__.py # Package initialization
├── conftest.py # Shared pytest fixtures and utilities
├── test_kusto.py # Kusto connector tests (37 tests, 98% coverage)
├── test_msgraph.py # Microsoft Graph connector tests (46 tests)
├── test_office365.py # Office365 connector tests (41 tests, 79% coverage)
├── test_sharepointonline.py # SharePoint Online connector tests (44 tests, 57% coverage)
├── test_teams.py # Teams connector tests (27 passed, 18 skipped, 73% coverage)
├── test_sdk_authentication.py # Authentication module tests (21 tests)
├── test_sdk_client_base.py # Client base module tests (14 tests)
├── test_sdk_exceptions.py # Exceptions module tests (14 tests)
├── test_sdk_http_client.py # HTTP client module tests (30 tests)
├── test_sdk_options.py # Options module tests (14 tests)
├── test_sdk_trigger_payload.py # Trigger payload module tests (17 tests)
└── README.md # This file
pytestpytest tests/test_kusto.pypytest -vpytest --cov=azure.connectors --cov-report=term-missingpytest tests/test_kusto.py --cov=azure.connectors.kusto --cov-report=term-missingCurrent test coverage by module:
-
kusto.py: 98% (37 tests)
- Initialization tests (7)
- Lifecycle tests (2)
- API method tests (16)
- Data class tests (7)
- Edge case tests (5)
-
msgraph.py: (46 tests)
- Initialization tests (7)
- Lifecycle tests (2)
- User operation tests (3)
- Group operation tests (13)
- License operation tests (3)
- Subscription operation tests (2)
- Data class tests (8)
- Edge case tests (8)
-
office365.py: 79% (41 tests covering 53 methods)
- Initialization tests (7)
- Lifecycle tests (2)
- Email operation tests (13)
- Calendar operation tests (3)
- Contact operation tests (1)
- MCP endpoint tests (2)
- Data class tests (4)
- Edge case tests (9)
-
sharepointonline.py: 57% (44 tests)
- Initialization tests (7)
- Lifecycle tests (2)
- Get all tables tests (4)
- File operation tests (5)
- Folder operation tests (4)
- Item operation tests (5)
- Sharing operation tests (2)
- Copy/move operation tests (3)
- Approval operation tests (2)
- Data class tests (4)
- Edge case tests (6)
-
teams.py: 73% (27 passed, 18 skipped)
- Initialization tests (7)
- Lifecycle tests (2)
- Meeting operation tests (2)
- List operation tests (3)
- Channel operation tests (4 skipped - template variable bugs in generated code)
- Chat operation tests (1 skipped - template variable bugs in generated code)
- Tag operation tests (6 skipped - template variable bugs in generated code)
- Message operation tests (4 skipped - template variable bugs in generated code)
- Member operation tests (1 skipped - template variable bugs in generated code)
- Trigger operation tests (2 skipped - template variable bugs in generated code)
- Data class tests (7)
- Edge case tests (6)
Note: Some Teams connector methods have template variables (e.g., {groupId}, {channelId}) that are not defined as parameters in the generated code. These tests are skipped with appropriate documentation. Once the code generation issue is fixed, these tests can be enabled.
-
authentication.py: (21 tests)
- AzureIdentityTokenProvider tests (8)
- ManagedIdentityTokenProvider tests (5)
- ConnectionStringTokenProvider tests (5)
- TokenProvider interface tests (3)
-
client_base.py: (14 tests)
- Abstract class tests (1)
- Initialization tests (6)
- Lifecycle tests (5)
- Credential wrapping tests (2)
-
exceptions.py: (14 tests)
- Initialization and message format tests (5)
- Body truncation tests (5)
- Status code and attribute tests (4)
-
http_client.py: (30 tests)
- ConnectorResponse tests (9)
- Initialization and session tests (7)
- Request sending tests (10)
- Retry delay tests (2)
- GET method tests (2)
-
options.py: (14 tests)
- Default values 305 tests (285 passing, 20 skipped)
-
Connector Tests: 195 tests (177
- Type verification tests (3)
-
trigger_payload.py: (17 tests)
- TriggerCallbackBody tests (7)
- TriggerCallbackPayload tests (10)
- Total Tests: 259 tests (249 passing, 18 skipped)
- Connector Tests: 149 tests (131 passing, 18 skipped)
- SDK Component Tests: 110 tests (110 passing)
- Overall Coverage: ~75%
Tests are organized into classes by functionality:
TestXClientInitialization: Tests for client initializationTestXClientLifecycle: Tests for lifecycle methods (close, context manager)TestMethodName: Tests for specific API methodsTestDataClasses: Tests for data classes and type definitionsTestEdgeCases: Tests for edge cases and boundary conditions
Common fixtures are defined in conftest.py:
mock_token_provider: A mock token provider for testingmock_response_success: A successful mock HTTP responsemock_response_error: An error mock HTTP responsemock_response_empty: An empty mock HTTP response
@pytest.mark.asyncio
async def test_success_with_json_response(self, mock_token_provider):
"""Test successful query execution with JSON response."""
client = KustoClient(
"https://example.azure.com/connections/test",
token_provider=mock_token_provider
)
mock_response = MockResponse(
status=200,
text='{"rows": [{"col1": "value1"}]}'
)
with patch.object(
client._http_client,
'send_async',
new_callable=AsyncMock,
return_value=mock_response
):
result = await client.list_kusto_results_async(QueryAndListSchema())
assert result == {"rows": [{"col1": "value1"}]}- Valid URL with defaults
- Trailing slash handling
- Custom token provider
- Custom options
- Error cases (empty URL, None URL)
- Property access
- Close method
- Async context manager
- Success with JSON response
- Success with empty response
- Error responses (4xx, 5xx)
- Parameter passing
- URL construction
- Query string encoding
- Data class creation
- Field validation
- Default values
- Type definitions
- Multiple consecutive calls
- JSON parse errors
- URL construction edge cases
- Property access
Test dependencies are defined in ../src/pyproject.toml:
pytest: Test frameworkpytest-asyncio: Async test supportpytest-cov: Coverage reporting
Install dev dependencies:
pip install -e ".[dev]"Tests are designed to run in CI/CD pipelines with:
- Fast execution (< 1 second for 37 tests)
- No external dependencies
- Comprehensive mocking
- Clear error messages
- Strict async mode
- Use descriptive test names:
test_method_scenario_expected_result - Group related tests: Use test classes to organize tests
- Mock external dependencies: Never make real HTTP calls in unit tests
- Test error cases: Always test both success and failure paths
- Use fixtures: Reuse common setup code via pytest fixtures
- Document test intent: Include docstrings explaining what is being tested
- Verify all code paths: Aim for high coverage (95%+)
- Keep tests fast: Unit tests should run in milliseconds