Beispiel #1
0
 def test_constraint_one_constraint_in(self):
     qmodel = QueryModel()
     qmodel.cstart("column1", ["hello", "world"], Operator.IN)
     self.assertEqual(qmodel.constraint,
                      {"column1": {
                          "$in": ["hello", "world"]
                      }})
Beispiel #2
0
 def test_select_two_exclude_from_sexclude(self):
     qmodel = QueryModel()
     qmodel.sexclude(["column1", "column2"])
     self.assertEqual(qmodel.select(), {
         "_id": False,
         "column1": False,
         "column2": False
     })
Beispiel #3
0
 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"
                      }})
Beispiel #4
0
 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"
                          }
                      }})
Beispiel #5
0
 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
             }
         }]})
Beispiel #6
0
 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))
Beispiel #7
0
 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
Beispiel #8
0
 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
                 }
             }]
         })
Beispiel #9
0
 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
Beispiel #10
0
 def _getQueryModel(self, cmap: dict) -> QueryModel:
     qm = QueryModel()
     for name in cmap:
         if cmap[name] is not None:
             if isinstance(cmap[name], list):
                 qm.cand(name, cmap[name], Operator.IN)
             else:
                 qm.cand(name, cmap[name], Operator.EQ)
     return qm
 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
Beispiel #12
0
 def test_select_no_constraint_with_id_sincludeId(self):
     qmodel = QueryModel()
     qmodel.sincludeID()
     self.assertEqual(qmodel.select(), {})
Beispiel #13
0
 def test_constraint_one_constraint_eq(self):
     qmodel = QueryModel()
     qmodel.cstart("column1", "hello")
     self.assertEqual(qmodel.constraint, {"column1": {"$eq": "hello"}})
Beispiel #14
0
 def test_select_no_constraint(self):
     qmodel = QueryModel()
     self.assertEqual(qmodel.select(), {"_id": False})
Beispiel #15
0
 def test_select_one_exclude(self):
     qmodel = QueryModel()
     self.assertEqual(qmodel.select(column1=False), {
         "_id": False,
         "column1": False
     })
Beispiel #16
0
 def test_select_one_include_from_sinclude(self):
     qmodel = QueryModel()
     qmodel.sinclude(["column1"])
     self.assertEqual(qmodel.select(), {"_id": False, "column1": True})
Beispiel #17
0
 def test_select_no_constraint_with_id(self):
     qmodel = QueryModel()
     self.assertEqual(qmodel.select(withId=True), {})
Beispiel #18
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
Beispiel #19
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)
         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