import unittest import os import inspect import tools.path_tool import basic.program import test.testtools import basic.constants as B import test.constants as T import model.component import model.entity import tools.data_const as D 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", "test_12getEntity"] 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() component = model.component.Component(job) entityNames = [] entityNames = component.read_unique_names(job, "", "", "", {}) self.assertEqual(type(entityNames), list) #entityNames = component.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() component = model.component.component() entityNames = [] entityNames = component.get_entities(job, storage=model.entity.STORAGE_FILE) self.assertEqual(type(entityNames), list) entityNames = component.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() component = model.component.Component(job) name = "testprd" actproject = component.read_entity(job, name) self.assertEqual(getattr(actproject, D.FIELD_NAME), name) self.assertRaises(Exception, component.read_entity, job, "xyzxyz") # #actproject = component.select_entity(job, name) #self.assertEqual(getattr(actproject, model.component.FIELD_USERNAME), name) #self.assertRaises(Exception, component.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" component = model.component.component() entityNames = component.get_unique_names(job, storage=model.entity.STORAGE_FILE) self.assertNotIn(username, entityNames) component.username = username component.name = "Hans" component.famname = "im Glueck" component.component = "TESTPROJ" component.write_entity(job, username) entityNames = component.get_unique_names(job, storage=model.entity.STORAGE_FILE) self.assertIn(username, entityNames) actUser = component.read_entity(job, username) self.assertEqual(getattr(actUser, model.component.FIELD_USERNAME), username) actUser.remove_entity(job, username) entityNames = component.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" component = model.component.component() entityNames = collectInnerList(component.get_unique_names(job, storage=model.entity.STORAGE_DB)) #self.assertNotIn(username, entityNames) component.username = username component.name = "Hans" component.famname = "im Glueck" component.component = "TESTPROJ" #component.insert_entity(job, username, table="component") entityNames = collectInnerList(component.get_unique_names(job, storage=model.entity.STORAGE_DB)) self.assertIn(username, entityNames) actUser = component.select_entity(job, username) self.assertEqual(getattr(actUser, model.component.FIELD_USERNAME), username) actUser.delete_entity(job, username, "component") entityNames = collectInnerList(component.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()