@@ -58,8 +58,15 @@ def test_get_db_connection(
5858 self .assertEqual (OpenvasDB .get_database_address (), "unix:///foo/bar" )
5959 self .assertEqual (mock_openvas .get_settings .call_count , 2 )
6060
61- def test_create_context_fail (self , mock_redis ):
61+ @patch ('ospd_openvas.db.Openvas' )
62+ def test_create_context_fail (self , mock_openvas : MagicMock , mock_redis ):
6263 mock_redis .from_url .side_effect = RCE
64+ mock_check = mock_openvas .check .return_value
65+ mock_check .get .return_value = True
66+
67+ OpenvasDB ._db_address = None # pylint: disable=protected-access
68+ mock_settings = mock_openvas .get_settings .return_value
69+ mock_settings .get .return_value = None
6370
6471 logging .Logger .error = MagicMock ()
6572
@@ -71,8 +78,16 @@ def test_create_context_fail(self, mock_redis):
7178 'Redis Error: Not possible to connect to the kb.'
7279 )
7380
74- def test_create_context_success (self , mock_redis ):
81+ @patch ('ospd_openvas.db.Openvas' )
82+ def test_create_context_success (self , mock_openvas : MagicMock , mock_redis ):
7583 ctx = mock_redis .from_url .return_value
84+ mock_check = mock_openvas .check .return_value
85+ mock_check .get .return_value = True
86+
87+ OpenvasDB ._db_address = None # pylint: disable=protected-access
88+ mock_settings = mock_openvas .get_settings .return_value
89+ mock_settings .get .return_value = None
90+
7691 ret = OpenvasDB .create_context ()
7792 self .assertIs (ret , ctx )
7893
@@ -328,18 +343,38 @@ def test_get_key_count_error(self, mock_redis):
328343 with self .assertRaises (RequiredArgument ):
329344 OpenvasDB .get_key_count (None )
330345
331- def test_find_database_by_pattern_none (self , mock_redis ):
346+ @patch ('ospd_openvas.db.Openvas' )
347+ def test_find_database_by_pattern_none (
348+ self , mock_openvas : MagicMock , mock_redis
349+ ):
332350 ctx = mock_redis .from_url .return_value
333351 ctx .keys .return_value = None
334352
353+ mock_check = mock_openvas .check .return_value
354+ mock_check .get .return_value = True
355+
356+ OpenvasDB ._db_address = None # pylint: disable=protected-access
357+ mock_settings = mock_openvas .get_settings .return_value
358+ mock_settings .get .return_value = None
359+
335360 new_ctx , index = OpenvasDB .find_database_by_pattern ('foo*' , 123 )
336361
337362 self .assertIsNone (new_ctx )
338363 self .assertIsNone (index )
339364
340- def test_find_database_by_pattern (self , mock_redis ):
365+ @patch ('ospd_openvas.db.Openvas' )
366+ def test_find_database_by_pattern (
367+ self , mock_openvas : MagicMock , mock_redis
368+ ):
341369 ctx = mock_redis .from_url .return_value
342370
371+ mock_check = mock_openvas .check .return_value
372+ mock_check .get .return_value = True
373+
374+ OpenvasDB ._db_address = None # pylint: disable=protected-access
375+ mock_settings = mock_openvas .get_settings .return_value
376+ mock_settings .get .return_value = None
377+
343378 # keys is called twice per iteration
344379 ctx .keys .side_effect = [None , None , None , None , True , True ]
345380
@@ -689,9 +724,17 @@ def test_release(self, mock_redis):
689724 ctx .hdel .assert_called_with (DBINDEX_NAME , maindb .index )
690725 ctx .flushdb .assert_called_with ()
691726
692- def test_get_new_kb_database (self , mock_redis ):
727+ @patch ('ospd_openvas.db.Openvas' )
728+ def test_get_new_kb_database (self , mock_openvas : MagicMock , mock_redis ):
693729 ctx = mock_redis .from_url .return_value
694730
731+ mock_check = mock_openvas .check .return_value
732+ mock_check .get .return_value = True
733+
734+ OpenvasDB ._db_address = None # pylint: disable=protected-access
735+ mock_settings = mock_openvas .get_settings .return_value
736+ mock_settings .get .return_value = None
737+
695738 maindb = MainDB (ctx )
696739 maindb ._max_dbindex = 123 # pylint: disable=protected-access
697740
0 commit comments