How to use the snapcraft.storeapi function in snapcraft

To help you get started, we’ve selected a few snapcraft examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github snapcore / snapcraft / tests / unit / commands / test_create_key.py View on Github external
def test_create_key_snapd_not_installed(self):
        self.fake_package_installed.mock.return_value = False

        raised = self.assertRaises(
            storeapi.errors.MissingSnapdError, self.run_command, ["create-key"]
        )

        self.assertThat(str(raised), Contains("The snapd package is not installed."))
        self.fake_package_installed.mock.assert_called_with("snapd")
        self.fake_check_output.mock.assert_not_called()
        self.fake_check_call.mock.assert_not_called()
github snapcore / snapcraft / tests / unit / integrations / test_travis.py View on Github external
def test_enable_successfully(
        self,
        mock_get_account_information,
        mock_login,
        mock_check_call,
        mock_check_output,
        mock_prompt,
    ):
        mock_prompt.side_effect = ["sample.person@canonical.com", "secret", "123456"]
        mock_login.side_effect = [
            storeapi.errors.StoreTwoFactorAuthenticationRequired(),
            None,
        ]
        mock_get_account_information.return_value = {"account_id": "abcd"}

        mock_check_call.side_effect = [None, None]
        mock_check_output.side_effect = [None]
        snapcraft_yaml_file_path = self.make_snapcraft_yaml(test_snapcraft_yaml)
        project = Project(snapcraft_yaml_file_path=snapcraft_yaml_file_path)
        self.make_travis_yml('after_success: [""]')

        travis.enable(project)

        # Attenuated credentials requested from the Store.
        mock_login.assert_called_with(
            "sample.person@canonical.com",
            "secret",
github snapcore / snapcraft / tests / unit / commands / test_status.py View on Github external
def test_status_with_3rd_party_snap_by_arch(self):
        raised = self.assertRaises(
            storeapi.errors.SnapNotFoundError,
            self.run_command,
            ["status", "snap-test", "--arch=arm64"],
        )

        self.assertThat(
            str(raised),
            Equals("Snap 'snap-test' for 'arm64' was not found in '16' series."),
        )
github snapcore / snapcraft / tests / unit / commands / test_login.py View on Github external
"error_list": [
                {
                    "message": storeapi.constants.MISSING_AGREEMENT,
                    "extra": {"url": "http://fake-url.com", "api": "fake-api"},
                }
            ]
        }
        response.json.return_value = content
        self.fake_store_account_info.mock.side_effect = storeapi.errors.StoreAccountInformationError(
            response
        )

        result = self.run_command(["login"], input="user@example.com\nsecret\nn\n")

        self.assertThat(result.exit_code, Equals(1))
        self.assertThat(result.output, Contains(storeapi.constants.AGREEMENT_ERROR))
        self.assertThat(result.output, Contains("Login failed."))
github snapcore / snapcraft / tests / unit / lifecycle / test_lifecycle.py View on Github external
def test_stable_grade_for_non_stable_base(self):
        self.fake_storeapi_get_info.mock.side_effect = snapcraft.storeapi.errors.SnapNotFoundError(
            name="core18"
        )
        lifecycle.execute(steps.PULL, self.project_config)

        global_state = states.GlobalState.load(filepath=self.global_state_filepath)
        self.assertThat(global_state.get_required_grade(), Equals("devel"))
        self.fake_storeapi_get_info.mock.assert_called_once_with("core18")
github snapcore / snapcraft / tests / unit / commands / test_status.py View on Github external
def test_status_without_login_must_ask(self):
        self.fake_store_account_info.mock.side_effect = [
            storeapi.errors.InvalidCredentialsError("error"),
            {"snaps": {"16": {"snap-test": {"snap-id": "snap-test-snap-id"}}}},
            {"snaps": {"16": {"snap-test": {"snap-id": "snap-test-snap-id"}}}},
            {"snaps": {"16": {"snap-test": {"snap-id": "snap-test-snap-id"}}}},
        ]
        self.fake_store_status.mock.return_value = {
            "channel_map_tree": {"latest": {"16": self.expected}}
        }

        result = self.run_command(
            ["status", "snap-test"], input="user@example.com\nsecret\n"
        )
        self.assertThat(
            result.output, Contains("You are required to login before continuing.")
        )
github snapcore / snapcraft / tests / unit / commands / test_release.py View on Github external
def test_release_without_login_must_ask(self):
        self.fake_store_release.mock.side_effect = [
            storeapi.errors.InvalidCredentialsError("error"),
            {
                "opened_channels": ["beta"],
                "channel_map_tree": {
                    "latest": {
                        "16": {
                            "amd64": [
                                {"channel": "stable", "info": "none"},
                                {"channel": "candidate", "info": "none"},
                                {
                                    "revision": 19,
                                    "channel": "beta",
                                    "version": "0",
                                    "info": "specific",
                                },
                                {"channel": "edge", "info": "tracking"},
                            ]
github snapcore / snapcraft / tests / unit / store / test_store_client.py View on Github external
    @mock.patch.object(storeapi.StoreClient, "get_account_information")
    @mock.patch.object(storeapi._sca_client.SCAClient, "get")
    def test_get_snap_status_server_error(self, mock_sca_get, mock_account_info):
        mock_account_info.return_value = {
            "snaps": {"16": {"basic": {"snap-id": "my_snap_id"}}}
        }

        mock_sca_get.return_value = mock.Mock(
            ok=False, status_code=500, reason="Server error", json=lambda: {}
        )

        self.client.login("dummy", "test correct password")
        e = self.assertRaises(
            storeapi.errors.StoreSnapStatusError, self.client.get_snap_status, "basic"
        )
        self.assertThat(
            str(e),
github snapcore / snapcraft / snapcraft / internal / lifecycle / _runner.py View on Github external
def _get_required_grade(*, base: Optional[str], arch: str) -> str:
    # Some types of snap do not require a base.
    if base is None:
        return "stable"

    # This will make a request over the network.
    # We use storeapi instead of repo.snaps so this can work under Docker
    # and related environments.
    try:
        base_info = storeapi.StoreClient().cpi.get_info(base)
        base_info.get_channel_mapping(risk="stable", arch=arch)
    except storeapi.errors.SnapNotFoundError:
        return "devel"
    else:
        return "stable"
github snapcore / snapcraft / snapcraft / integrations / travis.py View on Github external
def enable(project):
    series = storeapi.constants.DEFAULT_SERIES
    project_config = project_loader.load_config(project)
    snap_name = project_config.data["name"]
    logger.info(
        "Enabling Travis testbeds to push and release {!r} snaps "
        "to edge channel in series {!r}".format(snap_name, series)
    )

    packages = [{"name": snap_name, "series": series}]
    channels = ["edge"]
    _acquire_and_encrypt_credentials(packages, channels)

    logger.info(
        'Configuring "deploy" phase to build and release the snap in the ' "Store."
    )
    with open(TRAVIS_CONFIG_FILENAME, "r+") as fd:
        travis_conf = yaml_utils.load(fd)