Пример #1
0
 def test_sync_updates_nothing_with_no_team_change(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_kc.json"), "rt") as fp:
         rstdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_pit.json"), "rt") as fp:
         rstdata.extend(json.load(fp))
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_pit.json"), "rt") as fp:
         srcdata.extend(json.load(fp))
     rmgr = self._getMockPlayerGamelogManager(rosterData=rstdata,
                                              gamelogData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     rmgr = self._getMockPlayerGamelogManager(rosterData=rstdata,
                                              gamelogData=srcdata,
                                              dataExpired=False)
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), 0, "sync returned record count differs")
     self.assertEqual(rmgr._apiClient.getRequestedRosters(), [],
                      "requested rosters differs")
Пример #2
0
 def test_save_appends(self):
     recs = util.runCoroutine(self.datamgr.sync())
     arec = util.runCoroutine(self.datamgr.save([{"team": "NX"}]))
     recs.extend(arec)
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(len(dbrecs), len(recs), "record count differs")
     self.assertEqual(dbrecs, recs, "db records differ")
Пример #3
0
 def test_sync_initializes_collection_two_teams(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_kc.json"), "rt") as fp:
         rstdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_pit.json"), "rt") as fp:
         rstdata.extend(json.load(fp))
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_pit.json"), "rt") as fp:
         srcdata.extend(json.load(fp))
     rmgr = self._getMockPlayerGamelogManager(rosterData=rstdata,
                                              gamelogData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), len(srcdata),
                      "sync returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self._compareGL(dbrecs, recs)
     self.assertEqual(rmgr._apiClient.getRequestedRosters(), rstdata,
                      "requested rosters differs")
 def test_sync_new_finished_adds(self):
     schdata1 = self._getScheduleData()
     schdata2 = schdata1.copy()
     reqsch2 = []
     for r in schdata2:
         if not r["finished"]:
             r["finished"] = True
             reqsch2.append(r)
     gsdata1 = self._getGameDriveData([13])
     gsdata2 = self._getGameDriveData([14])
     gsmgr = self._getMockGameDriveManager(schdata1, gsdata1)
     recs1 = util.runCoroutine(gsmgr.sync())
     self.assertEqual(len(recs1), len(gsdata1),
                      "first returned record counts differ")
     gsmgr = self._getMockGameDriveManager(schdata2, gsdata2)
     recs2 = util.runCoroutine(gsmgr.sync())
     self.assertEqual(len(recs2), len(gsdata2),
                      "second returned record counts differ")
     dbrecs = util.runCoroutine(gsmgr.find())
     recs = recs1 + recs2
     for r in recs:
         del r["_id"]
     self.assertEqual(len(dbrecs), len(recs), "db record counts differ")
     self.assertEqual(dbrecs, recs, "db records differ")
     apireqs = gsmgr._apiClient.getRequestedSchedules()
     self.assertEqual(len(apireqs), len(reqsch2),
                      "api request record counts differ")
     self.assertEqual(apireqs, reqsch2, "api request records differ")
Пример #5
0
 def test_player_gamelog(self):
     pmgr = PlayerGamelogManagerFacade(self.entmgr)
     recs = util.runCoroutine(pmgr.sync())
     dbrecs = util.runCoroutine(pmgr.find())
     self.assertEqual(len(dbrecs), len(recs), "db records lengths differ")
     self.assertGreater(len([r for r in dbrecs if "previous_teams" in r]),
                        0, "previous_teams not set")
Пример #6
0
 def test_sync_req_unfinished_only_after_initialized_in_regseason(self):
     srcdata = []
     updata = []
     tddpath = os.path.join(os.path.dirname(__file__), "data")
     for fname in [
             "schedule_2017.json", "schedule_2018.json",
             "schedule_2019.json"
     ]:
         with open(os.path.join(tddpath, fname), "rt") as fp:
             data = json.load(fp)
             srcdata.extend(data)
             if fname == "schedule_2019.json":
                 updata = [rec for rec in data if not rec["finished"]]
     xreq = []
     for week in range(14, 18):
         xreq.append({
             "season": 2019,
             "season_type": "regular_season",
             "week": week
         })
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     recs1 = util.runCoroutine(smgr.sync())
     self.assertEqual(len(recs1), len(srcdata),
                      "sync1 returned record count differs")
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     recs2 = util.runCoroutine(smgr.sync())
     self.assertEqual(len(recs2), len(updata),
                      "sync2 returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs1, "db records differ")
     apireq = smgr._apiClient.getRequestedData()
     self.assertEqual(len(apireq), len(xreq), "api request lengths differ")
     self.assertEqual(apireq, xreq, "api requests differ")
Пример #7
0
 def test_sync_only_inserts_new(self):
     recs = util.runCoroutine(self.datamgr.sync())
     self.assertGreater(len(recs), 0, "sync returned 0 records")
     recs2 = util.runCoroutine(self.datamgr.sync())
     self.assertEqual(len(recs2), 0, "sync returned 0 records")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs, "db records differ")
Пример #8
0
 def test_game_play(self):
     mgr = GamePlayManagerFacade(self.entmgr)
     recs = util.runCoroutine(mgr.sync())
     writeData(mgr._getAmbiguousPlayerAbbrevs(),
               "game_play_ambig_plabb.json")
     writeData(mgr._getMissingPlayerAbbrevs(), "game_play_miss_plabb.json")
     dbrecs = util.runCoroutine(mgr.find())
     self.assertEqual(len(dbrecs), len(recs), "db records lengths differ")
Пример #9
0
 def test_roster(self):
     rmgr = RosterManagerFacade(self.entmgr)
     recs = util.runCoroutine(rmgr.sync())
     dbrecs = util.runCoroutine(rmgr.find())
     self.assertLessEqual(len(dbrecs), len(recs),
                          "db records lengths differ")
     self.assertGreater(len([r for r in dbrecs if "previous_teams" in r]),
                        0, "previous_teams not set")
Пример #10
0
 def test_sync_initializes_collection_one_team(self):
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     rmgr = self._getMockRosterManager(teamData=[{"team": "KC"}], rosterData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), len(srcdata), "sync returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs, "db records differ")
     self.assertEqual(rmgr._apiClient.getRequestedTeams(), set(["KC"]), "requested teams differs")
Пример #11
0
 def test_sync_no_new_finished_noop(self):
     schdata = self._getScheduleData()
     gsdata = self._getGameDriveData([13])
     gsmgr = self._getMockGameDriveManager(schdata, gsdata)
     recs1 = util.runCoroutine(gsmgr.sync())
     self.assertEqual(len(recs1), len(gsdata),
                      "first returned record counts differ")
     recs2 = util.runCoroutine(gsmgr.sync())
     self.assertEqual(len(recs2), 0, "second returned record counts differ")
     dbrecs = util.runCoroutine(gsmgr.find())
     self.assertEqual(len(dbrecs), len(recs1), "db record counts differ")
Пример #12
0
 def test_find_by_teams(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "schedule_2017.json"), "rt") as fp:
         srcdata = json.load(fp)
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     util.runCoroutine(smgr.sync())
     recs = util.runCoroutine(smgr.find(teams=["ATL"]))
     self.assertEqual(len(recs), 22, "ATL record count differs")
     recs = util.runCoroutine(smgr.find(teams=["ATL", "NE"]))
     self.assertEqual(len(recs), 44, "ATL, NE record count differs")
