forked from github.com/pypiserver
use webtest instead of twill
webtest works with python 3. we now also get rid of paste and pastedeploy and use bottle.Bottle.mount instead.
This commit is contained in:
parent
2f2eeee593
commit
6989d316c5
@ -1,7 +1,6 @@
|
|||||||
include .gitignore
|
include .gitignore
|
||||||
include MANIFEST.in
|
include MANIFEST.in
|
||||||
include README.rst
|
include README.rst
|
||||||
include conftest.py
|
|
||||||
include gen-standalone.py
|
include gen-standalone.py
|
||||||
include pypi-server
|
include pypi-server
|
||||||
include pypi-server-in.py
|
include pypi-server-in.py
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import sys
|
|
||||||
import httplib
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
|
||||||
if hasattr(sys, "pypy_version_info"):
|
|
||||||
# mechanize (as included by twill) calls this
|
|
||||||
httplib.HTTPResponse._decref_socketios = lambda self: None
|
|
@ -1,238 +1,170 @@
|
|||||||
#! /usr/bin/env py.test
|
#! /usr/bin/env py.test
|
||||||
|
|
||||||
import twill
|
|
||||||
from twill.commands import go, code, show, find, reload, showlinks, notfind
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
try:
|
|
||||||
from paste.deploy import loadapp
|
|
||||||
except ImportError:
|
|
||||||
loadapp = None
|
|
||||||
|
|
||||||
from pypiserver import core # do no remove. needed for bottle
|
from pypiserver import core # do no remove. needed for bottle
|
||||||
import bottle
|
import pytest, bottle, webtest
|
||||||
|
|
||||||
fallback_app = bottle.Bottle()
|
|
||||||
|
|
||||||
|
|
||||||
@fallback_app.route("path#.*#")
|
|
||||||
def pypi_notfound(path):
|
|
||||||
return bottle.HTTPError(404)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def root(request, env):
|
def _app(app):
|
||||||
return env["root"]
|
return app.module
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture
|
||||||
def _app(request, env):
|
def app(tmpdir):
|
||||||
return env["_app"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
|
||||||
def env(request, tmpdir):
|
|
||||||
from pypiserver import app
|
from pypiserver import app
|
||||||
a = app(root=tmpdir.strpath)
|
return app(root=tmpdir.strpath)
|
||||||
|
|
||||||
if loadapp:
|
|
||||||
pini = tmpdir.join(".paste.ini")
|
|
||||||
pini.write("""
|
|
||||||
[composite:main]
|
|
||||||
use = egg:Paste#urlmap
|
|
||||||
/priv/ = private
|
|
||||||
|
|
||||||
[app:private]
|
|
||||||
paste.app_factory = pypiserver:paste_app_factory
|
|
||||||
root = %s
|
|
||||||
|
|
||||||
[server:main]
|
|
||||||
use = egg:gunicorn#main
|
|
||||||
host = 0.0.0.0
|
|
||||||
port = 8001
|
|
||||||
workers = 5
|
|
||||||
accesslog = -
|
|
||||||
""" % tmpdir)
|
|
||||||
|
|
||||||
twill.add_wsgi_intercept("nonroot", 80, lambda: loadapp("config:%s" % pini))
|
|
||||||
|
|
||||||
twill.add_wsgi_intercept("localhost", 8080, lambda: a)
|
|
||||||
twill.add_wsgi_intercept("systemexit.de", 80, lambda: a)
|
|
||||||
twill.add_wsgi_intercept("pypi.python.org", 80, lambda: fallback_app)
|
|
||||||
|
|
||||||
def cleanup():
|
|
||||||
twill.remove_wsgi_intercept("localhost", 8080)
|
|
||||||
twill.remove_wsgi_intercept("systemexit.de", 80)
|
|
||||||
twill.remove_wsgi_intercept("pypi.python.org", 80)
|
|
||||||
if loadapp:
|
|
||||||
twill.remove_wsgi_intercept("nonroot", 80)
|
|
||||||
|
|
||||||
request.addfinalizer(cleanup)
|
|
||||||
|
|
||||||
go("http://localhost:8080/")
|
|
||||||
return dict(root=tmpdir, app=a, _app=a.module)
|
|
||||||
|
|
||||||
|
|
||||||
def test_root_count(root):
|
@pytest.fixture
|
||||||
go("/")
|
def testapp(app):
|
||||||
show()
|
return webtest.TestApp(app)
|
||||||
code(200)
|
|
||||||
find("PyPI compatible package index serving 0 packages")
|
|
||||||
showlinks()
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def root(tmpdir):
|
||||||
|
return tmpdir
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def priv(app):
|
||||||
|
b = bottle.Bottle()
|
||||||
|
b.mount("/priv/", app)
|
||||||
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def testpriv(priv):
|
||||||
|
return webtest.TestApp(priv)
|
||||||
|
|
||||||
|
|
||||||
|
def test_root_count(root, testapp):
|
||||||
|
resp = testapp.get("/")
|
||||||
|
resp.mustcontain("PyPI compatible package index serving 0 packages")
|
||||||
root.join("Twisted-11.0.0.tar.bz2").write("")
|
root.join("Twisted-11.0.0.tar.bz2").write("")
|
||||||
reload()
|
resp = testapp.get("/")
|
||||||
show()
|
resp.mustcontain("PyPI compatible package index serving 1 packages")
|
||||||
find("PyPI compatible package index serving 1 packages")
|
|
||||||
|
|
||||||
|
|
||||||
def test_root_hostname(root):
|
def test_root_hostname(testapp):
|
||||||
go("http://systemexit.de/")
|
resp = testapp.get("/", headers={"Host": "systemexit.de"})
|
||||||
find("easy_install -i http://systemexit.de/simple/ PACKAGE")
|
resp.mustcontain("easy_install -i http://systemexit.de/simple/ PACKAGE")
|
||||||
|
# go("http://systemexit.de/")
|
||||||
|
|
||||||
|
|
||||||
def test_packages_empty(root):
|
def test_packages_empty(testapp):
|
||||||
go("/packages")
|
resp = testapp.get("/packages")
|
||||||
show()
|
assert len(resp.html("a")) == 0
|
||||||
code(200)
|
|
||||||
assert list(showlinks()) == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_favicon(root):
|
def test_favicon(testapp):
|
||||||
final_url = go("/favicon.ico")
|
testapp.get("/favicon.ico", status=404)
|
||||||
show()
|
|
||||||
print "FINAL_URL:", final_url
|
|
||||||
assert final_url == "http://localhost:8080/favicon.ico"
|
|
||||||
code(404)
|
|
||||||
|
|
||||||
|
|
||||||
def test_fallback(root, _app):
|
def test_fallback(root, _app, testapp):
|
||||||
assert _app.config.redirect_to_fallback
|
assert _app.config.redirect_to_fallback
|
||||||
final_url = go("/simple/pypiserver/")
|
resp = testapp.get("/simple/pypiserver/", status=302)
|
||||||
assert final_url == "http://pypi.python.org/simple/pypiserver/"
|
assert resp.headers["Location"] == "http://pypi.python.org/simple/pypiserver/"
|
||||||
|
|
||||||
|
|
||||||
def test_no_fallback(root, _app):
|
def test_no_fallback(root, _app, testapp):
|
||||||
_app.config.redirect_to_fallback = False
|
_app.config.redirect_to_fallback = False
|
||||||
final_url = go("/simple/pypiserver/")
|
testapp.get("/simple/pypiserver/", status=404)
|
||||||
assert final_url == "http://localhost:8080/simple/pypiserver/"
|
|
||||||
code(404)
|
|
||||||
|
|
||||||
|
|
||||||
def test_serve_no_dotfiles(root):
|
def test_serve_no_dotfiles(root, testapp):
|
||||||
root.join(".foo-1.0.zip").write("secret")
|
root.join(".foo-1.0.zip").write("secret")
|
||||||
go("/packages/.foo-1.0.zip")
|
testapp.get("/packages/.foo-1.0.zip", status=404)
|
||||||
show()
|
|
||||||
code(404)
|
|
||||||
|
|
||||||
|
|
||||||
def test_packages_list_no_dotfiles(root):
|
def test_packages_list_no_dotfiles(root, testapp):
|
||||||
root.join(".foo-1.0.zip").write("secret")
|
root.join(".foo-1.0.zip").write("secret")
|
||||||
go("/packages/")
|
resp = testapp.get("/packages/")
|
||||||
notfind("foo")
|
assert "foo" not in resp
|
||||||
|
|
||||||
|
|
||||||
def test_simple_list_no_dotfiles(root):
|
def test_simple_list_no_dotfiles(root, testapp):
|
||||||
root.join(".foo-1.0.zip").write("secret")
|
root.join(".foo-1.0.zip").write("secret")
|
||||||
go("/simple/")
|
resp = testapp.get("/simple/")
|
||||||
notfind("foo")
|
assert "foo" not in resp
|
||||||
|
|
||||||
|
|
||||||
def test_simple_list_no_dotfiles2(root):
|
def test_simple_list_no_dotfiles2(root, testapp):
|
||||||
root.join(".foo-1.0.zip").write("secret")
|
root.join(".foo-1.0.zip").write("secret")
|
||||||
go("/simple/.foo/")
|
resp = testapp.get("/simple/")
|
||||||
assert list(showlinks()) == []
|
assert resp.html("a") == []
|
||||||
|
|
||||||
|
|
||||||
def test_serve_no_dotdir(root):
|
def test_serve_no_dotdir(root, testapp):
|
||||||
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
||||||
go("/packages/.subdir/foo-1.0.zip")
|
testapp.get("/packages/.subdir/foo-1.0.zip", status=404)
|
||||||
code(404)
|
|
||||||
|
|
||||||
|
|
||||||
def test_packages_list_no_dotdir(root):
|
def test_packages_list_no_dotdir(root, testapp):
|
||||||
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
||||||
go("/packages/")
|
resp = testapp.get("/packages/")
|
||||||
show()
|
assert "foo" not in resp
|
||||||
notfind("foo")
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple_list_no_dotdir(root):
|
def test_simple_list_no_dotdir(root, testapp):
|
||||||
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
||||||
go("/simple/")
|
resp = testapp.get("/simple/")
|
||||||
show()
|
assert "foo" not in resp
|
||||||
notfind("foo")
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple_list_no_dotdir2(root):
|
def test_simple_list_no_dotdir2(root, testapp):
|
||||||
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
||||||
go("/simple/foo/")
|
resp = testapp.get("/simple/foo/")
|
||||||
show()
|
assert resp.html("a") == []
|
||||||
assert list(showlinks()) == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple_index(root):
|
def test_simple_index(root, testapp):
|
||||||
root.join("foobar-1.0.zip").write("")
|
root.join("foobar-1.0.zip").write("")
|
||||||
root.join("foobar-1.1.zip").write("")
|
root.join("foobar-1.1.zip").write("")
|
||||||
root.join("foobarbaz-1.1.zip").write("")
|
root.join("foobarbaz-1.1.zip").write("")
|
||||||
root.join("foobar.baz-1.1.zip").write("")
|
root.join("foobar.baz-1.1.zip").write("")
|
||||||
|
|
||||||
go("/simple/foobar")
|
resp = testapp.get("/simple/foobar")
|
||||||
show()
|
assert len(resp.html("a")) == 2
|
||||||
links = list(showlinks())
|
|
||||||
assert len(links) == 2
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple_index_list(root):
|
def test_simple_index_list(root, testapp):
|
||||||
root.join("foobar-1.0.zip").write("")
|
root.join("foobar-1.0.zip").write("")
|
||||||
root.join("foobar-1.1.zip").write("")
|
root.join("foobar-1.1.zip").write("")
|
||||||
root.join("foobarbaz-1.1.zip").write("")
|
root.join("foobarbaz-1.1.zip").write("")
|
||||||
root.join("foobar.baz-1.1.zip").write("")
|
root.join("foobar.baz-1.1.zip").write("")
|
||||||
|
|
||||||
go("/simple/")
|
resp = testapp.get("/simple/")
|
||||||
show()
|
assert len(resp.html("a")) == 3
|
||||||
links = list(showlinks())
|
|
||||||
assert len(links) == 3
|
|
||||||
|
|
||||||
|
|
||||||
def test_simple_index_case(root):
|
def test_simple_index_case(root, testapp):
|
||||||
root.join("FooBar-1.0.zip").write("")
|
root.join("FooBar-1.0.zip").write("")
|
||||||
root.join("FooBar-1.1.zip").write("")
|
root.join("FooBar-1.1.zip").write("")
|
||||||
|
resp = testapp.get("/simple/foobar")
|
||||||
go("/simple/foobar")
|
assert len(resp.html("a")) == 2
|
||||||
show()
|
|
||||||
links = list(showlinks())
|
|
||||||
assert len(links) == 2
|
|
||||||
|
|
||||||
need_paste = pytest.mark.skipif("loadapp is None")
|
|
||||||
|
|
||||||
|
|
||||||
@need_paste
|
def test_nonroot_root(testpriv):
|
||||||
def test_nonroot_root(root):
|
resp = testpriv.get("/priv/", headers={"Host": "nonroot"})
|
||||||
go("http://nonroot/priv/")
|
resp.mustcontain("easy_install -i http://nonroot/priv/simple/ PACKAGE")
|
||||||
find("easy_install -i http://nonroot/priv/simple/ PACKAGE")
|
|
||||||
|
|
||||||
|
|
||||||
@need_paste
|
def test_nonroot_simple_index(root, testpriv):
|
||||||
def test_nonroot_simple_index(root):
|
|
||||||
root.join("foobar-1.0.zip").write("")
|
root.join("foobar-1.0.zip").write("")
|
||||||
|
|
||||||
for url in ["http://nonroot/priv/simple/foobar",
|
for path in ["/priv/simple/foobar",
|
||||||
"http://nonroot/priv/simple/foobar/"]:
|
"/priv/simple/foobar/"]:
|
||||||
go(url)
|
resp = testpriv.get(path)
|
||||||
show()
|
links = resp.html("a")
|
||||||
links = list(showlinks())
|
|
||||||
assert len(links) == 1
|
assert len(links) == 1
|
||||||
assert links[0].url == "/priv/packages/foobar-1.0.zip"
|
assert links[0]["href"] == "/priv/packages/foobar-1.0.zip"
|
||||||
|
|
||||||
|
|
||||||
@need_paste
|
def test_nonroot_simple_packages(root, testpriv):
|
||||||
def test_nonroot_simple_packages(root):
|
|
||||||
root.join("foobar-1.0.zip").write("123")
|
root.join("foobar-1.0.zip").write("123")
|
||||||
for url in ["http://nonroot/priv/packages",
|
for path in ["/priv/packages",
|
||||||
"http://nonroot/priv/packages/"]:
|
"/priv/packages/"]:
|
||||||
go(url)
|
resp = testpriv.get(path)
|
||||||
show()
|
links = resp.html("a")
|
||||||
links = list(showlinks())
|
|
||||||
assert len(links) == 1
|
assert len(links) == 1
|
||||||
assert links[0].url == "/priv/packages/foobar-1.0.zip"
|
assert links[0]["href"] == "/priv/packages/foobar-1.0.zip"
|
||||||
|
8
tox.ini
8
tox.ini
@ -1,9 +1,9 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = py25,py26,py27
|
envlist = py25,py26,py27
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps=pytest>=2.3
|
deps=pytest>=2.3
|
||||||
twill
|
webtest
|
||||||
paste
|
beautifulsoup4
|
||||||
pastedeploy
|
commands=py.test []
|
||||||
commands=py.test
|
|
||||||
sitepackages=False
|
sitepackages=False
|
||||||
|
Loading…
Reference in New Issue
Block a user