How to use the snapcraft.storeapi.errors 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 / store / test_store_client.py View on Github external
def test_get_snap_status_no_id(self):
        self.client.login("dummy", "test correct password")
        e = self.assertRaises(
            storeapi.errors.NoSnapIdError, self.client.get_snap_status, "no-id"
        )
        self.assertThat(e.snap_name, Equals("no-id"))
github snapcore / snapcraft / tests / unit / store / test_client.py View on Github external
def test_max_retries_error(self, mock_request):
        mock_request.side_effect = exceptions.ConnectionError(
            urllib3.exceptions.MaxRetryError(pool="test-pool", url="test-url")
        )
        self.assertRaises(
            errors.StoreNetworkError, self.client.request, "GET", "test-url"
        )
github snapcore / snapcraft / tests / unit / commands / test_list_keys.py View on Github external
def test_command_without_login_must_ask(self):
        # TODO: look into why this many calls are done inside snapcraft.storeapi
        self.fake_store_account_info.mock.side_effect = [
            storeapi.errors.InvalidCredentialsError("error"),
            {"account_id": "abcd", "account_keys": list()},
            {"account_id": "abcd", "account_keys": list()},
            {"account_id": "abcd", "account_keys": list()},
        ]

        result = self.run_command(
            [self.command_name], input="user@example.com\nsecret\n"
        )
        self.assertThat(
            result.output, Contains("You are required to login before continuing.")
        )
github snapcore / snapcraft / tests / unit / store / test_store_client.py View on Github external
def test_push_snap_build_invalid_data(self):
        self.client.login("dummy", "test correct password")
        raised = self.assertRaises(
            errors.StoreSnapBuildError,
            self.client.push_snap_build,
            "snap-id",
            "test-invalid-data",
        )
        self.assertThat(
            str(raised),
            Equals("Could not assert build: The snap-build assertion is not " "valid."),
        )
github snapcore / snapcraft / tests / unit / commands / test_push_metadata.py View on Github external
"snap-id": "snap-test-snap-id",
                            "status": "Approved",
                            "private": False,
                            "since": "2016-12-12T01:01Z",
                            "price": "0",
                        }
                    }
                },
            },
        )
        self.useFixture(self.fake_store_account_info)

        self.fake_store_push_metadata = fixtures.MockPatchObject(
            storeapi.StoreClient,
            "push_metadata",
            side_effect=[storeapi.errors.InvalidCredentialsError("error"), None],
        )
        self.useFixture(self.fake_store_push_metadata)

        result = self.run_command(
            ["push-metadata", self.snap_file], input="user@example.com\nsecret\n"
        )
        self.assertThat(
            result.output, Contains("You are required to login before continuing.")
        )
github snapcore / snapcraft / tests / unit / store / test_store_client.py View on Github external
self.client.login("dummy", "test correct password")
        self.client.register("test-duplicate-snap")
        tracker = self.client.upload("test-duplicate-snap", self.snap_path)
        self.assertTrue(isinstance(tracker, storeapi._status_tracker.StatusTracker))
        result = tracker.track()
        expected_result = {
            "code": "processing_error",
            "revision": "1",
            "url": "/dev/click-apps/5349/rev/1",
            "can_release": False,
            "processed": True,
            "errors": [{"message": "Duplicate snap already uploaded"}],
        }
        self.assertThat(result, Equals(expected_result))

        raised = self.assertRaises(errors.StoreReviewError, tracker.raise_for_code)

        self.assertThat(
            str(raised),
            Equals(
                "The store was unable to accept this snap.\n"
                "  - Duplicate snap already uploaded"
github snapcore / snapcraft / snapcraft / _store.py View on Github external
built_at=built_at,
            channels=channels,
            delta_format=delta_format,
            source_hash=snap_hashes["source_hash"],
            target_hash=snap_hashes["target_hash"],
            delta_hash=snap_hashes["delta_hash"],
        )
        result = delta_tracker.track()
        delta_tracker.raise_for_code()
    except storeapi.errors.StoreReviewError as e:
        if e.code == "processing_upload_delta_error":
            raise storeapi.errors.StoreDeltaApplicationError(str(e))
        else:
            raise
    except storeapi.errors.StoreServerError as e:
        raise storeapi.errors.StorePushError(snap_name, e.response)
    finally:
        if os.path.isfile(delta_filename):
            try:
                os.remove(delta_filename)
            except OSError:
                logger.warning("Unable to remove delta {}.".format(delta_filename))
    return result
github snapcore / snapcraft / snapcraft / cli / store.py View on Github external
def _requires_login():
    try:
        yield
    except storeapi.errors.InvalidCredentialsError:
        echo.error("No valid credentials found." ' Have you run "snapcraft login"?')
        raise
github snapcore / snapcraft / snapcraft / _store.py View on Github external
def _generate_snap_build(authority_id, snap_id, grade, key_name, snap_filename):
    """Return the signed snap-build declaration for a snap on disk."""
    cmd = [
        "snap",
        "sign-build",
        "--developer-id=" + authority_id,
        "--snap-id=" + snap_id,
        "--grade=" + grade,
    ]
    if key_name:
        cmd.extend(["-k", key_name])
    cmd.append(snap_filename)
    try:
        return subprocess.check_output(cmd)
    except subprocess.CalledProcessError as e:
        raise storeapi.errors.SignBuildAssertionError(snap_filename) from e