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
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
def test_load_cookie_touches(mock_touch, mockop): load_cookie() mock_touch.assert_called_once_with("auth_cookie")
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() == []
def test_load_cookie(mock_path, mockop): assert load_cookie() == {"foo": "bar"}