Esempio n. 1
0
def test_add_anime_to_database():
    mock_session = MagicMock()
    mock_session.query.return_value.filter.return_value.one_or_none.return_value = None

    expected_anime = Anime(id=1234,
                           name="The Melancholy of Haruhi Suzumiya",
                           season_id=0)

    Anime.add_anime_to_database(
        expected_anime.id,
        expected_anime.name,
        Season(id=expected_anime.season_id),
        mock_session,
    )
    args, _ = mock_session.add.call_args
    anime_added = args[0]
    assert isinstance(anime_added, Anime)
    assert anime_added.id == expected_anime.id
    assert anime_added.name == expected_anime.name
    assert anime_added.season_id == expected_anime.season_id
def get_licensed_anime(licenses_lines: Optional[Iterable[str]],
                       session: Session) -> Set[int]:
    print("Getting licensed anime from licenses file")
    licensed_anime = set()
    if licenses_lines is not None:
        for title in licenses_lines:
            anime = Anime.get_anime_from_database_by_name(
                title.strip(), session)
            if anime is None:
                print(f"{title} is not found in database")
            else:
                licensed_anime.add(anime.id)
    return licensed_anime
Esempio n. 3
0
def collect_series() -> None:
    config = configparser.ConfigParser()
    config.read("config.ini")

    # Ensure season is lowercase string and year is integer
    season_of_year = config["season info"]["season"].lower()
    year = int(config["season info"]["year"])

    series_dict = get_series(season_of_year, year)

    # text files workflow
    series = series_dict.items()
    print(len(series))

    output_series(series, "series.txt")
    output_series_titles(series_dict.values(), "series_sorted.txt")

    # database workflow
    print("adding anime to database")
    with session_scope() as session:
        season = Season.get_season_from_database(season_of_year, year, session)
        for anime_id, anime_name in series_dict.items():
            Anime.add_anime_to_database(anime_id, anime_name, season, session)
def get_anime_simulcast_region_counts(simulcast_lines: Optional[Iterable[str]],
                                      session: Session) -> Dict[int, int]:
    print("Getting region counts of each anime in simulcast file")
    anime_simulcast_region_counts = {}
    if simulcast_lines is not None:
        for line in simulcast_lines:
            title, subs = line.split("=")
            title = title.strip()
            anime = Anime.get_anime_from_database_by_name(title, session)
            if anime is None:
                print(f"{title} is not found in database")
            else:
                num_regions = len(
                    [entry for entry in subs.split() if entry == "simul"])
                anime_simulcast_region_counts[anime.id] = num_regions
    return anime_simulcast_region_counts
Esempio n. 5
0
def load_aces(input_lines: Iterable[str]) -> None:
    """Takes in an iterable of "<teamname> <anime to ace>" inputs.
    Parses these inputs and sets the anime for the team to ace for the week
    if the anime has not been previously aced on that team and the score for that anime hasn't hit the cutoff.
    """

    season_of_year = config.get("season info", "season").lower()
    year = config.getint("season info", "year")
    week = config.getint("weekly info", "current-week")

    with session_scope() as session:
        season = Season.get_season_from_database(season_of_year, year, session)
        for line in input_lines:
            teamname, animename = line.split(" ", 1)
            team = Team.get_team_from_database(teamname, season, session)
            anime = Anime.get_anime_from_database_by_name(
                animename.strip(), session)
            assert anime
            if not team_anime_aced_already(team, anime, session):
                this_week_team_anime = (session.query(TeamWeeklyAnime).filter(
                    TeamWeeklyAnime.anime_id == anime.id,
                    TeamWeeklyAnime.team_id == team.id,
                    TeamWeeklyAnime.week == week,
                ).one())
                if ace_already_loaded_this_week(team, week, session):
                    print(
                        f"{team.name} tried to ace {anime.name}, but already has an anime aced this week"
                    )
                elif this_week_team_anime.bench == 1:
                    print(
                        f"{team.name} tried to ace {anime.name}, but it was benched"
                    )
                else:
                    this_week_team_anime.ace = 1

            else:
                print(
                    f"{team.name} tried to ace {anime.name}, but it has already been aced"
                )
def add_anime_to_team(team: Team, anime_lines: Sequence[str], bench: int,
                      session: Session) -> None:
    """Add anime by name to the team in the database.
       Raises an exception if anime cannot be found in database
       """

    for anime_name in anime_lines:
        anime_name = anime_name.strip()
        anime = Anime.get_anime_from_database_by_name(anime_name, session)
        if not anime:
            print(f"{team.name} has {anime_name} on their team,"
                  " which is not in the database")
            return

        assert anime.season_id == team.season_id
        if not anime.eligible:
            print(f"{team.name} has {anime_name} on their team,"
                  " which is not eligible for this season")

        team_weekly_anime = TeamWeeklyAnime(team_id=team.id,
                                            anime_id=anime.id,
                                            week=0,
                                            bench=bench)
        session.merge(team_weekly_anime)
Esempio n. 7
0
config.read("config.ini")

vcrpath = config["vcr"]["path"]


def test_localize_number():
    assert ptw_counter.localize_number(1034) == "1,034"


@patch("fal.controllers.ptw_counter.time")
@pytest.mark.parametrize(
    "anime_list",
    [
        (
            [
                Anime(id=34134, name="One Punch Man Season 2", season_id=2),
                Anime(id=38524, name="Shingeki no Kyojin Season 3 Part 2", season_id=2),
            ]
        )
    ],
)
@vcr.use_cassette(f"{vcrpath}/ptw_counter/get-ptw-info.yaml")
def test_get_ptw_info(time_mock, ptw_fixture, anime_list):
    time_mock.sleep.return_value = None  # no need to wait in a unit test!
    ptw = ptw_counter.get_ptw_info(anime_list)
    assert ptw == ptw_fixture


@pytest.mark.parametrize(
    "season_of_year, year, ptw",
    [