def create(self, test): session = test.session() with session.begin() as t: for name, typ, ccy in zip(self.inames, self.itypes, self.iccys): t.add(Instrument(name=name, type=typ, ccy=ccy)) for name in self.gnames: t.add(Group(name=name)) for name, ccy in zip(self.inames, self.iccys): t.add(Fund(name=name, ccy=ccy)) yield t.on_result iall = yield test.session().query(Instrument).load_only('id').all() fall = yield test.session().query(Fund).load_only('id').all() with session.begin() as t: for i in iall: t.add(ObjectAnalytics(model_type=Instrument, object_id=i.id)) for i in fall: t.add(ObjectAnalytics(model_type=Fund, object_id=i.id)) yield t.on_result obj_len = self.size[1] groups = yield session.query(Group).all() objs = yield session.query(ObjectAnalytics).all() groups = self.populate('choice', obj_len, choice_from=groups) objs = self.populate('choice', obj_len, choice_from=objs) with test.session().begin() as t: for g, o in zip(groups, objs): t.add(AnalyticData(group=g, object=o)) yield t.on_result
def create(self, test, use_transaction=True): session = test.session() models = test.mapper eq = assertEqual if isinstance(test, type) else test.assertEqual c = yield models.instrument.query().count() eq(c, 0) if use_transaction: with session.begin() as t: for name, ccy in zip(self.fund_names, self.fund_ccys): t.add(models.fund(name=name, ccy=ccy)) for name, typ, ccy in zip(self.inst_names, self.inst_types, self.inst_ccys): t.add(models.instrument(name=name, type=typ, ccy=ccy)) yield t.on_result else: test.register() for name, typ, ccy in zip(self.inst_names, self.inst_types, self.inst_ccys): yield models.instrument.new(name=name, type=typ, ccy=ccy) for name, ccy in zip(self.fund_names, self.fund_ccys): yield models.fund(name=name, ccy=ccy) self.num_insts = yield models.instrument.query().count() self.num_funds = yield models.fund.query().count() eq(self.num_insts, len(self.inst_names)) eq(self.num_funds, len(self.fund_names)) yield session
def make_items(self, test, content=False, related=None): '''Bulk creation of Item for testing search engine. Return a set of words which have been included in the Items.''' session = test.session() words = set() contents = self.groups if content else self.empty with session.begin() as t: for name, content in zip(self.names, contents): if len(name) > 3: words.add(name) if content: words.update(content.split()) t.add(Item(name=name, counter=randint(0,10), content=content, related=related)) yield t.on_result test.words = words yield test.words