def testCreateObjects(self): from test_model import createDevice #self.conf['debugSql'] = True dao = Dao(self.conf) session = dao.Session() device = createDevice(session, "test") ifd1 = InterfaceDefinition('ifd1', device, 'downlink') ifd2 = InterfaceDefinition('ifd2', device, 'downlink') ifd3 = InterfaceDefinition('ifd1', device, 'downlink') ifd4 = InterfaceDefinition('ifd2', device, 'downlink') dao.createObjects([ifd1, ifd2, ifd3, ifd4]) self.assertEqual(4, len(dao.getAll(InterfaceDefinition))) self.assertEqual(2, len(dao.getObjectsByName(InterfaceDefinition, 'ifd1'))) self.assertEqual(2, len(dao.getObjectsByName(InterfaceDefinition, 'ifd2')))
def testCascadeDeletePodDevice(self): from test_model import createDevice #self.conf['debugSql'] = True dao = Dao(self.conf) session = dao.Session() device = createDevice(session, "test") self.assertEqual(1, len(dao.getAll(Pod))) self.assertEqual(1, len(dao.getAll(Device))) dao.deleteObject(device.pod) self.assertEqual(0, len(dao.getAll(Pod))) self.assertEqual(0, len(dao.getAll(Device)))
def testCascadeDeletePodDeviceInterface(self): from test_model import createInterface #self.conf['debugSql'] = True dao = Dao(self.conf) session = dao.Session() interface = createInterface(session, "test") self.assertEqual(1, len(dao.getAll(Pod))) self.assertEqual(1, len(dao.getAll(Device))) self.assertEqual(1, len(dao.getAll(Interface))) dao.deleteObject(interface.device.pod) self.assertEqual(0, len(dao.getAll(Pod))) self.assertEqual(0, len(dao.getAll(Device))) self.assertEqual(0, len(dao.getAll(Interface)))
def testCreateObjects(self): from test_model import createDevice #self.conf['debugSql'] = True dao = Dao(self.conf) session = dao.Session() device = createDevice(session, "test") ifd1 = InterfaceDefinition('ifd1', device, 'downlink') ifd2 = InterfaceDefinition('ifd2', device, 'downlink') ifd3 = InterfaceDefinition('ifd1', device, 'downlink') ifd4 = InterfaceDefinition('ifd2', device, 'downlink') dao.createObjects([ifd1, ifd2, ifd3, ifd4]) self.assertEqual(4, len(dao.getAll(InterfaceDefinition))) self.assertEqual( 2, len(dao.getObjectsByName(InterfaceDefinition, 'ifd1'))) self.assertEqual( 2, len(dao.getObjectsByName(InterfaceDefinition, 'ifd2')))
def setUp(self): self.conf = {} self.conf['outputDir'] = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'out') self.conf['dbUrl'] = 'sqlite:///' self.conf['DOT'] = {'ranksep' : '5 equally', 'colors': ['red', 'green', 'blue']} self.conf['deviceFamily'] = { "QFX5100-24Q": { "ports": 'et-0/0/[0-23]' }, "QFX5100-48S": { "uplinkPorts": 'et-0/0/[48-53]', "downlinkPorts": 'xe-0/0/[0-47]' } } self.dao = Dao(self.conf) ''' Deletes 'out' folder under test dir''' shutil.rmtree(self.conf['outputDir'], ignore_errors=True)
def testDeleteNonExistingPod(self): dao = Dao(self.conf) dict = {} pod = Pod('unknown', **dict) with self.assertRaises(exc.InvalidRequestError): dao.deleteObject(pod)
def testInvalidConfig(self): with self.assertRaises(ValueError): dao = Dao({})
def testGetObjectById(self): from test_model import createPod #self.conf['debugSql'] = True dao = Dao(self.conf) session = dao.Session() pod = createPod("test", session)