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), )
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)
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))
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))
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))
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))
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)
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))
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))
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))
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)
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)
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))
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))
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))
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))
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))
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))
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))
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()))
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))
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))
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))
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))
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()))
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))
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))
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), )