Пример #13
0
 def test_find_constraint(self):
     recs = util.runCoroutine(
         self.entmgr.save(self.entityName, [{
             "team": "KC"
         }, {
             "team": "PIT"
         }]))
     for rec in recs:
         del rec["_id"]
     dbrecs = util.runCoroutine(self.datamgr.find(teams=["KC"]))
     self.assertEqual(dbrecs, [recs[0]], "db records differ")
Пример #14
0
 def test_find_by_finished(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "schedule_2019.json"), "rt") as fp:
         srcdata = json.load(fp)
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     util.runCoroutine(smgr.sync())
     recs = util.runCoroutine(smgr.find(finished=True))
     self.assertEqual(len(recs), 32, "True record count differs")
     recs = util.runCoroutine(smgr.find(finished=False))
     self.assertEqual(len(recs), 8, "False record count differs")
Пример #15
0
 def test_delete_profile_id(self):
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     rmgr = self._getRosterManager()
     recs = util.runCoroutine(rmgr.save(srcdata))
     self.assertEqual(len(recs), len(srcdata), "save returned record count differs")
     dcount = util.runCoroutine(rmgr.delete(profile_ids=[2562399]))
     self.assertEqual(dcount, 1, "delete returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(len(dbrecs), len(srcdata) - 1, "db record count differs")
     xdata = [_ for _ in srcdata if _["profile_id"] != 2562399]
     self.assertEqual(dbrecs, xdata, "db records differ")
Пример #16
0
 def test_find_by_season_type(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "schedule_2017.json"), "rt") as fp:
         srcdata = json.load(fp)
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     util.runCoroutine(smgr.sync())
     recs = util.runCoroutine(smgr.find(season_types=["regular_season"]))
     self.assertEqual(len(recs), 31, "regular_season record count differs")
     recs = util.runCoroutine(
         smgr.find(season_types=["regular_season", "postseason"]))
     self.assertEqual(len(recs), 36,
                      "regular_season, postseason record count differs")
