Skip to content

Commit

Permalink
improved unit test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Josephine.Rutten committed Dec 20, 2024
1 parent da6c763 commit fce3f20
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/cnaas_nms/api/tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from cnaas_nms.db.device import Device, DeviceState, DeviceType
from cnaas_nms.db.interface import Interface, InterfaceConfigType
from cnaas_nms.db.session import sqla_session
from cnaas_nms.db.stackmember import Stackmember


@pytest.mark.integration
Expand All @@ -24,10 +23,10 @@ def requirements(self, postgresql, settings_directory):

def cleandb(self):
with sqla_session() as session: # type: ignore
for hardware_id in ["AB1234", "CD5555", "GF43534"]:
stack = session.query(Stackmember).filter(Stackmember.hardware_id == hardware_id).one_or_none()
if stack:
session.delete(stack)
for interface_name in ["testinterface1", "testinterface2"]:
interface = session.query(Interface).filter(Interface.name == interface_name).one_or_none()
if interface:
session.delete(interface)
session.commit()
for hostname in ["testdevice", "testdevice2"]:
device = session.query(Device).filter(Device.hostname == hostname).one_or_none()
Expand Down

0 comments on commit fce3f20

Please sign in to comment.