Ejemplo n.º 1
0
    def test_push_unregistered_snap_must_raise_exception_if_not_registering(
            self):
        class MockResponse:
            status_code = 404

            def json(self):
                return dict(
                    error_list=[{
                        "code": "resource-not-found",
                        "message": "Snap not found for name=basic",
                    }])

        self.fake_store_push_precheck.mock.side_effect = [
            StorePushError("basic", MockResponse()),
            None,
        ]

        raised = self.assertRaises(storeapi.errors.StorePushError,
                                   self.run_command, ["push", self.snap_file])

        self.assertThat(
            str(raised),
            Contains(
                "This snap is not registered. Register the snap and try again."
            ),
        )
        self.fake_store_register.mock.assert_not_called()
Ejemplo n.º 2
0
    def test_push_unregistered_snap_must_ask(self):
        class MockResponse:
            status_code = 404

            def json(self):
                return dict(
                    error_list=[{
                        "code": "resource-not-found",
                        "message": "Snap not found for name=basic",
                    }])

        self.fake_store_push_precheck.mock.side_effect = [
            StorePushError("basic", MockResponse()),
            None,
        ]

        result = self.run_command(["push", self.snap_file], input="y\n")

        self.assertThat(result.exit_code, Equals(0))
        self.assertThat(
            result.output,
            Contains(
                "You are required to register this snap before continuing. "),
        )
        self.fake_store_register.mock.assert_called_once_with("basic",
                                                              is_private=False,
                                                              series="16",
                                                              store_id=None)
Ejemplo n.º 3
0
    def test_unregistered_snap_must_raise_exception(self):
        class MockResponse:
            status_code = 404
            error_list = [{
                "code": "resource-not-found",
                "message": "Snap not found for name=basic",
            }]

        patcher = mock.patch.object(storeapi.StoreClient, "push_precheck")
        mock_precheck = patcher.start()
        self.addCleanup(patcher.stop)
        mock_precheck.side_effect = StorePushError("basic", MockResponse())

        raised = self.assertRaises(
            storeapi.errors.StorePushError,
            self.run_command,
            ["push-metadata", self.snap_file],
        )

        self.assertThat(
            str(raised),
            Contains(
                "You are not the publisher or allowed to push revisions for this "
                "snap. To become the publisher, run `snapcraft register "
                "basic` and try to push again."),
        )
Ejemplo n.º 4
0
    def test_push_unregistered_snap_must_raise_exception(self):
        self.useFixture(fixture_setup.FakeTerminal())

        class MockResponse:
            status_code = 404
            error_list = [{
                'code': 'resource-not-found',
                'message': 'Snap not found for name=my-snap-name'
            }]

        patcher = mock.patch.object(storeapi.StoreClient, 'push_precheck')
        mock_precheck = patcher.start()
        self.addCleanup(patcher.stop)
        mock_precheck.side_effect = StorePushError('my-snap-name',
                                                   MockResponse())

        # Create a snap
        main(['init'])
        main(['snap'])
        snap_file = glob.glob('*.snap')[0]

        self.assertRaises(SystemExit, main, ['push', snap_file])

        self.assertIn(
            'You are not the publisher or allowed to push revisions for this '
            'snap. To become the publisher, run `snapcraft register '
            'my-snap-name` and try to push again.', self.fake_logger.output)
Ejemplo n.º 5
0
    def test_unregistered_snap_must_raise_exception(self):
        class MockResponse:
            status_code = 404

            def json(self):
                return dict(
                    error_list=[{
                        "code": "resource-not-found",
                        "message": "Snap not found for name=basic",
                    }])

        patcher = mock.patch.object(storeapi.StoreClient, "push_precheck")
        mock_precheck = patcher.start()
        self.addCleanup(patcher.stop)
        mock_precheck.side_effect = StorePushError("basic", MockResponse())

        raised = self.assertRaises(
            storeapi.errors.StorePushError,
            self.run_command,
            ["upload-metadata", self.snap_file],
        )

        self.assertThat(
            str(raised),
            Contains(
                "This snap is not registered. Register the snap and try again."
            ),
        )
Ejemplo n.º 6
0
    def test_push_unregistered_snap_must_raise_exception(self):
        class MockResponse:
            status_code = 404
            error_list = [{'code': 'resource-not-found',
                           'message': 'Snap not found for name=basic'}]

        patcher = mock.patch.object(storeapi.StoreClient, 'push_precheck')
        mock_precheck = patcher.start()
        self.addCleanup(patcher.stop)
        mock_precheck.side_effect = StorePushError(
            'basic', MockResponse())

        raised = self.assertRaises(
            storeapi.errors.StorePushError,
            self.run_command, ['push', self.snap_file])

        self.assertThat(str(raised), Contains(
            'You are not the publisher or allowed to push revisions for this '
            'snap. To become the publisher, run `snapcraft register '
            'basic` and try to push again.'))