import unittest import os import inspect import shutil import tools.path_tool import basic.program import test.testtools import basic.constants as B import test.constants as T import tools.file_tool import model.user import model.entity HOME_PATH = test.constants.HOME_PATH PYTHON_CMD = "python" TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity", "test_13writeEntity", "test_14insertEntity"] #TEST_FUNCTIONS = ["test_10getEntityNames"] PROGRAM_NAME = "clean_workspace" class MyTestCase(unittest.TestCase): mymsg = "--------------------------------------------------------------" def test_10getEntityNames(self): global mymsg global jobObject actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() user = model.user.User(job) entityNames = [] entityNames = user.read_unique_names(job, "", "", "", {}) self.assertEqual(type(entityNames), list) entityNames = user.select_unique_names(job, "", "", "", {}) self.assertEqual(type(entityNames), list) def test_11getEntities(self): global mymsg global jobObject actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() user = model.user.User(job) entityNames = [] entityNames = user.get_entities(job, storage=model.entity.STORAGE_FILE) self.assertEqual(type(entityNames), list) entityNames = user.get_entities(job, storage=model.entity.STORAGE_DB) self.assertEqual(type(entityNames), list) def test_12getEntity(self): global mymsg global jobObject actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() user = model.user.User(job) name = "ulrich" actUser = user.read_entity(job, name) self.assertEqual(getattr(actUser, model.user.FIELD_USERNAME), name) self.assertRaises(Exception, user.read_entity, job, "xyzxyz") # actUser = user.select_entity(job, name) self.assertEqual(getattr(actUser, model.user.FIELD_USERNAME), name) self.assertRaises(Exception, user.select_entity, job, ["xyzxyz"]) def test_13writeEntity(self): global mymsg global jobObject actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() username = "hans_xyz" user = model.user.User(job) entityNames = user.get_unique_names(job, storage=model.entity.STORAGE_FILE) self.assertNotIn(username, entityNames) user.username = username user.name = "Hans" user.famname = "im Glueck" user.project = "TESTPROJ" user.write_entity(job, username) entityNames = user.get_unique_names(job, storage=model.entity.STORAGE_FILE) self.assertIn(username, entityNames) actUser = user.read_entity(job, username) self.assertEqual(getattr(actUser, model.user.FIELD_USERNAME), username) actUser.remove_entity(job, username) entityNames = user.get_unique_names(job, storage=model.entity.STORAGE_FILE) self.assertNotIn(username, entityNames) def test_14insertEntity(self): global mymsg global jobObject actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() username = "hans_xyz" user = model.user.User(job) entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB)) #self.assertNotIn(username, entityNames) user.username = username user.name = "Hans" user.famname = "im Glueck" user.project = "TESTPROJ" user.insert_entity(job, username, table="user") entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB)) self.assertIn(username, entityNames) actUser = user.select_entity(job, username) self.assertEqual(getattr(actUser, model.user.FIELD_USERNAME), username) actUser.delete_entity(job, username, "user") entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB)) self.assertNotIn(username, entityNames) def collectInnerList(inList): outList = [] for r in inList: outList += r return outList if __name__ == '__main__': unittest.main()