Commit 3eaaba32 authored by Patrick Mischke's avatar Patrick Mischke
parents 28e2090d 8fe89c27
*.ini
__pycache__
tags
test:
except:
- schedules
image: python:3.6-alpine
before_script:
- pacman -Sy --noconfirm python3 python-ldap3
script: python3 bin/module/test.py
- pip install ldap3
script:
- python bin/module/test.py
syntax:
except:
- schedules
image: debian:stretch
before_script:
- pacman -Sy --noconfirm flake8
script: flake8 --exclude .git,__pycache__,bin/module/test.py
- apt update > /dev/null
- apt install -y python-flake8 flake8 > /dev/null
script:
- /usr/bin/flake8 --exclude .git,__pycache__,bin/module/test.py
fallbackfiles:
only:
- schedules
image: python:3.6-alpine
before_script:
- export
- apk add git openssh-client bash
- git config --global user.email "protokoll@fs.physik.uni-kl.de"
- git config --global user.name "Protobot"
- pip install ldap3
- eval $( ssh-agent -s )
- echo -e "$SSH_PRIVATE_KEY" | ssh-add -
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
script:
- python bin/generate_fallback.py
- git add share/fsr share/fsr_extern
- '[ ! -z "$(git status --porcelain)" ] && git commit -m "updated fallbackfiles"'
- git push git@gitlab.rlp.net:fsr_physik_tu_kl/protokoll/protokoll_skript.git HEAD:master
Skript zur halbwegs automatischen Erstellung von FSR-Protokollen
================================================================
================================================================
1. Konfiguration
================
Von normalen Usern koennen folgende Dinge festgelegt werden:
- aktueller Sprecher (=> automatisch Sitzungsleiter)
- aktueller Protokollant (=> Unterschrift)
- Anzahl der Spalten in der Anwesenheitsliste
- Leute in der Anwesenheitsliste
Fuer die ersten drei Punkte muss die Datei "protskript_test.py" in beliebigem Texteditor
geöffnet und die entsprechenden Variablen (im markierten Bereich) geaendert
werden. Fuer den vierten Punkt müssen die Dateien fsr und fsr_extern bearbeitet werden. In diesen
muss in jeder Zeile genau ein Name stehen. Diese Dateien werden automatisch sortiert.
2. Bedienung
============
- ins Verzeichnis wo das Skript liegt wechseln
- "./protskript_test.py" eingeben
- Sitzungsleiter/Protokollant/Datum eingeben bzw. Standardwerte übernehmen
- wenn beim Übersetzen etwas schief ging: Den Fehler beheben und zweimal(!)
"pdflatex <datei>" (natürlich mit passendem Wert für <datei>) eingeben. Wenn
pdflatex nur einmal läuft wird die Seitenzahl falsch ausgegeben.
- Protokoll drucken, rumschicken und aushaengen
3. Bugs
=======
- momentan keine bekannt
- Meldungen an protokoll@fs.physik.uni-kl.de
Installation
---------------
1. git installieren
2. `git clone git@gitlab.rlp.net:fsr_physik_tu_kl/protokoll/protokolle_src.git <dateipfad>`
3. `git submodule init`
4. `git submodule update`
Konfiguration
----------------
Von normalen Usern koennen folgende Dinge festgelegt werden können mehere
Variablen festgelegt werden. Hierzu die datei `bin/generate_ini.py` ausführen.
Voreingestellte Standardwerte sind in `[]` angegeben und können ohne eingabe
übernommen werden. Sollten Werte unbekant sein oder nicht verständlich so solten
zuerst die Standardwerte ausprobiert werden.
Bedienung
------------
1. ins Verzeichnis wo das Skript liegt wechseln
2. `./proto.py` eingeben
3. die gefragten Werte eingeben oder die Standardwerte übernehmen
4. in das Protokoll verzeichnis wechseln und die Vorlage bearbeiten.
5. 3x `pdflatex` ausführen
6. Protokoll drucken, rumschicken und aushaengen
Fallbackfile update
-------------------
Die Fallbackfiles sind dazu da die Anwesenheitslisten zu generieren, wenn
der LDAP-Server der fachschaft nicht ereichbar ist. Um die Fallbackfies zu
updaten führe `bin/generate_fallback.py` aus. Sollte eine Verbindung zum
LDAP-Server der Fachschaft nicht möglich sein werden keine änderungen
vorgenommen. Sollte dies der fall sein frage bitte beim Rechnerreferat nach.
Bugs
-------
Siehe https://gitlab.rlp.net/fsr_physik_tu_kl/protokoll/protokoll_skript/issues
......@@ -3,7 +3,7 @@
"""
Created on Fri Nov 24 15:35:04 2017
@author: lorico
@author: Lorenz Steinert
"""
import os
......
......@@ -11,7 +11,7 @@ if __name__ == "__main__":
RUNDIR = os.path.dirname(os.path.realpath(__file__))
PARSER = argparse.ArgumentParser(description="generate ini file \
for the protokollskript")
for the Protokoll Script")
PARSER.add_argument('-c', '--config',
default=os.path.join(RUNDIR, '../etc/proto.ini'),
help="location of generated config file")
......@@ -19,7 +19,7 @@ if __name__ == "__main__":
CONFIG = get_config(RUNDIR, default=True)
print('Die Werte in [] können ohne eingabe übernommen werden.')
print('Die Werte in [] können ohne Eingabe übernommen werden.')
for i in CONFIG:
print('['+i+']')
......
......@@ -23,7 +23,9 @@ except ImportError:
class Error(Flag):
"""Error constants for the FsrLdap class"""
"""
Error constants for the FsrLdap class
"""
UNSEC_SEARCH = auto()
NO_FILE = auto()
LDAP_FAIL = auto()
......@@ -33,14 +35,18 @@ class Error(Flag):
def current_user():
"""get the current user"""
"""
get the uid of the current user
"""
if pwd:
return pwd.getpwuid(os.geteuid()).pw_name
return getpass.getuser()
def resort_fsr(fsr, num_cols=5):
"""resort list for pascal style sorting"""
"""
resort list of names by pascal style
"""
fsr += [""] * (num_cols - len(fsr) % num_cols)
depth = len(fsr) // num_cols
......@@ -53,7 +59,9 @@ def resort_fsr(fsr, num_cols=5):
class FsrLdap:
"""Class die die protokoll .tex datei erstellt"""
"""
Class providing LDAP integration
"""
def __init__(self, server, base, share_dir, config, debug=False,
timeout=1, testing=None):
......@@ -77,7 +85,11 @@ class FsrLdap:
self.config = config
def _get_protokollant_ldap(self):
"""search the LDAP for the current user"""
"""
get the name of the current user by searching the LDAP-Server
if the search is unsuccessful return Error.UNSEC_SEARCH
if the search fails because of a LDAPException return Error.LDAP_FAIL
"""
logging.info("Fetching Protokollant from LDAP ...")
try:
fil = "(uid="+current_user()+")"
......@@ -88,15 +100,20 @@ class FsrLdap:
return Error.UNSEC_SEARCH
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
logging.warning("Couldn't Connect to ldap. \
Using fallback default. %s" % error_message)
logging.warning("Couldn't connect to the LDAP-Server. \
Using fall-back default. %s" % error_message)
else:
logging.warning("Couldn't Connect to ldap. Using fallback default.") # noqa: E501
logging.warning("Couldn't Connect to the LDAP-Server. Using fall-back default.") # noqa: E501
return Error.LDAP_FAIL
@staticmethod
def _get_fallback_protokollant(config=None):
"""get protokollant from user input or config"""
"""
get the name of the Protokollant from user input or config
The values are used in this order:
- the Protokollant provided by the user
- config['PROTOKOLL']['Protokollant']
"""
protokollant = ''
if config:
protokollant = config['PROTOKOLL']['Protokollant']
......@@ -106,13 +123,20 @@ class FsrLdap:
return protokollant
def get_protokollant(self, config=None):
"""get protokollant"""
"""
get the Name of the Protokollant
The Name sources are used in this order:
- LDAP-Server
- user input
- config
if non is found return an empty string
"""
if not config:
config = self.config
protokollant = self._get_protokollant_ldap()
if isinstance(protokollant, tuple):
pass
protokollant = protokollant[0]
elif isinstance(protokollant, Flag):
if protokollant in Error.UNSEC_SEARCH | Error.LDAP_FAIL:
......@@ -122,7 +146,12 @@ class FsrLdap:
return protokollant
def _get_fsr_ldap(self):
"""get fsr from LDAP"""
"""
get the list of the names of the FSR by searching the LDAP-Server
if the search is unsuccessful return Error.UNSEC_SEARCH
if the search fails because of a LDAPException return Error.LDAP_FAIL
"""
logging.info("Fetching FSR from LDAP ...")
try:
fil = '(cn=intern)'
......@@ -141,27 +170,40 @@ class FsrLdap:
return Error.UNSEC_SEARCH
except ldap.core.exceptions.LDAPException as error_message:
if self.debug:
logging.warning("Couldn't Connect to ldap. \
Using fallback File. %s" % error_message)
logging.warning("Couldn't Connect to the LDAP-Server. \
Using the fall-back file. %s" % error_message)
else:
logging.warning("Couldn't Connect to ldap. Using fallback File.") # noqa: E501
logging.warning("Couldn't Connect to the LDAP-Server. Using fall-back file.") # noqa: E501
return (Error.LDAP_FAIL, error_message)
@staticmethod
def _get_fallback_fsr(share_dir):
"""get fsr form fallback file"""
"""
get the list of the names of the FSR from the fall back file
if the file is not found return Error.NO_FILE
"""
if os.path.isfile(os.path.join(share_dir, 'fsr')):
with codecs.open(os.path.join(share_dir, 'fsr'),
'r', 'utf-8') as fobj:
fsr = sorted([re.sub(re.escape('\t'), ' ',
line.rstrip('\n'))
for line in fobj.readlines()],
for line in fobj.readlines()
if line.rstrip('\n')],
key=lambda x: ''.join(x.split(' ')[::-1]))
return fsr
return Error.NO_FILE
def get_fsr(self, share_dir=None, gen_fallback=None):
"""get fsr"""
"""
get a sorted list of the names of the FSR
The name sources are used in this order:
- LDAP-Server
- user input
- fall-back file
if non is found return an empty list
"""
if not share_dir:
share_dir = self.share_dir
......@@ -175,11 +217,17 @@ class FsrLdap:
if isinstance(fsr, Error):
if fsr & (Error.NO_FILE | Error.UNSEC_SEARCH):
fsr = []
return resort_fsr(fsr)
return resort_fsr(fsr, num_cols=self.config['PROTOKOLL'].getint('NUM_COLS')) # noqa: E501
def _get_fsr_extern_ldap(self):
"""get the EFSR from LDAP"""
logging.info("Fetching EFSR from LDAP ...")
"""
get the list of the names of the eFSR
by searching the LDAP-Server
if the search is unsuccessful return Error.UNSEC_SEARCH
if the search fails because of a LDAPException return Error.LDAP_FAIL
"""
logging.info("Fetching eFSR from LDAP ...")
try:
fil = '(cn=extern)'
fsr_extern = []
......@@ -200,24 +248,35 @@ class FsrLdap:
logging.warning("Couldn't Connect to ldap. \
Using fallback File. %s" % error_message)
else:
logging.warning("Couldn't Connect to ldap. Using fallback File.") # noqa: E501
logging.warning("Couldn't connect to the LDAP-Server. Using fall-back file.") # noqa: E501
return (Error.LDAP_FAIL, error_message)
@staticmethod
def _get_fallback_fsr_extern(share_dir):
"""get fsr_extern from fallback file"""
"""
get the list of the names of the extern FSR from the fall back file
if the file is not found return Error.NO_FILE
"""
if os.path.isfile(os.path.join(share_dir, 'fsr_extern')):
with codecs.open(os.path.join(share_dir, 'fsr_extern'),
'r', 'utf-8') as fobj:
fsr_extern = sorted([re.sub(re.escape('\t'), ' ',
line.rstrip('\n'))
for line in fobj.readlines()],
for line in fobj.readlines()
if line.rstrip('\n')],
key=lambda x: ''.join(x.split(' ')[::-1]))
return fsr_extern
return Error.NO_FILE
def get_fsr_extern(self, share_dir=None, gen_fallback=None):
"""get fsr extern"""
"""
get a sorted list of the names of the eFSR
The name sources are used in this order:
- LDAP-Server
- fall-back file
if non is found return an empty list
"""
if not share_dir:
share_dir = self.share_dir
......@@ -232,11 +291,16 @@ class FsrLdap:
if isinstance(fsr_extern, Error):
if fsr_extern & (Error.NO_FILE | Error.UNSEC_SEARCH):
fsr_extern = []
return resort_fsr(fsr_extern)
return resort_fsr(fsr_extern, num_cols=self.config['PROTOKOLL'].getint('NUM_COLS_EXT')) # noqa: E501
def get_sprecher(config=None):
"""get sprecher from user input or config"""
"""
get Sprecher from user input or config
The values are used in this order:
- the Sprecher provided by the user
- config['PROTOKOLL']['Sprecher']
"""
sprecher = ''
if config:
sprecher = config['PROTOKOLL']['Sprecher']
......@@ -247,7 +311,13 @@ def get_sprecher(config=None):
def get_date(test=False):
"""get current date then ask user"""
"""
get current date then ask user
The dates are used in this order:
- if test is true use the 01.01.2000
- the date provided by the user
- the current system time
"""
if test:
date = ('01.01.2000', '2000', '01', '01')
else:
......@@ -274,7 +344,9 @@ def get_date(test=False):
def get_editor(editor):
"""get the editor to use from user input"""
"""
get the editor to use from user input
"""
etmp = input("Editor ["+editor+"]: ")
if etmp != "":
return etmp
......@@ -282,7 +354,18 @@ def get_editor(editor):
def get_config(rundir, config_path=None, default=False):
"""get the location of the config file and load configparser"""
"""
get the location of the config file and load configparser
The files are used in this order:
- `config_path`
- if default is specified:
- `rundir/../etc/proto.ini.default`
- `rundir/../etc/proto.ini`
- `rundir/../etc/proto.ini.default`
if the file given by config_path is not found return Error.NO_FILE
if the default file is not found return Error.NO_DEFAULT_FILE
"""
if config_path:
if os.path.isfile(config_path):
config = configparser.ConfigParser()
......@@ -297,7 +380,7 @@ def get_config(rundir, config_path=None, default=False):
return config
logging.warning('No default File found at '
+ os.path.abspath(os.path.join(rundir,
'../etc/proto.ini.default'))) # noqa: E501
'../etc/proto.ini.default'))) # noqa: E501
return Error.NO_DEFAULT_FILE
elif os.path.isfile(os.path.join(rundir,
'../etc/proto.ini')) and not default:
......@@ -309,71 +392,118 @@ def get_config(rundir, config_path=None, default=False):
config = configparser.ConfigParser()
config.read(os.path.join(rundir, '../etc/proto.ini.default'))
return config
logging.warning('No ini file found. Using hardcoded defaults.')
logging.warning('No ini file found. Using hard codded defaults.')
return Error.NO_DEFAULT_FILE
def get_share(rundir, config=None, sharedir=None):
"""get the location of the share directory"""
"""
get the location of the share directory
The directories are used in this order:
- `sharedir`
- the one provided in config['PROTOKOLL']['share']
- if the path is a relative one it is relative
to the script directory
- `rundir/../share`
if a provided directory is not found return Error.NO_FILE
if the default directory is not found return Error.NO_DEFAULT_FILE
"""
if sharedir:
if os.path.isdir(sharedir):
return sharedir
logging.warning(sharedir + ': Not a Directory')
return Error.NO_DIR
elif config:
if os.path.isdir(config['PROTOKOLL']['share']):
config_share = config['PROTOKOLL']['share']
if os.path.isdir(config_share) and os.path.isabs(config_share):
return config['PROTOKOLL']['share']
logging.warning(config['PROTOKOLL']['share'] + ': Not a Directory')
elif os.path.isdir(os.path.join(rundir, '..', config_share)):
return os.path.normpath(os.path.join(rundir, '..', config_share))
logging.warning(config_share + ': Not a Directory')
return Error.NO_DIR
elif os.path.isdir(os.path.join(rundir, '../share')):
return os.path.join(rundir, '../share')
return os.path.normpath(os.path.join(rundir, '../share'))
logging.warning('No share Directory found at '
+ os.path.abspath(os.path.join(rundir, '../share')))
return Error.NO_DEFAULT_DIR
def get_path(rundir, config=None, path=None):
"""get the location of the protokoll directory"""
"""
get the location of the Protokoll directory
The directories are used in this order:
- `path`
- the one provided in config['PROTOKOLL']['path']
- if the path is a relative one it is relative
to the script directory
- `rundir/../..`
if a provided directory is not found return Error.NO_FILE
if the default directory is not found return Error.NO_DEFAULT_FILE
"""
if path:
if os.path.isdir(path):
return path
logging.warning(path + ': Not a Directory')
return Error.NO_DIR
elif config:
if os.path.isdir(config['PROTOKOLL']['path']):
return config['PROTOKOLL']['path']
config_path = config['PROTOKOLL']['path']
if os.path.isdir(config_path) and os.path.isabs(config_path):
return config_path
elif os.path.isdir(os.path.join(rundir, '..', config_path)):
return os.path.normpath(os.path.join(rundir, '..', config_path))
logging.warning(config['PROTOKOLL']['path'] + ': Not a Directory')
return Error.NO_DIR
elif os.path.isdir(os.path.join(rundir, '../..')):
return os.path.join(rundir, '../..')
return os.path.normpath(os.path.join(rundir, '../..'))
logging.warning('No Protokoll Directory found at '
+ os.path.abspath(os.path.join(rundir, '../..')))
+ os.path.normpath(os.path.join(rundir, '../..')))
return Error.NO_DEFAULT_DIR
def get_ldap_server(config=None, server=None):
"""get the ldap server for the fsr lookup"""
"""
get the LDAP-Server for the FSR lookup
The servers are used in this order:
- the server provided by server
- the server provided by config['SERVER']['NAME']
- `rincewind.fs.physik.uni-kl.de`
"""
if server:
return server
if config:
return config['SERVER']['NAME']
logging.warning('No LDAP Server supplied. Triing to use "rincwind.fs.physik.uni-kl.de".') # noqa: E501
logging.warning('No LDAP Server supplied. Trying to use "rincewind.fs.physik.uni-kl.de".') # noqa: E501
return "rincewind.fs.physik.uni-kl.de"
def get_ldap_base(config=None, base=None):
"""get the search base for the ldap server"""
"""
get the search base for the LDAP-Server
The bases are used in this order:
- the base provided by base
- the base provided by config['SERVER']['BASE']
- `dc=fs,dc=physik,dc=uni-kl,dc=de`
"""
if base:
return base
if config:
return config['SERVER']['BASE']
logging.warning('No LDAP search base supplied. '
'Triing to use "dc=fs,dc=physik,dc=uni-kl,dc=de".')
'Trying to use "dc=fs,dc=physik,dc=uni-kl,dc=de".')
return "dc=fs,dc=physik,dc=uni-kl,dc=de"
def get_server_timeout(config=None, test=None):
"""get the timeout for the connection to the ldap server"""
"""
get the timeout for the connection to the LDAP-Server
The timeouts are used in this order:
- if test is true:
- `1`
- config['SERVER']['connect_timeout']
- `10`
"""
if test:
return 1
if config:
......
......@@ -9,6 +9,7 @@ import configparser
import ldap3 as ldap
import esme
class FsrLdapTest(unittest.TestCase):
"""test the functions with ldap"""
......@@ -71,31 +72,37 @@ class FsrLdapTest(unittest.TestCase):
"""test the get_fsr_extern_ldap function"""
self.assertEqual(self.ldap_server._get_fsr_extern_ldap(),
['testing test2'])
self.assertEqual(self.info, ['Fetching EFSR from LDAP ...', 'Done'])
self.assertEqual(self.info, ['Fetching eFSR from LDAP ...', 'Done'])
self.assertEqual(self.warning, [])
def test_get_protokollant_ldap(self):
"""test the get_protokollant_ldap function"""
esme.current_user = lambda: 'test1'
self.assertEqual(self.ldap_server._get_protokollant_ldap(), 'testing test1')
self.assertEqual(self.info, ['Fetching Protokollant from LDAP ...', 'Done'])
self.assertEqual(self.ldap_server._get_protokollant_ldap(),
'testing test1')
self.assertEqual(self.info, ['Fetching Protokollant from LDAP ...',
'Done'])
self.assertEqual(self.warning, [])
def test_get_fallback_fsr(self):
"""test the get_fallback_fsr function"""
sharedir = "/tmp/python3-esme-testing"
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir), ['testing test1'])
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir),
['testing test1'])
os.remove("/tmp/python3-esme-testing/fsr")
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir), esme.Error.NO_FILE)
self.assertEqual(self.ldap_server._get_fallback_fsr(sharedir),
esme.Error.NO_FILE)
self.assertEqual(self.info, [])
self.assertEqual(self.warning, [])
def test_get_fallback_fsr_extern(self):
"""test the get_fallback_fsr_extern function"""
sharedir = "/tmp/python3-esme-testing"
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir), ['testing test2'])
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir),
['testing test2'])
os.remove("/tmp/python3-esme-testing/fsr_extern")
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir), esme.Error.NO_FILE)
self.assertEqual(self.ldap_server._get_fallback_fsr_extern(sharedir),
esme.Error.NO_FILE)
self.assertEqual(self.info, [])
self.assertEqual(self.warning, [])
......@@ -105,8 +112,10 @@ class FsrLdapTest(unittest.TestCase):
esme.input = lambda x: 'testinput'
self.assertEqual(self.ldap_server._get_fallback_protokollant(self.ldap_server.config),
"testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(config), "testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(), "testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(config),
"testinput")
self.assertEqual(self.ldap_server._get_fallback_protokollant(),
"testinput")
esme.input = lambda x: ''
self.assertEqual(self.ldap_server._get_fallback_protokollant(self.ldap_server.config),
......@@ -130,7 +139,7 @@ class FsrLdapTest(unittest.TestCase):
self.ldap_server.conn.search = self.ldap_search_fail
self.assertEqual(self.ldap_server._get_fsr_extern_ldap(),
esme.Error.UNSEC_SEARCH)
self.assertEqual(self.info, ['Fetching EFSR from LDAP ...'])
self.assertEqual(self.info, ['Fetching eFSR from LDAP ...'])
self.assertEqual(self.warning, [])
def test_get_protokollant_ldap_no_server(self):
......@@ -148,15 +157,17 @@ class FsrLdapTest(unittest.TestCase):
self.assertEqual(self.ldap_server._get_fsr_ldap()[0],
esme.Error.LDAP_FAIL)
self.assertEqual(self.info, ['Fetching FSR from LDAP ...'])
self.assertEqual(self.warning, ["Couldn't Connect to ldap. Using fallback File."])
self.assertEqual(self.warning,
["Couldn't Connect to the LDAP-Server. Using fall-back file."])
def test_get_fsr_extern_ldap_ldap_exception(self):
"""test the get_fsr_extern_ldap function with a LDAPException"""
self.ldap_server.conn.search = self.ldap_exception
self.assertEqual(self.ldap_server._get_fsr_extern_ldap()[0],
esme.Error.LDAP_FAIL)
self.assertEqual(self.info, ['Fetching EFSR from LDAP ...'])
self.assertEqual(self.warning, ["Couldn't Connect to ldap. Using fallback File."])
self.assertEqual(self.info, ['Fetching eFSR from LDAP ...'])
self.assertEqual(self.warning,
["Couldn't connect to the LDAP-Server. Using fall-back file."])
def test_get_protokollant_ldap_ldap_exception(self):
"""test the get_protokollant_ldap function with a LDAPException"""
......@@ -165,7 +176,8 @@ class FsrLdapTest(unittest.TestCase):
self.assertEqual(self.ldap_server._get_protokollant_ldap(),
esme.Error.LDAP_FAIL)
self.assertEqual(self.info, ['Fetching Protokollant from LDAP ...'])
self.assertEqual(self.warning, ["Couldn't Connect to ldap. Using fallback default."])
self.assertEqual(self.warning,
["Couldn't Connect to the LDAP-Server. Using fall-back default."])
def tearDown(self):
"""cleanup after the tests"""
......@@ -241,38 +253,53 @@ class GetFuncTest(unittest.TestCase):
def test_get_config(self):
"""test the get_config function"""
self.assertEqual(esme.get_config("", "/tmp/python3-esme-testing/etc/proto.ini"),
self.assertEqual(esme.get_config("",
"/tmp/python3-esme-testing/etc/proto.ini"),
self.config)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"),
self.config)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"), self.config)
os.remove("/tmp/python3-esme-testing/etc/proto.ini")
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"), self.config1)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc", default=True),
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"),
self.config1)
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc",
default=True),
self.config1)
os.remove("/tmp/python3-esme-testing/etc/proto.ini.default")
self.assertEqual(esme.get_config("/tmp/python3-esme-testing/etc"),
esme.Error.NO_DEFAULT_FILE)
esme.Error.NO_DEFAULT_FILE)
self.assertEqual(self.info, [])
self.assertEqual(self.warning, ['No non default ini file found using default file.',
'No ini file found. Using hardcoded defaults.'])
self.assertEqual(self.warning,
['No non default ini file found using default file.',
'No ini file found. Using hard codded defaults.'])
def test_get_share(self):
"""test the get_share function"""
self.assertEqual(esme.get_share("", self.config), '/tmp/python3-esme-testing/share')
self.assertEqual(os.path.abspath(esme.get_share("/tmp/python3-esme-testing/share")),
self.assertEqual(esme.get_share("", self.config),
'/tmp/python3-esme-testing/share')
self.assertEqual(esme.get_share("/tmp/python3-esme-testing/share"),
'/tmp/python3-esme-testing/share')
self.assertEqual(os.path.abspath(esme.get_share("", self.config,
'/tmp/python3-esme-testing/share')),
self.assertEqual(esme.get_share("", self.config,
'/tmp/python3-esme-testing/share'),
'/tmp/python3-esme-testing/share')
self.config['PROTOKOLL']['share'] = './share'
self.assertEqual(esme.get_share("/tmp/python3-esme-testing/share",
self.config),
'/tmp/python3-esme-testing/share')
self.assertEqual(self.info, [])
self.assertEqual(self.warning, [])
def test_get_path(self):
"""test the get_path function"""
self.assertEqual(esme.get_path("", self.config), '/tmp/python3-esme-testing')
self.assertEqual(os.path.abspath(esme.get_path("/tmp/python3-esme-testing/etc/test")),
self.assertEqual(esme.get_path("", self.config),
'/tmp/python3-esme-testing')
self.assertEqual(esme.get_path("/tmp/python3-esme-testing/etc/test"),
'/tmp/python3-esme-testing')
self.assertEqual(esme.get_path("",</