Example #1
0
    def test_excludes_new_releases(self, tmpdir, db_session):
        from belt.refresh import outdated_releases

        pkg = tmpdir.join('foo-1.2.tar.gz')
        package = create_package(pkg, content=u'Short lived')
        db_session.add(package)
        db_session.flush()

        # in a search for releases that were last modified before 2010-01-01 we
        # trust that a newly created package's release won't be found
        releases = outdated_releases(db_session,
                                     last_modified_at=datetime.datetime(2010, 1, 1))
        assert 0 == len(releases)
Example #2
0
    def test_obtains_missing_file_from_pypi(self, tmpdir, db_session,
                                            dummy_request):

        pkg = tmpdir.join('foo-1.2.tar.gz')
        package = create_package(pkg, content=u'Short lived')

        # remove just the package file, not the record
        pkg.remove()
        db_session.add(package)
        db_session.flush()

        url = pypi_url(pypi_base_url, 'source', 'foo', 'foo-1.2.tar.gz')
        dummy_request.path = url
        dummy_request.matchdict = {'package': 'foo', 'kind': 'source',
                                   'letter': 'f', 'basename': 'foo-1.2.tar.gz'}
        with patch('belt.views.get_package_from_pypi') as get_package:
            get_package.expects_call().with_args(url).returns(cStringIO.StringIO('Got it!'))
            response = download_package(dummy_request)
        assert 'Got it!' == response.body
Example #3
0
    def test_returns_only_outdated_releases(self, tmpdir, db_session):
        from belt.refresh import outdated_releases

        pkg = tmpdir.join('bar-1.0.tar.gz')
        package = create_package(pkg, content=u'n/a')

        # a datetime for 1st release and a datetime for the point against which we
        # consider releases outdated and in need of refreshing
        first_release_date = Delorean(datetime.datetime(1978, 1, 1), u'UTC').datetime
        jan_1st = datetime.datetime(2010, 1, 1)

        # change the modified timestamp of the 1st release to be in the past.
        # Create a new release and trust that its modified stamp will be newer
        # than 2010-01-01
        rel, = package.releases
        rel.modified = first_release_date
        new_release = models.Release(version=u'1.3')
        package.releases.add(new_release)

        db_session.add(package)
        db_session.flush()

        releases = outdated_releases(db_session, last_modified_at=jan_1st)
        assert 1 == len(releases)