Пример #17
0
 def test_save_appends(self):
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         kcdata = json.load(fp)
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_pit.json"), "rt") as fp:
         pitdata = json.load(fp)
     rmgr = self._getMockRosterManager(teamData=[{"team": "KC"}], rosterData=kcdata.copy())
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), len(kcdata), "sync record count differs")
     recs.extend(util.runCoroutine(rmgr.save(pitdata.copy())))
     self.assertEqual(len(recs), len(kcdata) + len(pitdata), "save record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(len(dbrecs), len(recs), "db record count differs")
     self.assertEqual(dbrecs, recs, "db records differ")
Пример #18
0
 def test_save_adds_teams(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "schedule_2017.json"), "rt") as fp:
         srcdata = json.load(fp)
     d = srcdata[0]
     smgr = ScheduleManagerFacade(self.entmgr)
     recs = util.runCoroutine(smgr.save([d]))
     self.assertEqual(len(recs), 1, "returned record count differs")
     self.assertTrue("teams" in recs[0], "teams not added")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs, "db records differ")
     self.assertEqual(dbrecs[0]["teams"], ["MIA", "ATL"],
                      "teams value differs")
Пример #19
0
 def test_find_by_season(self):
     srcdata = []
     tddpath = os.path.join(os.path.dirname(__file__), "data")
     for fname in [
             "schedule_2017.json", "schedule_2018.json",
             "schedule_2019.json"
     ]:
         with open(os.path.join(tddpath, fname), "rt") as fp:
             srcdata.extend(json.load(fp))
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     util.runCoroutine(smgr.sync())
     recs = util.runCoroutine(smgr.find(seasons=[2017]))
     self.assertEqual(len(recs), 44, "2017 record count differs")
     recs = util.runCoroutine(smgr.find(seasons=[2017, 2019]))
     self.assertEqual(len(recs), 84, "2017, 2019 record count differs")
