]> git.ipfire.org Git - pbs.git/commitdiff
tests: Mark that we are in test mode and disable LDAP stuff
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Oct 2022 17:33:32 +0000 (17:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Oct 2022 17:33:32 +0000 (17:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/__init__.py
src/buildservice/users.py
tests/test.py

index 2cdd2f5609a8609b477fe5dda6e190086785456d..2bda06085f9727922142d7747d601476d6d43306 100644 (file)
@@ -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
index 937a14f4c230df722aff73d639128bbd3c67f899..56f31b46e6c40871c4f52563c310074e624fb58e 100644 (file)
@@ -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)"
index 8b4defc1c5e504c2a0ccf34a0f91e9e74155d156..9230a07226f197a66eb66d2820fe74341b215584 100644 (file)
@@ -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