-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡ handle timeout error and add tests
- Loading branch information
Showing
5 changed files
with
57 additions
and
18 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
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
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 |
---|---|---|
@@ -1,22 +1,53 @@ | ||
"""Test class for base config.""" | ||
|
||
import re | ||
import sys | ||
import os | ||
import unittest | ||
from unittest.mock import patch, mock_open | ||
import pytest | ||
from aioresponses import aioresponses | ||
|
||
sys.path.append(os.path.realpath(os.path.dirname(__file__) + '/..')) | ||
|
||
from jeedomdaemon.base_daemon import BaseDaemon # pylint: disable=wrong-import-position | ||
from jeedomdaemon.base_config import BaseConfig # pylint: disable=wrong-import-position | ||
from jeedomdaemon.aio_connector import Publisher | ||
|
||
class TestBaseConfig(unittest.TestCase): | ||
def test_base_daemon_creation(self): | ||
class TestBaseDaemon(): | ||
def _get_test_config(self): | ||
config = BaseConfig() | ||
config.parse(['--loglevel', 'info', '--socketport', '42000', '--callback', 'http://localhost/path', '--apikey', 'cnysltyql', '--pid', '/tmp/test_daemon']) | ||
return config | ||
|
||
@patch("builtins.open", new_callable=mock_open) | ||
def test_base_daemon_creation(self, dummy_file): | ||
""" | ||
Test that it can create a basic config parser | ||
Test that it can create a basic daemon | ||
""" | ||
config = BaseConfig() | ||
config.parse([]) | ||
BaseDaemon(config) | ||
config = self._get_test_config() | ||
testdaemon = BaseDaemon(config) | ||
with pytest.raises(SystemExit) as pytest_wrapped_e: | ||
testdaemon.run() | ||
assert pytest_wrapped_e.type == SystemExit | ||
assert pytest_wrapped_e.value.code == 0 | ||
|
||
class TestPublisher(): | ||
|
||
@pytest.mark.asyncio | ||
async def test_send_to_jeedom(self): | ||
pub = Publisher('http://local/', 'cnysltyql') | ||
with aioresponses() as mocked: | ||
pattern = re.compile(r'^http://local/\?apikey=.*$') | ||
mocked.get(pattern, status=200, body='test') | ||
mocked.post(pattern, status=200, body='test') | ||
resp = await pub.send_to_jeedom({}) | ||
assert resp == True | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
@pytest.mark.asyncio | ||
async def test_send_to_jeedom_timeout(self): | ||
pub = Publisher('http://local/', 'cnysltyql') | ||
with aioresponses() as mocked: | ||
pattern = re.compile(r'^http://local/\?apikey=.*$') | ||
mocked.post(pattern, status=200, timeout=True) | ||
resp = await pub.send_to_jeedom({}) | ||
assert resp == False |