From: Michael Tremer Date: Fri, 14 Oct 2022 17:33:32 +0000 (+0000) Subject: tests: Mark that we are in test mode and disable LDAP stuff X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef1960e3622c0246043622cfe31d7637238b2948;p=pbs.git tests: Mark that we are in test mode and disable LDAP stuff Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/__init__.py b/src/buildservice/__init__.py index 2cdd2f56..2bda0608 100644 --- a/src/buildservice/__init__.py +++ b/src/buildservice/__init__.py @@ -48,8 +48,10 @@ class Backend(object): # A list of any background tasks __tasks = set() - def __init__(self, config_file): - # Read configuration file. + def __init__(self, config_file, test=False): + self.test = test + + # Read configuration file self.config = self.read_config(config_file) # Fetch the base path diff --git a/src/buildservice/users.py b/src/buildservice/users.py index 937a14f4..56f31b46 100644 --- a/src/buildservice/users.py +++ b/src/buildservice/users.py @@ -197,6 +197,11 @@ class Users(base.Object): if user: return user + # Do nothing in test mode + if self.backend.test: + log.warning("Cannot use get_by_name test mode") + return + # Search in LDAP res = self._ldap_get( "(&" @@ -216,7 +221,12 @@ class Users(base.Object): def get_by_email(self, mail): # Strip any excess stuff from the email address - name, mail = email.util.parseaddr(mail) + name, mail = email.utils.parseaddr(mail) + + # Do nothing in test mode + if self.backend.test: + log.warning("Cannot use get_by_email in test mode") + return # Search in LDAP res = self._ldap_get( @@ -240,6 +250,11 @@ class Users(base.Object): return self.get_by_name(uid) def search(self, q, limit=None): + # Do nothing in test mode + if self.backend.test: + log.warning("Cannot search for users in test mode") + return [] + res = self._ldap_query( "(&" "(objectClass=person)" diff --git a/tests/test.py b/tests/test.py index 8b4defc1..9230a072 100644 --- a/tests/test.py +++ b/tests/test.py @@ -90,7 +90,7 @@ class TestCase(unittest.IsolatedAsyncioTestCase): f.flush() # Initialize the backend - self.backend = Backend(f.name) + self.backend = Backend(f.name, test=True) # Create handle to the database self.db = self.backend.db