diff --git a/rye/tests/common/mod.rs b/rye/tests/common/mod.rs index 6162682514..e2f25a6ad2 100644 --- a/rye/tests/common/mod.rs +++ b/rye/tests/common/mod.rs @@ -64,23 +64,21 @@ toolchain = "cpython@3.12.1" r#" [pypi] - [bad-repo] repository-url = "bad url" username = "bad name" token = "bad token" [good-repo-bad-token] -repository-url = "https://test.pypi.org/legacy/" +repository-url = "http://localhost:5353" token = "bad token" - [good-repo-keyring] -repository-url = "https://test.pypi.org/legacy/" +repository-url = "http://localhost:5353" username = "test-keyring" [no-repo-username-keyring] -repository-url = "https://test.pypi.org/legacy/" +repository-url = "http://localhost:5353" "#, ) .unwrap(); diff --git a/rye/tests/test_publish.rs b/rye/tests/test_publish.rs index 53a607c272..6d3b931744 100644 --- a/rye/tests/test_publish.rs +++ b/rye/tests/test_publish.rs @@ -6,12 +6,12 @@ mod common; #[test] fn test_publish() { let space = Space::new(); - space.init("my-project"); + space.init("test-project"); - // Build 'my-project' for distribution - // TODO(cnpryer) - space.rye_cmd().arg("build").status().unwrap(); + let credentials_path = space.rye_home().join("credentials"); + let credentials = std::fs::read_to_string(&credentials_path).unwrap(); + // prompt for token rye_cmd_snapshot!(space.rye_cmd().arg("publish"), @r###" success: false exit_code: 1 @@ -25,10 +25,42 @@ fn test_publish() { not a terminal "###); - // TODO(cnpryer) - // rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials"), @r###" - // "###); + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + No access token found, generate one at: https://pypi.org/manage/account/token/ + ERROR InvalidDistribution: Cannot find file (or expand pattern): + '[TEMP_PATH]/project/dist/*' + + ----- stderr ----- + Access token: error: failed to publish files + "###); + + // invalid auth ('token') + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--username").arg("user").arg("--token").arg("token"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + ERROR InvalidDistribution: Cannot find file (or expand pattern): + '[TEMP_PATH]/project/dist/*' + + ----- stderr ----- + error: failed to publish files + "###); + + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--token").arg("token"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + ERROR InvalidDistribution: Cannot find file (or expand pattern): + '[TEMP_PATH]/project/dist/*' + + ----- stderr ----- + error: failed to publish files + "###); + // invalid credentials file rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("no-repo"), @r###" success: false exit_code: 1 @@ -47,39 +79,43 @@ fn test_publish() { error: relative URL without a base "###); - // TODO(cnpryer) - // rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("good-repo-bad-token").arg("-y"), @r###" - // success: false - // exit_code: 1 - // ----- stdout ----- + // --yes + rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("--skip-save-credentials").arg("--repository").arg("good-repo-bad-token").arg("-y"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + ERROR InvalidDistribution: Cannot find file (or expand pattern): + '[TEMP_PATH]/project/dist/*' - // ----- stderr ----- - // error: relative URL without a base - // "###); + ----- stderr ----- + error: failed to publish files + "###); - // TODO(cnpryer) - // fail until keyring setup + // keyring rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("-r").arg("good-repo-keyring").arg("--skip-save-credentials").arg("-y"), @r###" success: false exit_code: 1 ----- stdout ----- - Uploading distributions to https://test.pypi.org/legacy/ - ERROR NonInteractive: Credential not found for password. + ERROR InvalidDistribution: Cannot find file (or expand pattern): + '[TEMP_PATH]/project/dist/*' ----- stderr ----- error: failed to publish files "###); - // TODO(cnpryer) - // prompt username + // prompt username (keyring fallback) rye_cmd_snapshot!(space.rye_cmd().arg("publish").arg("-r").arg("no-repo-username-keyring"), @r###" success: false exit_code: 1 ----- stdout ----- - Uploading distributions to https://test.pypi.org/legacy/ - ERROR NonInteractive: Credential not found for password. + ERROR InvalidDistribution: Cannot find file (or expand pattern): + '[TEMP_PATH]/project/dist/*' ----- stderr ----- Username: error: failed to publish files "###); + + let final_credentials = std::fs::read_to_string(credentials_path).unwrap(); + + assert_eq!(credentials, final_credentials); }