def test_constraint_one_constraint_in(self): qmodel = QueryModel() qmodel.cstart("column1", ["hello", "world"], Operator.IN) self.assertEqual(qmodel.constraint, {"column1": { "$in": ["hello", "world"] }})
def _getQueryModel(self, **kwargs) -> QueryModel: qm = QueryModel() if "teams" in kwargs and kwargs["teams"] is not None: qm.cstart("team", kwargs["teams"], Operator.IN) if "include_previous_teams" in kwargs and kwargs[ "include_previous_teams"]: qm.cor("previous_teams", kwargs["teams"], Operator.IN) cmap = { "position": kwargs["positions"] if "positions" in kwargs else None, "last_name": kwargs["last_names"] if "last_names" in kwargs else None, "first_name": kwargs["first_names"] if "first_names" in kwargs else None, "profile_id": kwargs["profile_ids"] if "profile_ids" in kwargs else None } for name in cmap: if cmap[name] is not None: qm.cand(name, cmap[name], Operator.IN) if "player_abbreviations" in kwargs and kwargs[ "player_abbreviations"] is not None: paqm = QueryModel() for pabb in kwargs["player_abbreviations"]: if not (pabb is None or pabb == ""): curqm = QueryModel() fi, ln = util.parseNameAbbreviation(pabb) if not (fi is None and ln is None): if fi is not None: curqm.cstart("first_name", fi, Operator.REGEX, "i") curqm.cand("last_name", ln, Operator.REGEX, "i") paqm.cor(query_model=curqm) qm.cand(query_model=paqm) return qm
def test_constraint_one_constraint_regex_opt(self): qmodel = QueryModel() qmodel.cstart("column1", "hello", Operator.REGEX, "i") self.assertEqual(qmodel.constraint, {"column1": { "$regex": "hello", "$options": "i" }})
def test_constraint_one_constraint_negate_eq(self): qmodel = QueryModel() qmodel.cstart("column1", "hello", Operator.negate(Operator.EQ)) self.assertEqual(qmodel.constraint, {"column1": { "$not": { "$eq": "hello" } }})
def test_constraint_two_constraint_nor(self): qmodel = QueryModel() qmodel.cstart("column1", "hello").cnor("column2", 1) self.assertEqual( qmodel.constraint, {"$nor": [{ "column1": { "$eq": "hello" } }, { "column2": { "$eq": 1 } }]})
def _getQueryModel(self, **kwargs) -> QueryModel: qm = QueryModel() if kwargs["teams"] is not None: qm.cstart("teams", kwargs["teams"], Operator.IN) cmap = { "season": kwargs["seasons"] if "seasons" in kwargs else None, "season_type": kwargs["season_types"] if "season_types" in kwargs else None, "week": kwargs["weeks"] if "weeks" in kwargs else None, "finished": kwargs["finished"] if "finished" in kwargs else None } for name in cmap: if cmap[name] is not None: qm.cand(name, cmap[name], Operator.IN) return qm
def _getQueryModel(self, **kwargs) -> QueryModel: qm = QueryModel() if kwargs["teams"] is not None: qm.cstart("team", kwargs["teams"], Operator.IN) if "include_previous_teams" in kwargs and kwargs["include_previous_teams"]: qm.cor("previous_teams", kwargs["teams"], Operator.IN) cmap = { "last_name": kwargs["last_names"] if "last_names" in kwargs else None, "first_name": kwargs["first_names"] if "first_names" in kwargs else None, "profile_id": kwargs["profile_ids"] if "profile_ids" in kwargs else None } for name in cmap: if cmap[name] is not None: qm.cand(name, cmap[name], Operator.IN) return qm
async def sync(self) -> List[dict]: logging.info("Syncing {} data...".format(self._entity_name)) cur = await self.find() if len(cur) > 0: gsidqm = QueryModel() gsidqm.sinclude(["gsis_id"]) cgsidd = await self.find(qm=gsidqm) cgsids = list(set([r["gsis_id"] for r in cgsidd])) schqm = QueryModel() schqm.cstart("finished", True) if len(cgsids) > 0: schqm.cand("gsis_id", cgsids, Operator.NIN) sch = await self._scheduleManager.find(qm=schqm) else: sch = await self._scheduleManager.find() return await self.save(self._queryAPI(sch))
async def sync(self) -> List[dict]: logging.info("Syncing {} data...".format(self._entity_name)) pidqm = QueryModel() pidqm.cstart("profile_id", False, Operator.EXISTS) udata = await self.find(qm=pidqm) if len(udata) > 0: await self._setProfileIds(udata) udata = [d for d in udata if "profile_id" in d] if len(udata) > 0: udata = await self.save(udata) data = await super(PlayerSchedDepManagerFacade, self).sync() if len(udata) > 0: if len(data) > 0: data = udata + data else: data = udata return data
def test_constraint_three_constraint_and(self): qmodel = QueryModel() qmodel.cstart("column1", "hello").cand("column2", 1).cand("column3", 1.0) self.assertEqual( qmodel.constraint, { "$and": [{ "column1": { "$eq": "hello" } }, { "column2": { "$eq": 1 } }, { "column3": { "$eq": 1.0 } }] })
def _getQueryModel(self, **kwargs) -> QueryModel: qm = QueryModel() if "teams" in kwargs and kwargs["teams"] is not None: qm.cstart("team", kwargs["teams"], Operator.IN) return qm
def test_constraint_one_constraint_eq(self): qmodel = QueryModel() qmodel.cstart("column1", "hello") self.assertEqual(qmodel.constraint, {"column1": {"$eq": "hello"}})