# 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
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(
"(&"
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(
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)"
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