def test_getFilters(self):
        # test that getFilters() correctly extracts file patterns from
        # the database.

        ztm = self.layer.txn
        ztm.begin()

        evolution = getUtility(IProductSet).getByName('evolution')
        trunk = evolution.getSeries('trunk')
        trunk.releasefileglob = ('http://ftp.gnome.org/pub/GNOME/sources/'
                                 'evolution/2.7/evolution-*.tar.gz')
        ztm.commit()

        logging.basicConfig(level=logging.CRITICAL)
        prf = ProductReleaseFinder(ztm, logging.getLogger())
        # get the filters for evolution and firefox
        for product_name, filters in prf.getFilters():
            if product_name == 'evolution':
                evo_filters = filters

        self.assertEqual(len(evo_filters), 1)
        self.failUnless(isinstance(evo_filters[0], FilterPattern))
        self.assertEqual(evo_filters[0].key, 'trunk')
        self.assertEqual(evo_filters[0].base_url,
            'http://ftp.gnome.org/pub/GNOME/sources/evolution/2.7/')
        self.assertEqual(evo_filters[0].urlglob,
            'http://ftp.gnome.org/pub/GNOME/sources/evolution/2.7/'
            'evolution-*.tar.gz')
        self.failUnless(evo_filters[0].match(
            'http://ftp.gnome.org/pub/GNOME/sources/evolution/2.7/'
            'evolution-2.7.1.tar.gz'))
    def test_handleReleaseWithExistingRelease(self):
        # Test that handleRelease() can add a file release to an
        # existing ProductRelease.
        ztm = self.layer.txn

        # verify that a 2.1.6 release of evolution exists without any
        # files attached.
        evo = getUtility(IProductSet).getByName('evolution')
        trunk = evo.getSeries('trunk')
        release = trunk.getRelease('2.1.6')
        self.assertNotEqual(release, None)
        self.assertEqual(release.files.count(), 0)
        ztm.abort()

        logging.basicConfig(level=logging.CRITICAL)
        prf = ProductReleaseFinder(ztm, logging.getLogger())
        file_path, file_name = self.create_tarball('evolution-2.1.6.tar.gz')
        file_names = prf.getReleaseFileNames('evolution')
        prf.handleRelease('evolution', 'trunk', file_path, file_names)

        # verify that we now have files attached to the release:
        evo = getUtility(IProductSet).getByName('evolution')
        trunk = evo.getSeries('trunk')
        release = trunk.getRelease('2.1.6')
        self.assertEqual(release.files.count(), 1)
    def test_handleRelease(self):
        ztm = self.layer.txn
        logging.basicConfig(level=logging.CRITICAL)
        prf = ProductReleaseFinder(ztm, logging.getLogger())
        alt_file_name = 'evolution-42.0.orig.tar.bz2'
        file_path, file_name = self.create_tarball(
            'evolution-42.0.orig.tar.gz')
        file_names = set()
        prf.handleRelease('evolution', 'trunk', file_path, file_names)
        self.assertTrue(file_name in file_names)
        self.assertFalse(alt_file_name in file_names)

        # check to see that the release has been created
        evo = getUtility(IProductSet).getByName('evolution')
        trunk = evo.getSeries('trunk')
        release = trunk.getRelease('42.0')
        self.assertNotEqual(release, None)
        self.assertEqual(release.files.count(), 1)
        fileinfo = release.files[0]
        self.assertEqual(fileinfo.filetype, UpstreamFileType.CODETARBALL)
        self.assertEqual(fileinfo.libraryfile.filename, file_name)

        # verify that the fileinfo object is sane
        self.failUnless(verifyObject(IProductReleaseFile, fileinfo))
        for field in getFields(IProductReleaseFile).values():
            # XXX: BradCrittenden 2008-09-04 bug=264829:
            # Several interfaces have uploaded files as `Bytes` attributes but
            # then the values get converted to LibraryFileAlias objects.  The
            # Bytes._validate() method then fails.  As a work-around the
            # validate test is being disabled here for those fields.
            from zope.schema import Bytes
            if isinstance(field, Bytes):
                continue
            bound = field.bind(fileinfo)
            bound.validate(bound.get(fileinfo))
 def test_handleReleaseTwice(self):
     # Test that handleRelease() handles the case where a tarball
     # has already been attached to the ProductRelease.  We do this
     # by calling handleRelease() twice.
     ztm = self.layer.txn
     logging.basicConfig(level=logging.CRITICAL)
     prf = ProductReleaseFinder(ztm, logging.getLogger())
     file_path, file_name = self.create_tarball('evolution-42.0.tar.gz')
     file_names = prf.getReleaseFileNames('evolution')
     prf.handleRelease('evolution', 'trunk', file_path, file_names)
     prf.handleRelease('evolution', 'trunk', file_path, file_names)
     evo = getUtility(IProductSet).getByName('evolution')
     trunk = evo.getSeries('trunk')
     release = trunk.getRelease('42.0')
     self.assertEqual(release.files.count(), 1)
 def test_getReleaseFileNames(self):
     product = self.factory.makeProduct()
     series1 = self.factory.makeProductSeries(product=product)
     series2 = self.factory.makeProductSeries(product=product)
     self.factory.makeProductReleaseFile(
         productseries=series1, filename='foo-1.0.tar.gz')
     file2 = self.factory.makeProductReleaseFile(
         productseries=series2, filename='foo-2.0.tar.gz')
     self.factory.makeProductReleaseFile(
         productseries=series2, release=file2.productrelease,
         filename='foo-2.1.tar.gz')
     expected = set(['foo-1.0.tar.gz', 'foo-2.0.tar.gz', 'foo-2.1.tar.gz'])
     transaction.commit()
     prf = ProductReleaseFinder(self.layer.txn, logging.getLogger())
     found = prf.getReleaseFileNames(product.name)
     self.assertEqual(expected, found)
 def test_getFilters_ignore_obsolete(self):
     # Verify that obsolete series are ignnored.
     ztm = self.layer.txn
     ztm.begin()
     product = self.factory.makeProduct(name="bunny")
     active_series = product.getSeries('trunk')
     active_series.releasefileglob = 'http://eg.dom/bunny/trunk/*'
     obsolete_series = self.factory.makeProductSeries(
         product=product, name='rabbit')
     obsolete_series.releasefileglob = 'http://eg.dom/bunny/rabbit/*'
     obsolete_series.status = SeriesStatus.OBSOLETE
     ztm.commit()
     logging.basicConfig(level=logging.CRITICAL)
     prf = ProductReleaseFinder(ztm, logging.getLogger())
     product_filters = prf.getFilters()
     self.assertEqual(1, len(product_filters))
     found_product, filters = product_filters[0]
     self.assertEqual('bunny', found_product)
     self.assertEqual(1, len(filters))
     self.assertEqual(filters[0].key, 'trunk')
    def test_handleReleaseUnableToParseVersion(self):
        # Test that handleRelease() handles the case where a version can't be
        # parsed from the url given.
        ztm = self.layer.txn
        output = StringIO()
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        logger.addHandler(logging.StreamHandler(output))
        prf = ProductReleaseFinder(ztm, logger)

        # create a release tarball
        fp = open(os.path.join(
            self.release_root, 'evolution-42.0.tar.gz'), 'w')
        fp.write('foo')
        fp.close()

        url = self.release_url + '/evolution420.tar.gz'
        file_names = prf.getReleaseFileNames('evolution')
        prf.handleRelease('evolution', 'trunk', url, file_names)
        self.assertEqual(
            "Unable to parse version from %s\n" % url, output.getvalue())
 def test_handleReleaseTwice_multiple_series(self):
     # Series can have overlaping release file globs, but versions
     # are unique to a project. A file is uploaded to a release only
     # once, regardless of which series wants the upload.
     ztm = self.layer.txn
     logging.basicConfig(level=logging.CRITICAL)
     prf = ProductReleaseFinder(ztm, logging.getLogger())
     file_path, file_name = self.create_tarball('evolution-1.2.3.tar.gz')
     file_names = prf.getReleaseFileNames('evolution')
     prf.handleRelease('evolution', 'trunk', file_path, file_names)
     file_path, file_name = self.create_tarball('evolution-1.2.3.tar.gz')
     prf.handleRelease('evolution', '1.0', file_path, file_names)
     product = getUtility(IProductSet).getByName('evolution')
     release = product.getMilestone('1.2.3').product_release
     self.assertEqual(release.files.count(), 1)
 def test_handleRelease_alternate_verstion(self):
     """Verify that tar.gz and tar.bz2 versions are both uploaded."""
     ztm = self.layer.txn
     logging.basicConfig(level=logging.CRITICAL)
     prf = ProductReleaseFinder(ztm, logging.getLogger())
     file_path, file_name = self.create_tarball('evolution-45.0.tar.gz')
     alt_file_path, alt_file_name = self.create_tarball(
         'evolution-45.0.tar.bz2')
     file_names = prf.getReleaseFileNames('evolution')
     prf.handleRelease('evolution', 'trunk', file_path, file_names)
     prf.handleRelease('evolution', 'trunk', alt_file_path, file_names)
     evo = getUtility(IProductSet).getByName('evolution')
     trunk = evo.getSeries('trunk')
     release = trunk.getRelease('45.0')
     release_filenames = [file_info.libraryfile.filename
                          for file_info in release.files]
     self.assertEqual(len(release_filenames), 2)
     self.assertTrue(file_name in release_filenames)
     self.assertTrue(alt_file_name in release_filenames)
 def test_findReleases_permissions(self):
     switch_dbuser(config.productreleasefinder.dbuser)
     prf = ProductReleaseFinder(self.layer.txn, logging.getLogger())
     # Test that this raises no exceptions.
     prf.findReleases()
 def __init__(self):
     ProductReleaseFinder.__init__(self, None, None)
     self.seen_products = []
 def __init__(self, ztm, log):
     ProductReleaseFinder.__init__(self, ztm, log)
     self.seen_releases = []
 def main(self):
     prf = ProductReleaseFinder(self.txn, self.logger)
     prf.findReleases()
Example #14
0
 def main(self):
     prf = ProductReleaseFinder(self.txn, self.logger)
     prf.findReleases()