Пример #1
0
    def test_post_conflict(self):
        user = UserFactory(
            roles=[Role.find("developer"),
                   Role.find("package_admin")])
        db.session.commit()

        architectures = [
            Architecture.find("88f628x"),
            Architecture.find("cedarview")
        ]
        build = BuildFactory.build(architectures=architectures)
        with create_spk(build) as spk:
            self.assert201(
                self.client.post(
                    url_for("api.packages"),
                    headers=authorization_header(user),
                    data=spk.read(),
                ))
            spk.seek(0)
            response = self.client.post(
                url_for("api.packages"),
                headers=authorization_header(user),
                data=spk.read(),
            )
        self.assert409(response)
        self.assertIn(
            "Conflicting architectures: 88f628x, cedarview",
            response.data.decode(response.charset),
        )
Пример #2
0
    def test_post_minimum(self):
        user = UserFactory(roles=[Role.find('developer'), Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        with create_spk(build) as spk:
            self.assert201(self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                            data=spk.read()))
        self.assertBuildInserted(Build.query.one(), build, user)
Пример #3
0
    def test_post_signed(self):
        user = UserFactory(roles=[Role.find('developer'), Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        with create_spk(build, signature='signature') as spk:
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Package contains a signature', response.data.decode(response.charset))
Пример #4
0
    def test_post_invalid_spk(self):
        user = UserFactory(roles=[Role.find('developer'), Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        with create_spk(build) as spk:
            spk.seek(100)
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Invalid SPK', response.data.decode(response.charset))
Пример #5
0
    def test_post_wrong_version(self):
        user = UserFactory(roles=[Role.find('developer'), Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        info = create_info(build)
        info['version'] = '1.2.3~4'
        with create_spk(build, info=info) as spk:
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Invalid version', response.data.decode(response.charset))
Пример #6
0
    def test_post_wrong_description_language(self):
        user = UserFactory(roles=[Role.find('developer'), Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        info = create_info(build)
        info['description_zzz'] = 'description_zzz'
        with create_spk(build, info=info) as spk:
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Unknown INFO description language', response.data.decode(response.charset))
Пример #7
0
    def test_post_not_startable(self):
        user = UserFactory(
            roles=[Role.find('developer'),
                   Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build(version__startable=False)
        with create_spk(build) as spk:
            self.assert201(
                self.client.post(url_for('api.packages'),
                                 headers=authorization_header(user),
                                 data=spk.read()))
        self.assertBuildInserted(Build.query.one(), build, user)
Пример #8
0
    def test_post_conflict(self):
        user = UserFactory(roles=[Role.find('developer'), Role.find('package_admin')])
        db.session.commit()

        architectures = [Architecture.find('88f628x'), Architecture.find('cedarview')]
        build = BuildFactory.build(architectures=architectures)
        with create_spk(build) as spk:
            self.assert201(self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                            data=spk.read()))
            spk.seek(0)
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert409(response)
        self.assertIn('Conflicting architectures: 88f628x, cedarview', response.data.decode(response.charset))
Пример #9
0
    def test_post_invalid_spk(self):
        user = UserFactory(
            roles=[Role.find('developer'),
                   Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        with create_spk(build) as spk:
            spk.seek(100)
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Invalid SPK', response.data.decode(response.charset))
Пример #10
0
    def test_post_signed(self):
        user = UserFactory(
            roles=[Role.find('developer'),
                   Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        with create_spk(build, signature='signature') as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Package contains a signature',
                      response.data.decode(response.charset))
Пример #11
0
    def test_post_icons_in_both(self):
        user = UserFactory(
            roles=[Role.find('developer'),
                   Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        with create_spk(build, with_package_icons=True,
                        with_info_icons=True) as spk:
            self.assert201(
                self.client.post(url_for('api.packages'),
                                 headers=authorization_header(user),
                                 data=spk.read()))
        self.assertBuildInserted(Build.query.one(), build, user)
Пример #12
0
    def test_post_upgrade_wizard(self):
        user = UserFactory(
            roles=[Role.find("developer"),
                   Role.find("package_admin")])
        db.session.commit()

        build = BuildFactory.build(version__upgrade_wizard=True)
        with create_spk(build) as spk:
            self.assert201(
                self.client.post(
                    url_for("api.packages"),
                    headers=authorization_header(user),
                    data=spk.read(),
                ))
        self.assertBuildInserted(Build.query.one(), build, user)
Пример #13
0
    def test_post_no_data(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        response = self.client.post(url_for('api.packages'), headers=authorization_header(user))
        self.assert400(response)
        self.assertIn('No data to process', response.data.decode(response.charset))
Пример #14
0
    def test_post_wrong_version(self):
        user = UserFactory(
            roles=[Role.find('developer'),
                   Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        info = create_info(build)
        info['version'] = '1.2.3~4'
        with create_spk(build, info=info) as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Invalid version',
                      response.data.decode(response.charset))
Пример #15
0
    def test_post_wrong_description_language(self):
        user = UserFactory(
            roles=[Role.find('developer'),
                   Role.find('package_admin')])
        db.session.commit()

        build = BuildFactory.build()
        info = create_info(build)
        info['description_zzz'] = 'description_zzz'
        with create_spk(build, info=info) as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Unknown INFO description language',
                      response.data.decode(response.charset))
Пример #16
0
    def test_post_new_package_not_author_not_maintainer_user(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        with create_spk(BuildFactory.build()) as spk:
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert403(response)
        self.assertIn('Insufficient permissions to create new packages', response.data.decode(response.charset))
Пример #17
0
    def test_post_wrong_version(self):
        user = UserFactory(
            roles=[Role.find("developer"),
                   Role.find("package_admin")])
        db.session.commit()

        build = BuildFactory.build()
        info = create_info(build)
        info["version"] = "1.2.3~4"
        with create_spk(build, info=info) as spk:
            response = self.client.post(
                url_for("api.packages"),
                headers=authorization_header(user),
                data=spk.read(),
            )
        self.assert422(response)
        self.assertIn("Invalid version",
                      response.data.decode(response.charset))
Пример #18
0
    def test_post_wrong_displayname_language(self):
        user = UserFactory(
            roles=[Role.find("developer"),
                   Role.find("package_admin")])
        db.session.commit()

        build = BuildFactory.build()
        info = create_info(build)
        info["displayname_zzz"] = "displayname_zzz"
        with create_spk(build, info=info) as spk:
            response = self.client.post(
                url_for("api.packages"),
                headers=authorization_header(user),
                data=spk.read(),
            )
        self.assert422(response)
        self.assertIn("Unknown INFO displayname language",
                      response.data.decode(response.charset))
Пример #19
0
    def test_post_no_data(self):
        user = UserFactory(roles=[Role.find("developer")])
        db.session.commit()

        response = self.client.post(url_for("api.packages"),
                                    headers=authorization_header(user))
        self.assert400(response)
        self.assertIn("No data to process",
                      response.data.decode(response.charset))
Пример #20
0
    def test_post_existing_package_maintainer_user(self):
        user = UserFactory(roles=[Role.find('developer')])
        package = PackageFactory(maintainers=[user])
        db.session.commit()

        build = BuildFactory.build(version__package=package)
        db.session.expire(package)
        with create_spk(build) as spk:
            self.assert201(self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                            data=spk.read()))
Пример #21
0
    def test_post_unknown_architecture(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        build = BuildFactory.build(architectures=[Architecture(code='newarch')])
        with create_spk(build) as spk:
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Unknown architecture: newarch', response.data.decode(response.charset))
Пример #22
0
    def test_post_unknown_firmware(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        build = BuildFactory.build(firmware=Firmware(version='1.0', build=421))
        with create_spk(build) as spk:
            response = self.client.post(url_for('api.packages'), headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Unknown firmware', response.data.decode(response.charset))
Пример #23
0
    def test_post_new_package_not_author_not_maintainer_user(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        with create_spk(BuildFactory.build()) as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert403(response)
        self.assertIn('Insufficient permissions to create new packages',
                      response.data.decode(response.charset))
Пример #24
0
    def test_post_unknown_firmware(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        build = BuildFactory.build(firmware=Firmware(version='1.0', build=421))
        with create_spk(build) as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Unknown firmware',
                      response.data.decode(response.charset))
Пример #25
0
    def test_post_existing_package_maintainer_user(self):
        user = UserFactory(roles=[Role.find('developer')])
        package = PackageFactory(maintainers=[user])
        db.session.commit()

        build = BuildFactory.build(version__package=package)
        db.session.expire(package)
        with create_spk(build) as spk:
            self.assert201(
                self.client.post(url_for('api.packages'),
                                 headers=authorization_header(user),
                                 data=spk.read()))
Пример #26
0
    def test_post_unknown_architecture(self):
        user = UserFactory(roles=[Role.find('developer')])
        db.session.commit()

        build = BuildFactory.build(
            architectures=[Architecture(code='newarch')])
        with create_spk(build) as spk:
            response = self.client.post(url_for('api.packages'),
                                        headers=authorization_header(user),
                                        data=spk.read())
        self.assert422(response)
        self.assertIn('Unknown architecture: newarch',
                      response.data.decode(response.charset))
Пример #27
0
    def test_post_invalid_firmware(self):
        user = UserFactory(roles=[Role.find("developer")])
        db.session.commit()

        build = BuildFactory.build(firmware=Firmware(version="1.0", build=42))
        with create_spk(build) as spk:
            response = self.client.post(
                url_for("api.packages"),
                headers=authorization_header(user),
                data=spk.read(),
            )
        self.assert422(response)
        self.assertIn("Invalid firmware",
                      response.data.decode(response.charset))
Пример #28
0
    def test_post_existing_package_not_author_not_maintainer_user(self):
        user = UserFactory(roles=[Role.find("developer")])
        package = PackageFactory()
        db.session.commit()

        with create_spk(BuildFactory.build(version__package=package)) as spk:
            response = self.client.post(
                url_for("api.packages"),
                headers=authorization_header(user),
                data=spk.read(),
            )
        self.assert403(response)
        self.assertIn(
            "Insufficient permissions on this package",
            response.data.decode(response.charset),
        )