22"""
33Notificator Queue unit tests
44"""
5+ import asyncio
6+
57import pytest
68
79from common .peewee_model import NotificationType
@@ -33,9 +35,10 @@ async def _notified_users_cnt(pool):
3335 return res [0 ]
3436
3537 @staticmethod
36- @pytest .mark .asyncio
37- async def test_queue_empty (asyncpg_pool , event_loop ):
38+ @pytest .mark .asyncio ( loop_scope = "function" )
39+ async def test_queue_empty (asyncpg_pool ):
3840 """Tests queue single run when its empty"""
41+ event_loop = asyncio .get_running_loop ()
3942 queue = await TestNotificatorQueue ._build_queue (asyncpg_pool , event_loop )
4043 await queue ._process_queue ()
4144 # Queues should be empty
@@ -44,9 +47,10 @@ async def test_queue_empty(asyncpg_pool, event_loop):
4447 NotificatorQueue .delete ()
4548
4649 @staticmethod
47- @pytest .mark .asyncio
48- async def test_queue_nonexisting (asyncpg_pool , event_loop ):
50+ @pytest .mark .asyncio ( loop_scope = "function" )
51+ async def test_queue_nonexisting (asyncpg_pool ):
4952 """Tests queue run with non existing sys_vuln"""
53+ event_loop = asyncio .get_running_loop ()
5054 queue = await TestNotificatorQueue ._build_queue (asyncpg_pool , event_loop )
5155 # add nonexisting sys vuln to queue
5256 queue .notif_cves_queue [1337 ] = QueueItem ("CVE-NONEXISTING" , 1337 , 0 , "0" , [NotificationType .CVSS_NOTIFICATION ])
@@ -60,9 +64,10 @@ async def test_queue_nonexisting(asyncpg_pool, event_loop):
6064 NotificatorQueue .delete ()
6165
6266 @staticmethod
63- @pytest .mark .asyncio
64- async def test_queue_non_advisor_eval (asyncpg_pool , event_loop ):
67+ @pytest .mark .asyncio ( loop_scope = "function" )
68+ async def test_queue_non_advisor_eval (asyncpg_pool ):
6569 """Tests queue run with not yet advisor evaluated system"""
70+ event_loop = asyncio .get_running_loop ()
6671 queue = await TestNotificatorQueue ._build_queue (asyncpg_pool , event_loop )
6772
6873 # insert into db system which is not advisor evaluated and has single CVE
@@ -88,9 +93,10 @@ async def test_queue_non_advisor_eval(asyncpg_pool, event_loop):
8893 NotificatorQueue .delete ()
8994
9095 @staticmethod
91- @pytest .mark .asyncio
92- async def test_queue_mitigated (asyncpg_pool , event_loop ):
96+ @pytest .mark .asyncio ( loop_scope = "function" )
97+ async def test_queue_mitigated (asyncpg_pool ):
9398 """Test queue run but cve gets mitigated"""
99+ event_loop = asyncio .get_running_loop ()
94100 queue = await TestNotificatorQueue ._build_queue (asyncpg_pool , event_loop )
95101
96102 # insert into db system which is not vulnerable anymore, based on the advisor listener
@@ -117,9 +123,10 @@ async def test_queue_mitigated(asyncpg_pool, event_loop):
117123 NotificatorQueue .delete ()
118124
119125 @staticmethod
120- @pytest .mark .asyncio
121- async def test_queue_valid (asyncpg_pool , event_loop ):
126+ @pytest .mark .asyncio ( loop_scope = "function" )
127+ async def test_queue_valid (asyncpg_pool ):
122128 """Test queue run with valid system vulnerabilities, which should be notified"""
129+ event_loop = asyncio .get_running_loop ()
123130 msgs = []
124131
125132 def _send_kafka_notif_mock (self , acc_id , event_type , * _ , ** __ ):
@@ -156,9 +163,10 @@ def _send_kafka_notif_mock(self, acc_id, event_type, *_, **__):
156163 NotificatorQueue .delete ()
157164
158165 @staticmethod
159- @pytest .mark .asyncio
160- async def test_queue_unknown_cve (asyncpg_pool , event_loop ):
166+ @pytest .mark .asyncio ( loop_scope = "function" )
167+ async def test_queue_unknown_cve (asyncpg_pool ):
161168 """Test queue run with unknown cve vulnerabilities yet"""
169+ event_loop = asyncio .get_running_loop ()
162170 queue = await TestNotificatorQueue ._build_queue (asyncpg_pool , event_loop )
163171
164172 # insert into db system which vulnerable to CVE which vulnerability does not know yet
0 commit comments