Skip to content

Commit

Permalink
add mock_test_callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Mips2648 committed Aug 23, 2024
1 parent 570cfad commit 0e063f4
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/base_daemon_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def test_base_daemon_creation(self, mock_open_method):
Tests if it can create a basic daemon
"""
with pytest.raises(SystemExit) as pytest_wrapped_e:
# with mock.patch('jeedomdaemon.aio_connector.Publisher.test_callback') as mock_test_callback:
self._test_daemon.run()
with mock.patch('jeedomdaemon.aio_connector.Publisher.test_callback') as mock_test_callback:
self._test_daemon.run()
assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 0
# mock_test_callback.assert_called_once()
mock_test_callback.assert_called_once()

@mock.patch("builtins.open", new_callable=mock.mock_open)
def test_base_daemon_initialization(self, mock_open_method):
Expand Down Expand Up @@ -81,19 +81,19 @@ 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
async with Publisher('http://local/', 'cnysltyql') as pub:
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

@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
async with Publisher('http://local/', 'cnysltyql') as pub:
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

0 comments on commit 0e063f4

Please sign in to comment.