def setUp(self): # file handle print("\nsetting up...") el = MYSQLDataBase() self.connect(el) self.version = long(el.version()) el.close()
def test_connect_close(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object)) self.connect(el) self.assertEqual(long(el.version()), self.version) self.assertEqual(el.close(), None)
def test_mandatory_no_comp(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object)) self.connect(el) man = el.mandatory() self.assertTrue(isinstance(man, list)) avc = el.availableComponents() name = "mcs_test_component" while name in avc: name = name + '_1' # print(avc self.assertEqual(el.setMandatory(name), None) self.assertEqual(el.setMandatory(name), None) man2 = el.mandatory() # for cp in man: # self.assertTrue(cp in man2) # self.assertTrue(name in man2) self.assertEqual(len(man), len(man2)) for cp in man: self.assertTrue(cp in man2) self.assertEqual(long(el.version()), self.version) self.assertEqual(el.close(), None)
def test_available_no_dsrc(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object)) self.connect(el) avc = el.availableDataSources() self.assertTrue(isinstance(avc, list)) name = "mcs_test_datasource" while name in avc: name = name + '_1' # print(avc self.myAssertRaise(NonregisteredDBRecordError, el.dataSources, [name]) self.assertEqual(long(el.version()), self.version) self.assertEqual(el.close(), None)
def test_available_dsrc_strange(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object)) self.connect(el) avc = el.availableDataSources() self.assertTrue(isinstance(avc, list)) name = "mcs_test_datasource\\ \' \" \\\" \\\\" xml = "<?xml version='1.0'?><definition>\\ \' \" \\\" " \ + "\\\\<group type='NXentry'/></definition>" while name in avc: name = name + '_1' # print(avc self.assertEqual(el.storeDataSource(name, xml), None) self.assertEqual(el.storeDataSource(name, xml), None) self.__ds.append(name) avc2 = el.availableDataSources() # print(avc2 self.assertTrue(isinstance(avc2, list)) for cp in avc: self.assertTrue(cp in avc2) self.assertTrue(name in avc2) cpx = el.dataSources([name]) self.assertEqual(cpx[0], xml) self.assertEqual(el.deleteDataSource(name), None) self.__ds.pop() avc3 = el.availableDataSources() self.assertTrue(isinstance(avc3, list)) for cp in avc: self.assertTrue(cp in avc3) self.assertTrue(name not in avc3) self.assertEqual(long(el.version()), self.version + 2) self.assertEqual(el.close(), None)
def test_available_dsrc2_xml(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object)) self.connect(el) avc = el.availableDataSources() self.assertTrue(isinstance(avc, list)) name = "mcs_test_datasource" xml = "<?xml version='1.0'?><definition><group type='NXentry'/>" \ + "</definition>" xml2 = "<?xml version='1.0'?><definition><group type='NXentry2'/>" \ + "</definition>" while name in avc: name = name + '_1' name2 = name + '_2' while name2 in avc: name2 = name2 + '_2' # print(avc cpx = el.dataSources(avc) self.assertEqual(el.storeDataSource(name, xml), None) self.__ds.append(name) avc2 = el.availableDataSources() # print(avc2 cpx2 = el.dataSources(avc2) self.assertTrue(isinstance(avc2, list)) for i in range(len(avc)): self.assertTrue(avc[i] in avc2) j = avc2.index(avc[i]) self.assertEqual(cpx2[j], cpx[i]) self.assertTrue(name in avc2) j = avc2.index(name) self.assertEqual(cpx2[j], xml) self.assertEqual(el.storeDataSource(name2, xml2), None) self.__ds.append(name2) avc2 = el.availableDataSources() # print(avc2 cpx2 = el.dataSources(avc2) self.assertTrue(isinstance(avc2, list)) for i in range(len(avc)): self.assertTrue(avc[i] in avc2) j = avc2.index(avc[i]) self.assertEqual(cpx2[j], cpx[i]) self.assertTrue(name2 in avc2) j = avc2.index(name2) self.assertEqual(cpx2[j], xml2) cpx2b = el.dataSources([name, name2]) self.assertEqual(cpx2b[0], xml) self.assertEqual(cpx2b[1], xml2) self.assertEqual(el.deleteDataSource(name), None) self.__ds.pop(-2) self.assertEqual(el.deleteDataSource(name2), None) self.__ds.pop() avc3 = el.availableDataSources() cpx3 = el.dataSources(avc3) self.assertTrue(isinstance(avc3, list)) for i in range(len(avc)): self.assertTrue(avc[i] in avc3) j = avc3.index(avc[i]) self.assertEqual(cpx3[j], cpx[i]) self.assertTrue(name not in avc3) self.assertEqual(long(el.version()), self.version + 4) self.assertEqual(el.close(), None)
def tearDown(self): print("tearing down ...") if self.__cmps: el = MYSQLDataBase() self.connect(el) for cp in self.__cmps: el.deleteComponent(cp) el.close() if self.__ds: el = MYSQLDataBase() self.connect(el) for ds in self.__ds: el.deleteDataSource(ds) el.close()
def test_mandatory_comp2(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object)) self.connect(el) man = el.mandatory() self.assertTrue(isinstance(man, list)) avc = el.availableComponents() name = "mcs_test_component" xml = "<?xml version='1.0'?><definition><group type='NXentry'/>" \ + "</definition>" while name in avc: name = name + '_1' name2 = name + '_2' while name2 in avc: name2 = name2 + '_2' # print(avc self.assertEqual(el.storeComponent(name, xml), None) self.__cmps.append(name) # print(man self.assertEqual(el.setMandatory(name), None) man2 = el.mandatory() self.assertEqual(len(man) + 1, len(man2)) for cp in man: self.assertTrue(cp in man2) self.assertTrue(name in man2) self.assertEqual(el.storeComponent(name2, xml), None) self.__cmps.append(name2) # print(man self.assertEqual(el.setMandatory(name2), None) man2 = el.mandatory() self.assertEqual(len(man) + 2, len(man2)) for cp in man: self.assertTrue(cp in man2) self.assertTrue(name in man2) self.assertTrue(name2 in man2) self.assertEqual(el.unsetMandatory(name), None) # print(<man man2 = el.mandatory() self.assertEqual(len(man) + 1, len(man2)) for cp in man: self.assertTrue(cp in man2) self.assertTrue(name2 in man2) self.assertEqual(el.unsetMandatory(name2), None) man2 = el.mandatory() self.assertEqual(len(man), len(man2)) for cp in man: self.assertTrue(cp in man2) self.assertTrue(name not in man2) self.assertEqual(el.deleteComponent(name), None) self.__cmps.pop() self.assertEqual(el.deleteComponent(name2), None) self.__cmps.pop() man2 = el.mandatory() self.assertEqual(len(man), len(man2)) for cp in man: self.assertTrue(cp in man2) self.assertTrue(name not in man2) self.assertEqual(long(el.version()), self.version + 8) self.assertEqual(el.close(), None)
def test_init(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) el = MYSQLDataBase() self.assertTrue(isinstance(el, object))