"""Token file parser tests.""" from __future__ import annotations import pytest from cloud_sync.creds import CredentialsError, read_credentials def test_parses_one_liner(tmp_path): t = tmp_path / "token" t.write_text("358881557521498112:s3cret-pass\n") discord_id, password = read_credentials(t) assert discord_id == "358881557521498112" assert password == "s3cret-pass" def test_trims_whitespace(tmp_path): t = tmp_path / "token" t.write_text(" 123 : pw \n") discord_id, password = read_credentials(t) assert discord_id == "123" assert password == "pw" def test_missing_file_raises_with_actionable_message(tmp_path): missing = tmp_path / "missing-token" with pytest.raises(CredentialsError) as exc: read_credentials(missing) assert "token not found" in str(exc.value) assert "discord_id:password" in str(exc.value) def test_missing_colon_rejected(tmp_path): t = tmp_path / "token" t.write_text("no-colon-here") with pytest.raises(CredentialsError) as exc: read_credentials(t) assert "malformed" in str(exc.value) def test_empty_id_rejected(tmp_path): t = tmp_path / "token" t.write_text(":password") with pytest.raises(CredentialsError): read_credentials(t) def test_empty_password_rejected(tmp_path): t = tmp_path / "token" t.write_text("123:") with pytest.raises(CredentialsError): read_credentials(t) def test_password_with_colon_kept_intact(tmp_path): """Passwords containing : should be kept whole after the first split.""" t = tmp_path / "token" t.write_text("123:pw:with:colons") discord_id, password = read_credentials(t) assert discord_id == "123" assert password == "pw:with:colons"