Commit 2bd98c8f authored by Lorenz Steinert's avatar Lorenz Steinert

added more get tests

parent 41454ee7
......@@ -3,8 +3,9 @@
"""test the esme module"""
import os
import unittest
import configparser
import ldap3 as ldap
from esme import FsrLdap, get_fallback_fsr, get_fallback_fsr_extern, get_sprecher, get_protokollant
from esme import FsrLdap, get_fallback_fsr, get_fallback_fsr_extern, get_sprecher, get_protokollant, get_config, get_share, get_path
class FsrLdapTest(unittest.TestCase):
"""test the functions with ldap"""
......@@ -71,12 +72,34 @@ class GetFuncTest(unittest.TestCase):
def setUp(self):
"""setup for the tests"""
os.mkdir("/tmp/python3-esme-testing")
os.mkdir("/tmp/python3-esme-testing/etc")
os.mkdir("/tmp/python3-esme-testing/etc/test")
os.mkdir("/tmp/python3-esme-testing/share")
with open("/tmp/python3-esme-testing/fsr", 'w') as fobj:
fobj.write("testing test1\n")
with open("/tmp/python3-esme-testing/fsr_extern", 'w') as fobj:
fobj.write("testing test2")
self.config = {'PROTOKOLL': {'Sprecher': 'testsprecher',
'Protokollant': 'testprotokollant'}}
self.config = configparser.ConfigParser()
self.config['PROTOKOLL'] = {'Sprecher': 'testsprecher',
'Protokollant': 'testprotokollant',
'share': '/tmp/python3-esme-testing/share',
'path': '/tmp/python3-esme-testing'}
self.config['SERVER'] = {'name': 'test_server',
'base': 'dc=test,dc=de',
'connect_timeout': 10}
with open("/tmp/python3-esme-testing/etc/proto.ini", 'w') as fobj:
self.config.write(fobj)
self.config1 = configparser.ConfigParser()
self.config1['PROTOKOLL'] = {'Sprecher': 'testsprecher',
'Protokollant': 'testprotokollant',
'share': '/tmp/python3-esme-testing/share',
'path': '/tmp/python3-esme-testing'}
self.config1['SERVER'] = {'name': 'test_server',
'base': 'dc=test,dc=de',
'connect_timeout': 10}
self.config1['DEFAULT'] = {'tmp': 'tmp'}
with open("/tmp/python3-esme-testing/etc/proto.ini.default", 'w') as fobj:
self.config1.write(fobj)
@staticmethod
def input_test(arg):
......@@ -116,12 +139,39 @@ class GetFuncTest(unittest.TestCase):
self.assertEqual(get_protokollant(getinput=self.input_test), "testinginput")
self.assertEqual(get_protokollant(getinput=self.input_test2), "")
def test_get_config(self):
"""test the get_config function"""
self.assertEqual(get_config("", "/tmp/python3-esme-testing/etc/proto.ini"), self.config)
self.assertEqual(get_config("/tmp/python3-esme-testing/etc"), self.config)
os.remove("/tmp/python3-esme-testing/etc/proto.ini")
self.assertEqual(get_config("/tmp/python3-esme-testing/etc"), self.config1)
self.assertEqual(get_config("/tmp/python3-esme-testing/etc", default=True), self.config1)
def test_get_share(self):
"""test the get_share function"""
self.assertEqual(get_share("", self.config), '/tmp/python3-esme-testing/share')
self.assertEqual(os.path.abspath(get_share("/tmp/python3-esme-testing/share")), '/tmp/python3-esme-testing/share')
self.assertEqual(os.path.abspath(get_share("", self.config, '/tmp/python3-esme-testing/share')), '/tmp/python3-esme-testing/share')
def test_get_path(self):
"""test the get_path function"""
self.assertEqual(get_path("", self.config), '/tmp/python3-esme-testing')
self.assertEqual(os.path.abspath(get_path("/tmp/python3-esme-testing/etc/test")), '/tmp/python3-esme-testing')
self.assertEqual(os.path.abspath(get_path("", self.config, '/tmp/python3-esme-testing')), '/tmp/python3-esme-testing')
def tearDown(self):
"""cleanup after tests"""
if os.path.isfile('/tmp/python3-esme-testing/fsr'):
os.remove("/tmp/python3-esme-testing/fsr")
if os.path.isfile('/tmp/python3-esme-testing/fsr_extern'):
os.remove("/tmp/python3-esme-testing/fsr_extern")
if os.path.isfile('/tmp/python3-esme-testing/etc/proto.ini'):
os.remove("/tmp/python3-esme-testing/etc/proto.ini")
if os.path.isfile('/tmp/python3-esme-testing/etc/proto.ini.default'):
os.remove("/tmp/python3-esme-testing/etc/proto.ini.default")
os.rmdir("/tmp/python3-esme-testing/etc/test")
os.rmdir("/tmp/python3-esme-testing/etc")
os.rmdir("/tmp/python3-esme-testing/share")
os.rmdir("/tmp/python3-esme-testing")
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment