def test_to_create_race_profile_page_url():
    args = {'registration_number': 4444}
    factory = UrlFactory(version=Version.V1707,
                         page_type=PageType.RACER_PROFILE_PAGE,
                         args=args)
    assert str(factory.create(
    )) == "https://boatrace.jp/owpc/pc/data/racersearch/profile?toban=4444"
def test_to_create_event_holdings_page_url():
    args = {'date': '2020-03-20'}
    factory = UrlFactory(version=Version.V1707,
                         page_type=PageType.EVENT_HOLDINGS_PAGE,
                         args=args)
    assert str(factory.create()
               ) == "https://boatrace.jp/owpc/pc/race/index?hd=20200320"
def test_to_create_event_schedule_page_url():
    args = {'year': 2020, 'month': 3}
    factory = UrlFactory(version=Version.V1707,
                         page_type=PageType.EVENT_SCHEDULE_PAGE,
                         args=args)
    assert str(factory.create(
    )) == "https://boatrace.jp/owpc/pc/race/monthlyschedule?ym=202003"
def test_to_create_event_entries_page_url():
    stadium_tel_code = 4
    args = {
        'stadium_tel_code': stadium_tel_code,
        'event_starts_on': '2020-03-17'
    }
    factory = UrlFactory(version=Version.V1707,
                         page_type=PageType.EVENT_ENTRIES_PAGE,
                         args=args)
    assert str(factory.create(
    )) == "https://boatrace.jp/owpc/pc/race/rankingmotor?jcd=04&hd=20200317"
def test_to_create_race_odds_page_url():
    stadium_tel_code = 4
    race_number = 6
    args = {
        'stadium_tel_code': stadium_tel_code,
        'race_opened_on': '2020-03-20',
        'race_number': race_number
    }
    factory = UrlFactory(version=Version.V1707,
                         page_type=PageType.RACE_ODDS_PAGE,
                         args=args)
    assert str(factory.create(
    )) == "https://boatrace.jp/owpc/pc/race/odds3t?rno=6&jcd=04&hd=20200320"
def test_to_create_race_exhibition_page_url():
    stadium_tel_code = 4
    race_number = 6
    args = {
        'stadium_tel_code': stadium_tel_code,
        'race_opened_on': '2020-03-20',
        'race_number': race_number
    }
    factory = UrlFactory(version=Version.V1707,
                         page_type=PageType.RACE_EXHIBITION_INFORMATION_PAGE,
                         args=args)
    assert str(
        factory.create()
    ) == "https://boatrace.jp/owpc/pc/race/beforeinfo?rno=6&jcd=04&hd=20200320"
def redirection():
    version = _get_version()
    page_type = _get_page_type()
    args = _without_keys(request.args, {'version', 'page_type'})
    url_object = UrlFactory(version=version, page_type=page_type,
                            args=args).create()
    return redirect(str(url_object), code=302)
def file():
    version = _get_version()
    page_type = _get_page_type()
    args = _without_keys(request.args, {'version', 'page_type'})
    cache_file = FileFactory(version=version, page_type=page_type,
                             args=args).create()
    # HACK: `cache_file.content() is None` を先に評価しないと `FileNotFoundError` が発生してしまうバギーなコード
    # ディレクトリの生成自体は `cache_file.content() is None` でやってるから、
    # `request.headers.get('Cache-Control') == 'no-cache'` を or で先に評価して真になったら
    # `cache_file.content() is None`が実行されず(ディレクトリの生成が行われず)に前述したエラーとなる
    if (cache_file.content() is None) or (request.headers.get('Cache-Control')
                                          == 'no-cache'):
        url_object = UrlFactory(version=version,
                                page_type=page_type,
                                args=args).create()
        urllib.request.urlretrieve(str(url_object), cache_file.path())
    return cache_file.content()