1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

netcmd: tests: make use of addCleanup

Makes self.members redundant and tearDown method can go completely.

Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Rob van der Linde 2023-10-17 18:54:52 +13:00 committed by Andrew Bartlett
parent 3e9f74a680
commit ed245e2887

View File

@ -21,7 +21,6 @@
# #
import json import json
from collections import defaultdict
from unittest.mock import patch from unittest.mock import patch
from samba.netcmd.domain.models.exceptions import ModelError from samba.netcmd.domain.models.exceptions import ModelError
@ -470,29 +469,18 @@ class AuthSiloMemberCmdTestCase(BaseAuthCmdTest):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.members = defaultdict(list)
# Create an organisational unit to test in. # Create an organisational unit to test in.
self.ou = self.samdb.get_default_basedn() self.ou = self.samdb.get_default_basedn()
self.ou.add_child("OU=Domain Auth Tests") self.ou.add_child("OU=Domain Auth Tests")
self.samdb.create_ou(self.ou) self.samdb.create_ou(self.ou)
self.addCleanup(self.samdb.delete, self.ou, ["tree_delete:1"])
# Assign members to silos # Assign members to silos
self.add_silo_member("Developers", "bob") self.add_silo_member("Developers", "bob")
self.add_silo_member("Developers", "jane") self.add_silo_member("Developers", "jane")
self.add_silo_member("Managers", "alice") self.add_silo_member("Managers", "alice")
def tearDown(self):
# Remove organisational unit.
self.samdb.delete(self.ou, ["tree_delete:1"])
# Remove members from silos.
for silo, members in self.members.items():
for member in members:
self.remove_silo_member(silo, member)
super().tearDown()
def create_computer(self, name): def create_computer(self, name):
"""Create a Computer and return the dn.""" """Create a Computer and return the dn."""
dn = f"CN={name},{self.ou}" dn = f"CN={name},{self.ou}"
@ -507,9 +495,7 @@ class AuthSiloMemberCmdTestCase(BaseAuthCmdTest):
self.assertIsNone(result, msg=err) self.assertIsNone(result, msg=err)
self.assertIn(f"User '{member}' added to the {silo} silo.", out) self.assertIn(f"User '{member}' added to the {silo} silo.", out)
self.addCleanup(self.remove_silo_member, silo, member)
# Ensure that tearDown cleans up the silo members.
self.members[silo].append(member)
def remove_silo_member(self, silo, member): def remove_silo_member(self, silo, member):
"""Remove a member to an authentication silo.""" """Remove a member to an authentication silo."""