Skip to content

Test/add unit tests and ci - #5

Closed
buckleypaul wants to merge 11 commits into
mainfrom
test/add-unit-tests-and-ci
Closed

Test/add unit tests and ci#5
buckleypaul wants to merge 11 commits into
mainfrom
test/add-unit-tests-and-ci

Conversation

@buckleypaul

Copy link
Copy Markdown
Collaborator

No description provided.

Add pytest-asyncio to support testing async BLE functions.

Signed-off-by: Paul Buckley <paul@hubble.com>
Create tests directory with:
- __init__.py package marker
- conftest.py with shared pytest fixtures for:
  - Sample Location, EncryptedPacket, DecryptedPacket
  - Sample Device and Credentials
  - Mock fixtures for httpx and bleak

Signed-off-by: Paul Buckley <paul@hubble.com>
Test Location, EncryptedPacket, and DecryptedPacket dataclasses:
- Instantiation with required and optional fields
- Default values
- Frozen (immutable) behavior
- Equality and hash comparisons

Signed-off-by: Paul Buckley <paul@hubble.com>
Test Device dataclass:
- Constructor with various arguments
- from_json() factory method with complete/partial JSON
- ID type conversion (int to string)
- Key handling for 128-bit and 256-bit keys
- Mutable (non-frozen) behavior

Signed-off-by: Paul Buckley <paul@hubble.com>
Test exception classes and helper functions:
- Exception inheritance hierarchy validation
- map_http_status() for 400, 500, and other status codes
- raise_for_response() with dict, string, and None bodies
- Error message extraction from various response formats

Signed-off-by: Paul Buckley <paul@hubble.com>
Test crypto module functions:
- ParsedPacket parsing (sequence, auth tag, payload)
- KDF key generation (_generate_kdf_key)
- Nonce generation (_get_nonce)
- Auth tag generation and verification
- Full decrypt() function with valid/invalid keys
- find_time_counter_delta() for time sync checking

Uses synthetic test vectors by encrypting known payloads.

Signed-off-by: Paul Buckley <paul@hubble.com>
Test BLE scanning functions with mocked hardware:
- _get_location() returns fake location
- Target UUID format validation
- scan_async() timeout and packet collection
- scan_single_async() first packet detection
- Sync/async wrapper functions

All tests marked with @pytest.mark.ble for selective running.

Signed-off-by: Paul Buckley <paul@hubble.com>
Test cloud module with mocked httpx.Client:
- Environment and Credentials dataclasses
- cloud_request() with success, errors, timeouts
- Continuation token handling for pagination
- get_env_from_credentials() validation flow
- Device registration, listing, and updates
- Packet retrieval and ingestion

Signed-off-by: Paul Buckley <paul@hubble.com>
Test Organization class with mocked cloud module:
- Constructor with credentials object or explicit args
- InvalidCredentialsError when validation fails
- Device registration and name updates
- Device listing with pagination
- Packet retrieval with pagination
- Packet ingestion

Signed-off-by: Paul Buckley <paul@hubble.com>
Test CLI commands:
- Main CLI group help and version options
- validate-credentials command
- BLE subcommands (detect, scan, check-time) help text
- Org subcommands help and credential requirements
- Output format options for BLE commands
- Environment variable fallback
- main() entry point exit codes

Note: Due to Click's decorator behavior, org subcommand
testing is limited to help text and error handling.

Signed-off-by: Paul Buckley <paul@hubble.com>
Configure CI to run on PRs and pushes to main:
- Test on Python 3.10, 3.11, and 3.12
- Skip BLE and integration tests (no hardware/credentials)
- Generate coverage report with pytest-cov
- Upload coverage to Codecov (on Python 3.12)

Signed-off-by: Paul Buckley <paul@hubble.com>
@buckleypaul
buckleypaul marked this pull request as ready for review January 21, 2026 01:01
@buckleypaul

Copy link
Copy Markdown
Collaborator Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@buckleypaul
buckleypaul deleted the test/add-unit-tests-and-ci branch February 27, 2026 19:26
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