def test_cannot_archive_package_when_package_misses_info(self): invalid_packages = [ Package(product='1'), # without version Package(version='1'), # without product UID Package(version='1', product='1'), # without objects ] output = self.create_file() os.remove(output) for pkg in invalid_packages: with self.assertRaises(ValueError): dump_package_archive(pkg, output)
def test_can_archive_package(self): pkg = self.create_package()[0] expected = '{}-{}.uhupkg'.format(self.product, self.version) self.addCleanup(os.remove, expected) observed = dump_package_archive(pkg) self.assertEqual(expected, observed) self.verify_archive(observed)
def test_dump_package_archive_does_not_archive_links(self): pkg = Package(version=self.version, product=self.product) expected = '{}-{}.uhupkg'.format(self.product, self.version) hlink = 'updatehub_hlink' self.addCleanup(os.remove, hlink) self.obj_options['filename'] = hlink os.symlink(self.obj_fn, hlink) pkg.objects.create(self.obj_options) slink = 'updatehub_slink' self.addCleanup(os.remove, slink) self.obj_options['filename'] = slink os.link(self.obj_fn, slink) pkg.objects.create(self.obj_options) self.addCleanup(os.remove, expected) observed = dump_package_archive(pkg) self.assertEqual(len(pkg.objects.all()), 4) self.verify_archive(observed)
def test_cannot_archive_package_when_metadata_is_invalid(self, mock): pkg = self.create_package()[0] output = self.create_file() with self.assertRaises(ValueError): dump_package_archive(pkg, output, force=True)
def test_can_archive_package_with_force(self): pkg = self.create_package()[0] output = self.create_file() self.assertTrue(os.path.exists(output)) dump_package_archive(pkg, output, force=True) self.verify_archive(output)
def test_cannot_archive_package_when_output_exists(self): pkg = self.create_package()[0] output = self.create_file() self.assertTrue(os.path.exists(output)) with self.assertRaises(FileExistsError): dump_package_archive(pkg, output)