Пример #1
0
    def test_redirects_to_pypi(self, db_session, dummy_request):

        url = pypi_url(pypi_base_url, 'source', 'foo', 'foo-1.2.tar.gz')
        dummy_request.matchdict = {'package': 'foo', 'kind': 'source',
                                   'letter': 'f', 'basename': 'foo-1.2.tar.gz'}
        dummy_request.path = url
        with patch('belt.views.get_package_from_pypi') as get_package:
            content = cStringIO.StringIO('GOT IT')
            get_package.expects_call().with_args(url).returns(content)
            response = download_package(dummy_request)
        assert 'GOT IT' == response.body
Пример #2
0
    def test_creates_file_record(self, db_session, dummy_request):

        url = pypi_url(pypi_base_url, 'source', 'foo', 'foo-1.2.tar.gz')
        dummy_request.matchdict = {'package': 'foo', 'kind': 'source',
                                   'letter': 'f', 'basename': 'foo-1.2.tar.gz'}
        dummy_request.path = url
        with patch('belt.views.get_package_from_pypi') as get_package:
            content = cStringIO.StringIO('Got it!')
            get_package.expects_call().with_args(url).returns(content)
            download_package(dummy_request)

        models.File.for_release('foo', '1.2')
Пример #3
0
    def test_returns_500_when_server_error(self, db_session, http, dummy_request):

        url = pypi_url(pypi_base_url, 'source', 'flake8', 'flake8-2.0.tar.gz')
        dummy_request.path = url
        dummy_request.matchdict = {'package': 'flake8', 'kind': 'source',
                                   'letter': 'f', 'basename': 'flake8-2.0.tar.gz'}

        with patch('belt.views.get_package_from_pypi') as get_package:
            err500 = urllib2.URLError('yikes!')
            get_package.expects_call().with_args(url).raises(err500)

            with py.test.raises(HTTPServerError):
                download_package(dummy_request)
Пример #4
0
    def test_returns_404_if_package_not_on_pypi(self, db_session, dummy_request):

        url = pypi_url(pypi_base_url, 'source', 'flake8', 'flake8-2.0.tar.gz')
        dummy_request.path = url
        dummy_request.matchdict = {'package': 'flake8', 'kind': 'source',
                                   'letter': 'f', 'basename': 'flake8-2.0.tar.gz'}

        with patch('belt.views.get_package_from_pypi') as get_package:
            err404 = urllib2.HTTPError(url, 404, 'Not Found', None, None)
            get_package.expects_call().with_args(url).raises(err404)

            with py.test.raises(HTTPNotFound):
                download_package(dummy_request)
Пример #5
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