コード例 #1
0
def get_auth_cookie_value() -> Optional[str]:
    """
    Returns Authorization field from any cookie, if none exist or all are
    expired then returns None
    """
    cookiejar = load_cookie()

    for cookie in cookiejar:
        if (cookie and cookie.name == "Authorization"
                and not cookie.is_expired()):
            return cookie.value

    return None
コード例 #2
0
def get_auth_cookie_expires_in_minutes() -> Optional[float]:
    """
    Returns the number of minutes until Authorization cookie expires
    """

    cookiejar = load_cookie()

    for cookie in cookiejar:
        if (cookie and cookie.name == "Authorization"
                and not cookie.is_expired()):
            expires = datetime.fromtimestamp(cookie.expires)
            time_remaining = expires - datetime.now()

            return time_remaining.seconds / 60

    return None
コード例 #3
0
def test_load_cookie_touches(mock_touch, mockop):
    load_cookie()
    mock_touch.assert_called_once_with("auth_cookie")
コード例 #4
0
def test_load_cookie_empty(mocker, mock_path):
    mo = mocker.mock_open(read_data=b"")
    mocker.patch("nhltv_lib.cookies.open", mo)
    assert load_cookie() == []
コード例 #5
0
def test_load_cookie(mock_path, mockop):
    assert load_cookie() == {"foo": "bar"}