Skip to content

Conversation

@bakonyiferenc
Copy link
Contributor

  • Add developer testing guide in docs/testing.md
  • Implement pytest fixtures in tests/conftest.py:
    • mock_session_factory for sequential response mocking
    • Response fixtures for login, errors, device info, hosts, xpath
    • Pre-configured client fixtures for all encryption methods
  • Add API response fixtures (6 JSON files) with realistic router responses
  • Add 4 example tests demonstrating key patterns:
    • Successful login with session state validation
    • Authentication error handling
    • XPath operations with sequential responses
    • Pre-configured fixture usage
  • Configure pytest in pyproject.toml:
    • Add pytest-asyncio, pytest-aiohttp, pytest-cov dependencies
    • Set asyncio_mode, testpaths, and markers

Part of #447: Add unit and integration tests to have test coverage

- Add developer testing guide in docs/testing.md
- Implement pytest fixtures in tests/conftest.py:
  - mock_session_factory for sequential response mocking
  - Response fixtures for login, errors, device info, hosts, xpath
  - Pre-configured client fixtures for all encryption methods
- Add API response fixtures (6 JSON files) with realistic router responses
- Add 4 example tests demonstrating key patterns:
  - Successful login with session state validation
  - Authentication error handling
  - XPath operations with sequential responses
  - Pre-configured fixture usage
- Configure pytest in pyproject.toml:
  - Add pytest-asyncio, pytest-aiohttp, pytest-cov dependencies
  - Set asyncio_mode, testpaths, and markers

Part of iMicknl#447: Add unit and integration tests to have test coverage
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR establishes comprehensive test infrastructure for the Sagemcom API client, including pytest configuration, mock fixtures, example tests, and developer documentation. The changes enable unit and integration testing with realistic API response mocking.

Key Changes:

  • Added pytest configuration with asyncio support and coverage tooling
  • Implemented mock session factory and response fixtures for authentication, errors, and data operations
  • Created 6 JSON fixture files containing realistic router API responses
  • Provided 4 example tests demonstrating key testing patterns

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyproject.toml Added pytest dependencies (pytest-asyncio, pytest-aiohttp, pytest-cov) and configuration for async tests, test paths, and custom markers
poetry.lock Updated dependency lock file with new test-related packages and version constraints
tests/conftest.py Implemented shared fixtures including mock session factory, response fixtures for various API scenarios, and pre-configured client fixtures for different encryption methods
tests/fixtures/login_success.json Realistic API response for successful authentication with session ID and nonce
tests/fixtures/login_auth_error.json API response demonstrating authentication failure error handling
tests/fixtures/login_invalid_session.json API response for invalid session error scenario
tests/fixtures/device_info.json Comprehensive device information response with 993 lines covering hardware, software, temperature sensors, and system configuration
tests/fixtures/hosts.json Connected hosts/devices list response with detailed device metadata
tests/fixtures/xpath_value.json Generic XPath query response demonstrating WiFi radio status retrieval
tests/unit/test_client_basic.py Four example tests demonstrating mocking patterns for login success/failure, XPath operations, and pre-configured fixtures
docs/testing.md Developer guide covering test structure, mocking strategies, fixture patterns, and instructions for running and adding tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@iMicknl iMicknl added the enhancement New feature or request label Dec 21, 2025
Copy link
Owner

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thank you!

(later we will need to add this to GitHub Actions as well)

@iMicknl iMicknl merged commit f8309a4 into iMicknl:main Dec 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants