def test_logout_removes_token(monkeypatch): with tempfile.NamedTemporaryFile(delete=False) as f: monkeypatch.setattr("prefect.client.Client.local_token_path", f.name) client = Client() client.login(api_token="a") assert f.read() == b"a" client.logout() assert not os.path.exists(f.name)
def test_client_logs_out_and_deletes_auth_token(monkeypatch): post = MagicMock(return_value=MagicMock( ok=True, json=MagicMock(return_value=dict(token="secrettoken")))) monkeypatch.setattr("requests.post", post) with set_temporary_config({"cloud.graphql": "http://my-cloud.foo"}): client = Client() client.login("*****@*****.**", "1234") token_path = os.path.expanduser("~/.prefect/.credentials/auth_token") assert os.path.exists(token_path) with open(token_path, "r") as f: assert f.read() == "secrettoken" client.logout() assert not os.path.exists(token_path)