-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and refactor
port_forwarding
module (#412)
- Loading branch information
1 parent
07fe8bf
commit b2bf66d
Showing
2 changed files
with
60 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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,46 @@ | ||
"""Tests for the port forwarding module.""" | ||
|
||
from unittest.mock import AsyncMock | ||
|
||
import pytest | ||
|
||
from asusrouter.modules.port_forwarding import ( | ||
KEY_PORT_FORWARDING_STATE, | ||
AsusPortForwarding, | ||
set_state, | ||
) | ||
|
||
async_callback = AsyncMock() | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"state, expect_modify, expect_call, expected_args", | ||
[ | ||
# Correct states | ||
(AsusPortForwarding.ON, True, True, {KEY_PORT_FORWARDING_STATE: 1}), | ||
(AsusPortForwarding.OFF, False, True, {KEY_PORT_FORWARDING_STATE: 0}), | ||
# Wrong states | ||
(AsusPortForwarding.UNKNOWN, False, False, {}), | ||
(None, False, False, {}), | ||
], | ||
) | ||
async def test_set_state(state, expect_modify, expect_call, expected_args): | ||
"""Test set_state.""" | ||
|
||
# Call the set_state function | ||
await set_state(callback=async_callback, state=state, expect_modify=expect_modify) | ||
|
||
# Check if the callback function was called | ||
if expect_call: | ||
async_callback.assert_called_once_with( | ||
service="restart_firewall", | ||
arguments=expected_args, | ||
apply=True, | ||
expect_modify=expect_modify, | ||
) | ||
else: | ||
async_callback.assert_not_called() | ||
|
||
# Reset the mock callback function | ||
async_callback.reset_mock() |