Пример #20
0
 def test_sync_only_updates_records_with_team_change(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_kc.json"), "rt") as fp:
         rstdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_pit.json"), "rt") as fp:
         rstdata.extend(json.load(fp))
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_pit.json"), "rt") as fp:
         srcdata.extend(json.load(fp))
     rmgr = self._getMockPlayerGamelogManager(rosterData=rstdata,
                                              gamelogData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     xreqrec = []
     for rec in rstdata:
         if rec["profile_id"] == 2560950:
             rec["team"] = "KC"
             xreqrec.append(rec)
     xrec = []
     for rec in srcdata:
         if rec["profile_id"] == 2560950:
             rec["team"] = "KC"
             crec = rec.copy()
             # Since the team is changing the previous_teams attribute should be set
             crec["previous_teams"] = ["PIT"]
             xrec.append(crec)
     rmgr = self._getMockPlayerGamelogManager(rosterData=rstdata,
                                              gamelogData=srcdata,
                                              dataExpired=False)
     recs = util.runCoroutine(rmgr.sync())
     reqrec = rmgr._apiClient.getRequestedRosters()
     self.assertEqual(len(reqrec), len(xreqrec),
                      "requested roster lengths differs")
     self.assertEqual(reqrec, xreqrec, "requested rosters differs")
     self.assertEqual(len(recs), 24, "sync returned record count differs")
     dbrecs = util.runCoroutine(
         self.entmgr.find(self.entityName,
                          query={"profile_id": 2560950},
                          projection={"_id": False}))
     self.assertEqual(len(dbrecs), 24, "db record counts differ")
     self._compareGL(dbrecs, xrec)
Пример #21
0
 def test_sync_initializes_collection(self):
     schdata = self._getScheduleData()
     gsdata = self._getGameDriveData()
     gsmgr = self._getMockGameDriveManager(schdata, gsdata)
     recs = util.runCoroutine(gsmgr.sync())
     self.assertEqual(len(recs), len(gsdata),
                      "returned record counts differ")
     dbrecs = util.runCoroutine(gsmgr.find())
     for r in recs:
         del r["_id"]
     self.assertEqual(len(dbrecs), len(recs), "db record counts differ")
     self.assertEqual(dbrecs, recs, "db records differ")
     apireqs = gsmgr._apiClient.getRequestedSchedules()
     self.assertEqual(len(apireqs), len(schdata),
                      "api request record counts differ")
     self.assertEqual(apireqs, schdata, "api request records differ")
Пример #22
0
 def test_sync_initializes_collection_with_historic_data_with_previous_team(self):
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         histdata = json.load(fp)
         for rec in histdata:
             rec["team"] = "PIT"
     rmgr = self._getMockRosterManager(teamData=[{"team": "KC"}], rosterData=srcdata, historicData=histdata)
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), len(srcdata) + len(histdata), "sync returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(len(dbrecs), len(srcdata), "db record count differs")
     for rec in dbrecs:
         self.assertTrue("previous_teams" in rec, "previous_teams not added to {}".format(rec["profile_id"]))
         self.assertEqual(rec["previous_teams"], ["PIT"], "previous_teams value not equal for {}".format(rec["profile_id"]))
     self.assertEqual(rmgr._apiClient.getRequestedTeams(), set(["KC"]), "requested teams differs")
Пример #23
0
 def test_sync_req_postseason_only_after_initialized_after_regseason(self):
     srcdata = []
     psdata = []
     tddpath = os.path.join(os.path.dirname(__file__), "data")
     for fname in [
             "schedule_2017.json", "schedule_2018.json",
             "schedule_2019.json"
     ]:
         with open(os.path.join(tddpath, fname), "rt") as fp:
             data = json.load(fp)
             srcdata.extend(data)
             if fname == "schedule_2018.json":
                 # use the 2018 postseason data as the 2019 postseason data
                 for d in [
                         r for r in data if r["season_type"] == "postseason"
                 ]:
                     ud = d.copy()
                     ud["finished"] = False
                     ud["season"] = 2019
                     ud["gsis_id"] = ud["gsis_id"].replace(
                         "2019", "2020", 1)
                     psdata.append(ud)
     for rec in srcdata:
         if not rec["finished"]:
             rec["finished"] = True
     xreq = []
     for week in range(1, 5):
         xreq.append({
             "season": 2019,
             "season_type": "postseason",
             "week": week
         })
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     recs1 = util.runCoroutine(smgr.sync())
     self.assertEqual(len(recs1), len(srcdata),
                      "sync1 returned record count differs")
     smgr = self._getMockScheduleManager(scheduleData=psdata)
     recs2 = util.runCoroutine(smgr.sync())
     self.assertEqual(len(recs2), len(psdata),
                      "sync2 returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     xdbrecs = recs1 + recs2
     self.assertEqual(len(dbrecs), len(xdbrecs), "db record lengths differ")
     self.assertEqual(dbrecs, xdbrecs, "db records differ")
     apireq = smgr._apiClient.getRequestedData()
     self.assertEqual(len(apireq), len(xreq), "api request lengths differ")
     self.assertEqual(apireq, xreq, "api requests differ")
Пример #24
0
 def test_delete_team(self):
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         kcdata = json.load(fp)
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_pit.json"), "rt") as fp:
         pitdata = json.load(fp)
     srcdata = kcdata.copy()
     srcdata.extend(pitdata.copy())
     rmgr = self._getRosterManager()
     recs = util.runCoroutine(rmgr.save(srcdata))
     self.assertEqual(len(recs), len(srcdata), "save returned record count differs")
     dcount = util.runCoroutine(rmgr.delete(teams=["PIT"]))
     self.assertEqual(dcount, len(pitdata), "delete returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(len(dbrecs), len(kcdata), "db record count differs")
     for rec in dbrecs:
         del rec["_id"]
     self.assertEqual(dbrecs, kcdata, "db records differ")
Пример #25
0
 def test_delete_profile_id(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_gamelog_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     xdelrecs = [_ for _ in srcdata if _["profile_id"] == 2562399]
     xdata = [_ for _ in srcdata if _["profile_id"] != 2562399]
     rmgr = self._getPlayerGamelogManager()
     recs = util.runCoroutine(rmgr.save(srcdata))
     self.assertEqual(len(recs), len(srcdata),
                      "save returned record count differs")
     dcount = util.runCoroutine(rmgr.delete(profile_ids=[2562399]))
     self.assertEqual(dcount, len(xdelrecs),
                      "delete returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     for rec in dbrecs:
         del rec["_id"]
     self._compareGL(dbrecs, xdata)
Пример #26
0
 def test_sync_initializes_collection(self):
     srcdata = []
     tddpath = os.path.join(os.path.dirname(__file__), "data")
     for fname in [
             "schedule_2017.json", "schedule_2018.json",
             "schedule_2019.json"
     ]:
         with open(os.path.join(tddpath, fname), "rt") as fp:
             srcdata.extend(json.load(fp))
     xreq = [{"season": 2017}, {"season": 2018}, {"season": 2019}]
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     recs = util.runCoroutine(smgr.sync())
     self.assertEqual(len(recs), len(srcdata),
                      "sync returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs, "db records differ")
     self.assertEqual(smgr._apiClient.getRequestedData(), xreq,
                      "api requests differ")
 def test_sync_initializes_collection_one_team(self):
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "roster_kc.json"), "rt") as fp:
         rstdata = json.load(fp)
     with open(
             os.path.join(os.path.dirname(__file__), "data",
                          "player_profile_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     rmgr = self._getMockPlayerProfileManager(rosterData=rstdata,
                                              profileData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), len(srcdata),
                      "sync returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs, "db records differ")
     self.assertEqual(rmgr._apiClient.getRequestedRosters(), rstdata,
                      "requested rosters differs")
Пример #28
0
 def test_find_by_next(self):
     srcdata = []
     tddpath = os.path.join(os.path.dirname(__file__), "data")
     for fname in [
             "schedule_2017.json", "schedule_2018.json",
             "schedule_2019.json"
     ]:
         with open(os.path.join(tddpath, fname), "rt") as fp:
             srcdata.extend(json.load(fp))
     smgr = self._getMockScheduleManager(scheduleData=srcdata)
     util.runCoroutine(smgr.sync())
     recs = util.runCoroutine(smgr.find(next=True))
     self.assertEqual(len(recs), 2, "record count differs")
     for rec in recs:
         self.assertEqual(rec["season"], 2019,
                          "{} season differs".format(rec["gsis_id"]))
         self.assertEqual(rec["season_type"], "regular_season",
                          "{} season_type differs".format(rec["gsis_id"]))
         self.assertEqual(rec["week"], 14,
                          "{} week differs".format(rec["gsis_id"]))
    def test_sync_updates_all_with_all(self):
        with open(
                os.path.join(os.path.dirname(__file__), "data",
                             "roster_kc.json"), "rt") as fp:
            rstdata = json.load(fp)
        with open(
                os.path.join(os.path.dirname(__file__), "data",
                             "roster_pit.json"), "rt") as fp:
            rstdata.extend(json.load(fp))
        with open(
                os.path.join(os.path.dirname(__file__), "data",
                             "player_profile_kc.json"), "rt") as fp:
            srcdata = json.load(fp)
        with open(
                os.path.join(os.path.dirname(__file__), "data",
                             "player_profile_pit.json"), "rt") as fp:
            srcdata.extend(json.load(fp))
        rmgr = self._getMockPlayerProfileManager(rosterData=rstdata,
                                                 profileData=srcdata)
        recs = util.runCoroutine(rmgr.sync())

        def pidmap(recs: List[dict]) -> dict:
            return dict(zip([_["profile_id"] for _ in recs], recs))

        rmap = pidmap(rstdata.copy())
        pmap = pidmap(srcdata.copy())
        usrcdata = []
        for pid in rmap:
            t = random.choice(["KC", "PIT"])
            rmap[pid]["team"] = t
            pmap[pid]["team"] = t
            usrcdata.append(pmap[pid])
        rmgr = self._getMockPlayerProfileManager(rosterData=list(
            rmap.values()),
                                                 profileData=usrcdata)
        recs = util.runCoroutine(rmgr.sync(all=True))
        self.assertEqual(len(recs), len(usrcdata),
                         "sync returned record count differs")
        dbrecs = util.runCoroutine(
            self.entmgr.find(self.entityName, projection={"_id": False}))
        self.assertEqual(dbrecs, usrcdata, "db records differ")
Пример #30
0
 def test_sync_stores_previous_team(self):
     teamData = [{"team": "KC"}, {"team": "PIT"}]
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_kc.json"), "rt") as fp:
         srcdata = json.load(fp)
     with open(os.path.join(os.path.dirname(__file__), "data", "roster_pit.json"), "rt") as fp:
         srcdata.extend(json.load(fp))
     rmgr = self._getMockRosterManager(teamData=teamData, rosterData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     for rec in srcdata:
         if rec["profile_id"] == 2560950:
             rec["team"] = "KC"
     rmgr = self._getMockRosterManager(teamData=teamData, rosterData=srcdata)
     recs = util.runCoroutine(rmgr.sync())
     self.assertEqual(len(recs), len(srcdata), "sync returned record count differs")
     dbrecs = util.runCoroutine(self.entmgr.find(self.entityName))
     self.assertEqual(dbrecs, recs, "db records differ")
     self.assertEqual(rmgr._apiClient.getRequestedTeams(), set(["KC", "PIT"]), "requested teams differs")
     xurecs = [_ for _ in dbrecs if _["profile_id"] == 2560950]
     self.assertEqual(len(xurecs), 1, "updated record count differs")
     self.assertTrue("previous_teams" in xurecs[0], "previous_teams attribute missing")
     self.assertEqual(xurecs[0]["previous_teams"], ["PIT"], "previous_teams value differs")