|
|
@ -0,0 +1,112 @@ |
|
|
|
#!/usr/bin/python |
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
# --------------------------------------------------------------------------------------------------------- |
|
|
|
# Author : Ulrich Carmesin |
|
|
|
# Source : gitea.ucarmesin.de |
|
|
|
# --------------------------------------------------------------------------------------------------------- |
|
|
|
import unittest |
|
|
|
import inspect |
|
|
|
import test.testtools |
|
|
|
import basic.constants as B |
|
|
|
import test.constants as T |
|
|
|
import model.table |
|
|
|
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_20getSchema"] |
|
|
|
TEST_FUNCTIONS = ["test_20getSchema"] |
|
|
|
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() |
|
|
|
table = model.table.Table(job, "TESTPROJ") |
|
|
|
entityNames = table.read_unique_names(job, "", "", "", {}) |
|
|
|
self.assertEqual(type(entityNames), list) |
|
|
|
|
|
|
|
entityNames = table.read_unique_names(job, B.ATTR_INST_TESTSERVER, "", "", {}) |
|
|
|
self.assertEqual(type(entityNames), list) |
|
|
|
#entityNames = project.select_unique_names(job, "", "", "", {}) |
|
|
|
#self.assertEquals(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() |
|
|
|
table = model.table.Table(job, "TESTPROJ") |
|
|
|
entityNames = [] |
|
|
|
entityNames = table.get_entities(job, storage=model.entity.STORAGE_FILE) |
|
|
|
self.assertEqual(type(entityNames), list) |
|
|
|
#entityNames = table.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() |
|
|
|
table = model.table.Table(job, "TESTPROJ") |
|
|
|
name = "adress" |
|
|
|
acttable = table.read_entity(job, name) |
|
|
|
self.assertEqual(getattr(acttable, model.table.FIELD_NAME), name) |
|
|
|
self.assertRaises(Exception, table.read_entity, job, "xyzxyz") |
|
|
|
# |
|
|
|
table = model.table.Table(job, B.ATTR_INST_TESTSERVER) |
|
|
|
name = B.SUBJECT_APP |
|
|
|
acttable = table.read_entity(job, name, project=B.ATTR_INST_TESTSERVER) |
|
|
|
self.assertEqual(getattr(acttable, model.table.FIELD_NAME), name) |
|
|
|
self.assertRaises(Exception, table.read_entity, job, "xyzxyz") |
|
|
|
# |
|
|
|
table = model.table.Table(job, B.ATTR_INST_TESTSERVER) |
|
|
|
name = "ap_application" |
|
|
|
acttable = table.read_entity(job, name, project=B.ATTR_INST_TESTSERVER) |
|
|
|
self.assertEqual(getattr(acttable, model.table.FIELD_NAME), name) |
|
|
|
self.assertRaises(Exception, table.read_entity, job, "xyzxyz") |
|
|
|
|
|
|
|
def test_20getSchema(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() |
|
|
|
table = model.table.Table(job, B.ATTR_INST_TESTSERVER) |
|
|
|
entityNames = table.read_unique_names(job, B.ATTR_INST_TESTSERVER, "", "", {}) |
|
|
|
name = "tc_table" |
|
|
|
print(name) |
|
|
|
acttable = table.read_entity(job, name, project=B.ATTR_INST_TESTSERVER) |
|
|
|
schema = acttable.get_schema(name) |
|
|
|
print(schema) |
|
|
|
self.assertEqual("CREATE TABLE", schema[:12]) |
|
|
|
self.assertIn(name, schema) |
|
|
|
for name in entityNames: |
|
|
|
print(name) |
|
|
|
acttable = table.read_entity(job, name, project=B.ATTR_INST_TESTSERVER) |
|
|
|
schema = acttable.get_schema(name) |
|
|
|
print(schema) |
|
|
|
self.assertEqual("CREATE TABLE", schema[:12]) |
|
|
|
self.assertIn("PRIMARY KEY", schema) |
|
|
|
self.assertIn(name, schema) |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
unittest.main() |