-
Notifications
You must be signed in to change notification settings - Fork 1
Add (very basic) test #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pytest | ||
| pytest-asyncio | ||
| aiohttp | ||
| aioresponses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """Tests for the Ubiquity AirOS python module.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # https://bandit.readthedocs.io/en/latest/config.html | ||
|
|
||
| tests: | ||
| - B103 | ||
| - B108 | ||
| - B306 | ||
| - B307 | ||
| - B313 | ||
| - B314 | ||
| - B315 | ||
| - B316 | ||
| - B317 | ||
| - B318 | ||
| - B319 | ||
| - B320 | ||
| - B601 | ||
| - B602 | ||
| - B604 | ||
| - B608 | ||
| - B609 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """Ubiquity AirOS test fixtures.""" | ||
|
|
||
| from airos.airos8 import AirOS | ||
| import pytest | ||
|
|
||
| import aiohttp | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def base_url(): | ||
| """Return a testing url.""" | ||
| return "http://device.local" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def airos_device(base_url): | ||
| """AirOS device fixture.""" | ||
| session = aiohttp.ClientSession(cookie_jar=aiohttp.CookieJar()) | ||
| instance = AirOS(base_url, "username", "password", session, use_ssl=False) | ||
| yield instance | ||
| await session.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """Ubiquity AirOS tests.""" | ||
|
|
||
| from http.cookies import SimpleCookie | ||
| import json | ||
| import os | ||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| import aiofiles | ||
|
|
||
|
|
||
| async def _read_fixture(fixture: str = "ap-ptp"): | ||
| """Read fixture file per device type.""" | ||
| fixture_dir = os.path.join(os.path.dirname(__file__), "..", "fixtures") | ||
| path = os.path.join(fixture_dir, f"{fixture}.json") | ||
| try: | ||
| async with aiofiles.open(path, encoding="utf-8") as f: | ||
| return json.loads(await f.read()) | ||
| except FileNotFoundError: | ||
| pytest.fail(f"Fixture file not found: {path}") | ||
| except json.JSONDecodeError as e: | ||
| pytest.fail(f"Invalid JSON in fixture file {path}: {e}") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("mode", ["ap-ptp", "sta-ptp"]) | ||
| @pytest.mark.asyncio | ||
| async def test_ap(airos_device, base_url, mode): | ||
| """Test device operation.""" | ||
| cookie = SimpleCookie() | ||
| cookie["session_id"] = "test-cookie" | ||
| cookie["AIROS_TOKEN"] = "abc123" | ||
|
|
||
| # --- Prepare fake POST /api/auth response with cookies --- | ||
| mock_login_response = MagicMock() | ||
| mock_login_response.__aenter__.return_value = mock_login_response | ||
| mock_login_response.text = "{}" | ||
| mock_login_response.status = 200 | ||
| mock_login_response.cookies = cookie | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mock_login_response.headers = {"X-CSRF-ID": "test-csrf-token"} | ||
| # --- Prepare fake GET /api/status response --- | ||
| fixture_data = await _read_fixture(mode) | ||
| mock_status_payload = fixture_data | ||
| mock_status_response = MagicMock() | ||
| mock_status_response.__aenter__.return_value = mock_status_response | ||
| mock_status_response.text = json.dumps(fixture_data) | ||
| mock_status_response.status = 200 | ||
| mock_status_response.json = AsyncMock(return_value=mock_status_payload) | ||
|
|
||
| with ( | ||
| patch.object(airos_device.session, "post", return_value=mock_login_response), | ||
| patch.object(airos_device.session, "get", return_value=mock_status_response), | ||
| ): | ||
| assert await airos_device.login() | ||
| status = await airos_device.status() | ||
|
|
||
| # Verify the fixture returns the correct mode | ||
| assert status.get("wireless", {}).get("mode") == mode | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.