def save_cookie(cookies: RequestsCookieJar) -> None: # Ensure the cookie file exists if not os.path.isfile(COOKIE_FILE): touch(COOKIE_FILE) with open(COOKIE_FILE, "wb") as f: return pickle.dump(cookies, f)
def save_cookies_to_txt(cookies: List[Any], filename: str) -> None: # Ensure the cookie file exists if not os.path.isfile(filename): touch(filename) cjar = MozillaCookieJar(filename) for cookie in cookies: cjar.set_cookie(cookie) cjar.save(ignore_discard=False)
def load_cookie() -> List[Optional[Any]]: # Ensure the cookie file exists if not os.path.isfile(COOKIE_FILE): touch(COOKIE_FILE) with open(COOKIE_FILE, "rb") as f: try: return pickle.load(f) except EOFError: return []
def test_touch_yes(mock_isfile, mock_path_touch): mock_isfile.return_value = False touch("boo") mock_path_touch.assert_called_once()
def test_touch(mock_isfile, mock_path_touch): mock_isfile.return_value = True touch("boo") mock_path_touch.assert_not_called()