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 test_model_locator(self): from emc.kb.mapping_db import Model from emc.kb.interfaces import IModelLocator from zope.component import getUtility from emc.kb import kb_session as Session locator = getUtility(IModelLocator) #getModel xhdm = u'C7' xhmc = u"他的手机" model = locator.getModelByCode(xhdm) #addModel import pdb pdb.set_trace() if model == None: locator.addModel(xhdm=xhdm, xhmc=xhmc) else: # remove old delete locator.DeleteByCode(xhdm) locator.addModel(xhdm=xhdm, xhmc=xhmc) # locator.addModel(model) Session.flush() portal = self.layer['portal'] setRoles(portal, TEST_USER_ID, ('Manager', )) # portal.manage_permission('search_db', ['Member', 'Manager'], acquire=False) portal.invokeFactory('emc.kb.folder', 'folder', title=u"folder") portal['folder'].invokeFactory( 'emc.kb.ormfolder', 'ormfolder', title=u"ormfolder", description=u"ormfolder", ) # paras = {'xhdm':u"C6"} model = locator.getModelByCode(xhdm) self.assertEqual(model.xhdm, xhdm) # query pagenation 分页查询 models = locator.queryModel(start=0, size=1) import pdb pdb.set_trace() self.assertEqual(len(models), 1)