示例#1
0
def store_local_data():
    sn_json = api.Session(auth.username,
                          auth.key,
                          season=2017,
                          data_format="json")
    sn_xml = api.Session(auth.username,
                         auth.key,
                         season=2017,
                         data_format="xml")

    os.chdir("C:/Users/stacy/OneDrive/Projects/FIRST_API/fapy/data")

    season_json = api.get_season(sn_json)
    with open("season_json.pickle", "wb") as f:
        pickle.dump(season_json, f, pickle.HIGHEST_PROTOCOL)

    season_xml = api.get_season(sn_xml)
    with open("season_xml.pickle", "wb") as f:
        pickle.dump(season_xml, f, pickle.HIGHEST_PROTOCOL)

    status_json = api.get_status(sn_json)
    with open("status_json.pickle", "wb") as f:
        pickle.dump(status_json, f, pickle.HIGHEST_PROTOCOL)

    status_xml = api.get_status(sn_xml)
    with open("status_xml.pickle", "wb") as f:
        pickle.dump(status_xml, f, pickle.HIGHEST_PROTOCOL)

    districts_json = api.get_districts(sn_json)
    with open("districts_json.pickle", "wb") as f:
        pickle.dump(districts_json, f, pickle.HIGHEST_PROTOCOL)

    districts_xml = api.get_districts(sn_xml)
    with open("districts_xml.pickle", "wb") as f:
        pickle.dump(districts_xml, f, pickle.HIGHEST_PROTOCOL)

    events_json = api.get_events(sn_json, district="PNW")
    with open("events_json.pickle", "wb") as f:
        pickle.dump(events_json, f, pickle.HIGHEST_PROTOCOL)

    events_xml = api.get_events(sn_xml, district="PNW")
    with open("events_jxml.pickle", "wb") as f:
        pickle.dump(events_xml, f, pickle.HIGHEST_PROTOCOL)

    teams_json = api.get_teams(sn_json, district="PNW")
    with open("teams_json.pickle", "wb") as f:
        pickle.dump(teams_json, f, pickle.HIGHEST_PROTOCOL)

    teams_xml = api.get_teams(sn_xml, district="PNW")
    with open("teams_xml.pickle", "wb") as f:
        pickle.dump(teams_xml, f, pickle.HIGHEST_PROTOCOL)
示例#2
0
 def test_build_url(self):
     sn = api.Session("username", "key", source="staging")
     args = {"eventCode": None, "teamNumber": "1318",
             "excludeDistrict": False}
     url = server.build_url(sn, "districts", args)
     assert url == ("https://frc-staging-api.firstinspires.org" +
                    "/v2.0/2017/districts" +
                    "?teamNumber=1318&excludeDistrict=false")
示例#3
0
 def test_status(self):
     sn = api.Session(auth.username, auth.key, season='2017')
     status = api.get_status(sn)
     tdata = {
         "frame_type": "status",
         "shape": (1, 3),
         "spotcheck": ("name", 0, "FIRST ROBOTICS COMPETITION API")
     }
     CheckResults.frame(status, tdata)
示例#4
0
 def test_matches(self):
     sn = api.Session(auth.username, auth.key, season='2017')
     matches = api.get_matches(sn, event="TURING")
     tdata = {
         "frame_type": "matches",
         "shape": (672, 14),
         "spotcheck": ("teamNumber", 39, 1318)
     }
     CheckResults.frame(matches, tdata)
示例#5
0
 def test_scores(self):
     sn = api.Session(auth.username, auth.key, season='2017')
     scores = api.get_scores(sn, event="TURING", level="playoff")
     tdata = {
         "frame_type": "scores",
         "shape": (32, 36),
         "spotcheck": ("autoPoints", 21, 89)
     }
     CheckResults.frame(scores, tdata)
示例#6
0
 def test_df(self):
     sn = api.Session(auth.username, auth.key, season='2017')
     schedule = api.get_schedule(sn, event="TURING", team="1318")
     tdata = {
         "frame_type": "schedule",
         "shape": (60, 8),
         "spotcheck": ("teamNumber", 3, 1318)
     }
     CheckResults.frame(schedule, tdata)
示例#7
0
    def test_creation(self):
        session = api.Session("username", "key")

        assert session.username == "username"
        assert session.key == "key"
        assert session.season == int(
            datetime.date.today().strftime("%Y"))
        assert session.data_format == "dataframe"
        assert session.source == "production"
示例#8
0
 def test_2016(self):
     sn = api.Session(auth.username, auth.key, season='2016')
     season = api.get_season(sn)
     tdata = {
         "frame_type": "season",
         "shape": (1, 8),
         "spotcheck": ("teamCount", 0, 3140)
     }
     CheckResults.frame(season, tdata)
