Exemple #1
0
def test_export_login_with_params(emitter, fake_store_login):
    cmd = commands.StoreExportLoginCommand(None)

    cmd.run(
        argparse.Namespace(
            login_file="-",
            snaps="fake-snap,fake-other-snap",
            channels="stable,edge",
            acls="package_manage,package_push",
            expires="2030-12-12",
            experimental_login=False,
        ))

    assert fake_store_login.mock_calls == [
        call(
            ANY,
            packages=["fake-snap", "fake-other-snap"],
            channels=["stable", "edge"],
            acls=["package_manage", "package_push"],
            ttl=ANY,
        )
    ]
    emitter.assert_message(
        "Exported login credentials:\nsecret"
        "\n\nThese credentials must be used on Snapcraft 7.0 or greater.")
Exemple #2
0
def test_export_login_with_candid(emitter, fake_store_login, monkeypatch):
    monkeypatch.setenv("SNAPCRAFT_STORE_AUTH", "candid")

    cmd = commands.StoreExportLoginCommand(None)

    cmd.run(
        argparse.Namespace(
            login_file="-",
            snaps="fake-snap,fake-other-snap",
            channels="stable,edge",
            acls="package_manage,package_push",
            expires="2030-12-12",
            experimental_login=False,
        ))

    assert fake_store_login.mock_calls == [
        call(
            ANY,
            packages=["fake-snap", "fake-other-snap"],
            channels=["stable", "edge"],
            acls=["package_manage", "package_push"],
            ttl=ANY,
        )
    ]
    emitter.assert_message(
        "Exported login credentials:\nsecret"
        "\n\nThese credentials must be used on Snapcraft 7.0 or greater."
        "\nSet 'SNAPCRAFT_STORE_AUTH=candid' for these credentials to work.")
Exemple #3
0
def test_export_login(emitter, fake_store_login):
    cmd = commands.StoreExportLoginCommand(None)

    cmd.run(
        argparse.Namespace(
            login_file="-",
            snaps=None,
            channels=None,
            acls=None,
            expires=None,
            experimental_login=False,
        ))

    assert fake_store_login.mock_calls == [call(ANY, )]
    emitter.assert_message(
        "Exported login credentials:\nsecret"
        "\n\nThese credentials must be used on Snapcraft 7.0 or greater.")
Exemple #4
0
def test_export_login_with_experimental_fails():
    cmd = commands.StoreExportLoginCommand(None)

    with pytest.raises(craft_cli.errors.ArgumentParsingError) as raised:
        cmd.run(
            argparse.Namespace(
                login_file="-",
                snaps=None,
                channels=None,
                acls=None,
                expires=None,
                experimental_login=True,
            ))

    assert str(raised.value) == (
        "--experimental-login no longer supported. Set SNAPCRAFT_STORE_AUTH=candid instead"
    )
Exemple #5
0
def test_export_login_file(new_dir, emitter, fake_store_login):
    cmd = commands.StoreExportLoginCommand(None)

    cmd.run(
        argparse.Namespace(
            login_file="target_file",
            snaps=None,
            channels=None,
            acls=None,
            expires=None,
            experimental_login=False,
        ))

    assert fake_store_login.mock_calls == [call(ANY, )]
    emitter.assert_message(
        "Exported login credentials to 'target_file'"
        "\n\nThese credentials must be used on Snapcraft 7.0 or greater.")
    login_file = new_dir / "target_file"
    assert login_file.exists()
    assert login_file.read_text() == "secret"