def test_db_mapping_branch(self): from emc.kb.mapping_db import Branch from emc.kb.mapping_db import Model from z3c.saconfig import Session import pdb pdb.set_trace() model = Model() model.xhdm = u"C9" model.xhmc = u"我的手机" Session.add(model) branch = Branch() branch.fxtdm = u"C91" branch.fxtmc = u"发射器" branch.fxtlb = u"fashe" branch.model = model Session.add(branch) Session.flush() self.assertTrue(branch.branchId is not None) self.assertTrue(model.modelId is not None) self.assertEqual(branch.modelId, model.modelId) self.assertEqual(branch.branchId, model.branches[0].branchId)
def test_db_mapping_model(self): from emc.kb.mapping_db import Model from z3c.saconfig import Session model = Model() model.xhdm = u"C9" model.xhmc = u"我的手机" Session.add(model) Session.flush() self.assertTrue(model.modelId is not None)
def test_db_mapping_model(self): from emc.kb.mapping_db import Model from z3c.saconfig import Session model = Model() model.xhdm = u"C9" model.xhmc = u"我的手机" Session.add(model) Session.flush() nums = Session.query(func.count(model.modelId)).scalar() self.assertTrue(model.modelId is not None) print model.xhdm print nums
def Addmodel(self,modelId,xhdm,xhmc): """parameters db model table""" model = Model() model.id = modelId model.xhdm = xhdm model.xhmc = xhmc kb_session.add(model) try: kb_session.commit() except: kb_session.rollback() raise
def test_oracledb_model(self): from emc.kb.mapping_db import Model from emc.kb import pas_session as Session model = Model() import pdb pdb.set_trace() nums = Session.query(func.count(model.modelId)).scalar() if nums != 1: model.modelId = 100 model.xhdm = u"C9" model.xhmc = u"my phone" Session.add(model) Session.commit() self.assertTrue(model.modelId is not None) self.assertTrue(nums is not None)
def addModel(self, **kwargs): """parameters db model table""" model = Model() # model.modelId = kwargs['modelId'] model.xhdm = kwargs['xhdm'] model.xhmc = kwargs['xhmc'] # # registry db sources # # saconnect = ISQLAlchemyConnectionStrings(getSite()) # # Register z3c.saconfig utilities for mysql parameters db # dbURI = saconnect['mysql'] # # Register z3c.saconfig utilities for pas.plugins.sqlarchemy # engine = EngineFactory(dbURI, echo=False, convert_unicode=False) # provideUtility(engine, name=u"mysql.parameters") # session = GloballyScopedSession(engine=u"mysql.parameters", twophase=False) # provideUtility(session,name=u"mysql.parameters") kb_session.add(model) try: kb_session.commit() except: kb_session.rollback() pass