示例#9
0
 def test_local(self):
     sn = api.Session(auth.username, auth.key, season='2017')
     sn.source = "local"
     season = api.get_season(sn)
     tdata = {
         "frame_type": "season",
         "shape": (2, 8),
         "spotcheck": ("teamCount", 0, 3372)
     }
     CheckResults.frame(season, tdata)
示例#10
0
    def test_df(self):
        sn = api.Session(auth.username, auth.key, season='2017')
        teams = api.get_teams(sn, district="PNW")
        tdata = {
            "frame_type": "teams",
            "shape": (155, 16),
            "spotcheck": ("teamNumber", 13, 1318)
        }
        CheckResults.frame(teams, tdata)

        lmod = server.httpdate_addsec(teams.attr["Last-Modified"], True)
        teams2 = api.get_teams(sn, district="PNW", mod_since=lmod)
        CheckResults.empty(teams2, lmod)
示例#11
0
    def test_page(self):
        sn = api.Session(auth.username, auth.key, season='2017')
        teams = api.get_teams(sn, district="PNW", page="2")
        tdata = {
            "frame_type": "teams",
            "shape": (65, 16),
            "spotcheck": ("nameShort", 64, "Aluminati")
        }
        CheckResults.frame(teams, tdata)

        lmod = server.httpdate_addsec(teams.attr["Last-Modified"], True)
        teams2 = api.get_teams(sn,
                               district="PNW",
                               page="2",
                               only_mod_since=lmod)
        CheckResults.empty(teams2, lmod)
示例#12
0
    def test_df(self):
        sn = api.Session(auth.username, auth.key, season='2017')
        districts = api.get_districts(sn)
        tdata = {
            "frame_type": "districts",
            "shape": (10, 3),
            "spotcheck": ("code", 0, "IN")
        }
        CheckResults.frame(districts, tdata)

        # Test no data and 304 code returned when mod_since used.
        lmod = server.httpdate_addsec(districts.attr["Last-Modified"], True)
        dist2 = api.get_districts(sn, mod_since=lmod)
        CheckResults.empty(dist2, lmod)

        # Test no data and 304 code returned when only_mod_since used.
        dist3 = api.get_districts(sn, only_mod_since=lmod)
        CheckResults.empty(dist3, lmod)
示例#13
0
    def test_hybrid(self):
        sn = api.Session(auth.username, auth.key, season='2017')
        hybrid = api.get_hybrid(sn, event="TURING")
        tdata = {
            "frame_type": "hybrid",
            "shape": (672, 16),
            "spotcheck": ("scoreBlueFinal", 670, 255)
        }
        CheckResults.frame(hybrid, tdata)

        lm = "Fri, 21 Apr 2017 13:43:00 GMT"
        hyb2 = api.get_hybrid(sn, event="TURING", only_mod_since=lm)
        tdata = {
            "frame_type": "hybrid",
            "shape": (348, 16),
            "spotcheck": ("matchNumber", 0, 55)
        }
        CheckResults.frame(hyb2, tdata, lm)
示例#14
0
    def test_df(self):
        sn = api.Session(auth.username, auth.key, season='2017')
        events = api.get_events(sn, district="PNW")
        tdata = {
            "frame_type": "events",
            "shape": (10, 15),
            "spotcheck": ("code", 0, "ORLAK")
        }
        CheckResults.frame(events, tdata)

        # Test no data and 304 code returned when mod_since used.
        lmod = server.httpdate_addsec(events.attr["Last-Modified"], True)
        events2 = api.get_events(sn, district="PNW", mod_since=lmod)
        CheckResults.empty(events2, lmod)

        # Test no data and 304 code returned when only_mod_since used.
        events3 = api.get_events(sn, district="PNW", only_mod_since=lmod)
        CheckResults.empty(events3, lmod)
示例#15
0
    def test_errors(self):
        with pytest.raises(ValueError):
            api.Session("username", "key", season=2014)

        with pytest.raises(ValueError):
            future_year = int(datetime.date.today().strftime("%Y")) + 2
            api.Session("username", "key", season=future_year)

        with pytest.raises(TypeError):
            session = api.Session("username", "key")
            session.data_format = True

        with pytest.raises(ValueError):
            session = api.Session("username", "key")
            session.data_format = "yaml"

        with pytest.raises(TypeError):
            api.Session(42, "key")

        with pytest.raises(TypeError):
            api.Session("username", True)
示例#16
0
 def test_xml(self):
     sn = api.Session(auth.username, auth.key, season='2017')
     sn.data_format = "xml"
     season = api.get_season(sn)
     tdata = {"frame_type": "season"}
     CheckResults.dict(season, tdata)
示例#17
0
 def test_season(self):
     session = api.Session("username", "key", season='2017')
     assert session.season == 2017