Added cleanup for each test case

This commit is contained in:
Sviatoslav Boichuk
2024-11-25 16:44:45 +02:00
parent d5b6de0047
commit c18c657255
2 changed files with 19 additions and 1 deletions

View File

@@ -67,9 +67,18 @@ def test_context():
ctx.device_sim.disconnect()
# Let's make sure we destroy default group after we're done with tests.
# Let's make sure we destroy all groups after we're done with tests.
if ctx.kafka_producer.is_connected():
# 1. Destroy default group
ctx.kafka_producer.handle_single_group_delete(ctx.default_kafka_group())
# 2. Get all groups from Redis or PostgeSQL
groups_list = ctx.psql_client.get_all_infrastructure_groups()
if groups_list != None:
# 3. Interate over groups
for group in groups_list:
# 4. Send group_del request
ctx.kafka_producer.handle_single_group_delete(str(group[0]))
# We have to clear any messages after done working with kafka
if ctx.kafka_consumer.is_connected():

View File

@@ -84,6 +84,15 @@ class PostgreSQLClient:
return group_info
def get_all_infrastructure_groups(self) -> List[Tuple[int, int, int]]:
"""Fetch group record by group id."""
group_list = list()
self.execute_query(f"select * from infrastructure_groups;")
group_list = self.fetchall()
return group_list
def get_infra(self, mac: str) -> Tuple[str, int]:
"""Fetch group record by infra mac."""
infra_info = None