Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alopalao committed Sep 16, 2024
1 parent c57543d commit 1a1df5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions tests/unit/test_core/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ def test_debug_wrong_name(self):
@patch('kytos.core.controller.Controller.start_controller')
@patch('kytos.core.controller.Controller.create_pidfile')
@patch('kytos.core.controller.Controller.enable_logs')
def test_start(self, *args):
async def test_start(self, *args):
"""Test start method."""
(mock_enable_logs, mock_create_pidfile,
mock_start_controller, mock_db_conn_wait,
mock_init_apm) = args
self.controller.start()
await self.controller.start()

mock_enable_logs.assert_called()
mock_create_pidfile.assert_called()
Expand All @@ -190,13 +190,13 @@ def test_start(self, *args):
@patch('kytos.core.controller.Controller.start_controller')
@patch('kytos.core.controller.Controller.create_pidfile')
@patch('kytos.core.controller.Controller.enable_logs')
def test_start_error_broad_exception(self, *args):
async def test_start_error_broad_exception(self, *args):
"""Test start error handling broad exception."""
(mock_enable_logs, mock_create_pidfile,
mock_start_controller, mock_db_conn_wait,
mock_init_apm, mock_sys) = args
mock_start_controller.side_effect = Exception
self.controller.start()
await self.controller.start()

mock_enable_logs.assert_called()
mock_create_pidfile.assert_called()
Expand All @@ -210,14 +210,14 @@ def test_start_error_broad_exception(self, *args):
@patch('kytos.core.controller.Controller.start_controller')
@patch('kytos.core.controller.Controller.create_pidfile')
@patch('kytos.core.controller.Controller.enable_logs')
def test_start_with_mongodb_and_apm(self, *args):
async def test_start_with_mongodb_and_apm(self, *args):
"""Test start method with database and APM options set."""
(mock_enable_logs, mock_create_pidfile,
mock_start_controller, mock_db_conn_wait,
mock_init_apm) = args
self.controller.options.database = "mongodb"
self.controller.options.apm = "es"
self.controller.start()
await self.controller.start()

mock_enable_logs.assert_called()
mock_create_pidfile.assert_called()
Expand All @@ -229,11 +229,11 @@ def test_start_with_mongodb_and_apm(self, *args):
@patch('kytos.core.controller.sys.exit')
@patch('kytos.core.controller.Controller.create_pidfile')
@patch('kytos.core.controller.Controller.enable_logs')
def test_start_with_invalid_database_backend(self, *args):
async def test_start_with_invalid_database_backend(self, *args):
"""Test start method with unsupported database backend."""
(mock_enable_logs, _, mock_sys_exit) = args
self.controller.options.database = "invalid"
self.controller.start()
await self.controller.start()
mock_enable_logs.assert_called()
mock_sys_exit.assert_called()

Expand Down Expand Up @@ -722,7 +722,7 @@ async def test_start_controller(self, controller, monkeypatch):
controller.api_server = MagicMock()
controller.load_napps = MagicMock()
controller.options.napps_pre_installed = [napp]
controller.start_controller()
await controller.start_controller()
assert controller.buffers

controller.server.serve_forever.assert_called()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_core/test_kytosd.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_async_main(*args):

async_main(MagicMock())

event_loop.call_soon.assert_called_with(controller.start)
event_loop.run_until_complete.assert_called_with(controller.start())

@patch("builtins.open", create=True)
@patch('kytos.core.kytosd.os')
Expand Down

0 comments on commit 1a1df5b

Please sign in to comment.