2011-08-30 03:38:59 +02:00
|
|
|
#! /usr/bin/env py.test
|
|
|
|
|
2015-09-17 19:58:22 +02:00
|
|
|
import contextlib
|
|
|
|
import glob
|
2015-09-16 23:54:41 +02:00
|
|
|
import logging
|
2015-09-17 19:58:22 +02:00
|
|
|
import os
|
2016-01-17 21:57:16 +01:00
|
|
|
from pypiserver import __main__, bottle
|
2015-09-17 19:58:22 +02:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import webtest
|
|
|
|
|
2016-01-17 21:57:16 +01:00
|
|
|
import test_core
|
2015-09-17 19:58:22 +02:00
|
|
|
|
2016-01-19 12:52:34 +01:00
|
|
|
try:
|
|
|
|
from html.parser import HTMLParser
|
|
|
|
except ImportError:
|
|
|
|
from HTMLParser import HTMLParser
|
|
|
|
|
2011-08-30 03:38:59 +02:00
|
|
|
|
2015-09-17 19:58:22 +02:00
|
|
|
# Enable logging to detect any problems with it
|
2014-11-15 02:37:40 +01:00
|
|
|
##
|
2015-09-15 19:53:59 +02:00
|
|
|
__main__.init_logging(level=logging.NOTSET)
|
2016-01-19 12:52:34 +01:00
|
|
|
hp = HTMLParser()
|
2012-04-07 23:10:49 +02:00
|
|
|
|
2015-09-17 19:58:22 +02:00
|
|
|
|
2012-11-26 22:25:30 +01:00
|
|
|
@pytest.fixture()
|
2012-12-02 01:15:18 +01:00
|
|
|
def _app(app):
|
|
|
|
return app.module
|
2012-04-07 23:10:49 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def app(tmpdir):
|
2012-04-07 23:10:49 +02:00
|
|
|
from pypiserver import app
|
2015-12-21 00:06:19 +01:00
|
|
|
return app(root=tmpdir.strpath, authenticated=[])
|
2011-08-30 03:38:59 +02:00
|
|
|
|
2012-04-03 22:49:47 +02:00
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def testapp(app):
|
|
|
|
return webtest.TestApp(app)
|
2012-04-03 22:49:47 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def root(tmpdir):
|
|
|
|
return tmpdir
|
2012-04-03 22:49:47 +02:00
|
|
|
|
2011-08-30 03:38:59 +02:00
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def priv(app):
|
|
|
|
b = bottle.Bottle()
|
|
|
|
b.mount("/priv/", app)
|
|
|
|
return b
|
2011-09-01 01:08:32 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def testpriv(priv):
|
|
|
|
return webtest.TestApp(priv)
|
2011-08-30 03:38:59 +02:00
|
|
|
|
|
|
|
|
2015-09-17 19:58:22 +02:00
|
|
|
@pytest.fixture(params=[" ", # Mustcontain test below fails when string is empty.
|
2015-09-16 23:54:41 +02:00
|
|
|
"Hey there!",
|
2015-02-23 01:45:35 +01:00
|
|
|
"<html><body>Hey there!</body></html>",
|
|
|
|
])
|
|
|
|
def welcome_file_no_vars(request, root):
|
|
|
|
wfile = root.join("testwelcome.html")
|
2015-02-23 02:19:58 +01:00
|
|
|
wfile.write(request.param)
|
2015-09-16 23:54:41 +02:00
|
|
|
|
2015-02-23 01:45:35 +01:00
|
|
|
return wfile
|
|
|
|
|
|
|
|
|
2015-09-16 23:54:41 +02:00
|
|
|
@pytest.fixture()
|
2015-02-23 01:45:35 +01:00
|
|
|
def welcome_file_all_vars(request, root):
|
2015-09-17 19:58:22 +02:00
|
|
|
msg = """
|
2015-02-23 01:45:35 +01:00
|
|
|
{{URL}}
|
|
|
|
{{VERSION}}
|
|
|
|
{{NUMPKGS}}
|
|
|
|
{{PACKAGES}}
|
|
|
|
{{SIMPLE}}
|
|
|
|
"""
|
|
|
|
wfile = root.join("testwelcome.html")
|
2015-02-23 02:19:58 +01:00
|
|
|
wfile.write(msg)
|
2015-09-16 23:54:41 +02:00
|
|
|
|
2015-02-23 01:45:35 +01:00
|
|
|
return wfile
|
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_root_count(root, testapp):
|
|
|
|
resp = testapp.get("/")
|
|
|
|
resp.mustcontain("PyPI compatible package index serving 0 packages")
|
2011-08-30 03:38:59 +02:00
|
|
|
root.join("Twisted-11.0.0.tar.bz2").write("")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/")
|
|
|
|
resp.mustcontain("PyPI compatible package index serving 1 packages")
|
2011-08-30 03:38:59 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_root_hostname(testapp):
|
|
|
|
resp = testapp.get("/", headers={"Host": "systemexit.de"})
|
|
|
|
resp.mustcontain("easy_install -i http://systemexit.de/simple/ PACKAGE")
|
|
|
|
# go("http://systemexit.de/")
|
2011-08-30 03:38:59 +02:00
|
|
|
|
|
|
|
|
2015-02-23 01:45:35 +01:00
|
|
|
def test_root_welcome_msg_no_vars(root, welcome_file_no_vars):
|
|
|
|
from pypiserver import app
|
|
|
|
app = app(root=root.strpath, welcome_file=welcome_file_no_vars.strpath)
|
|
|
|
testapp = webtest.TestApp(app)
|
|
|
|
resp = testapp.get("/")
|
|
|
|
from pypiserver import __version__ as pver
|
2015-02-23 02:19:58 +01:00
|
|
|
resp.mustcontain(welcome_file_no_vars.read(), no=pver)
|
2015-02-23 01:45:35 +01:00
|
|
|
|
2014-11-14 00:36:32 +01:00
|
|
|
|
2015-02-23 01:45:35 +01:00
|
|
|
def test_root_welcome_msg_all_vars(root, welcome_file_all_vars):
|
2014-11-14 00:36:32 +01:00
|
|
|
from pypiserver import app
|
2015-02-23 01:45:35 +01:00
|
|
|
app = app(root=root.strpath, welcome_file=welcome_file_all_vars.strpath)
|
2014-11-14 00:36:32 +01:00
|
|
|
testapp = webtest.TestApp(app)
|
|
|
|
resp = testapp.get("/")
|
2015-09-16 23:54:41 +02:00
|
|
|
|
2015-02-23 01:45:35 +01:00
|
|
|
from pypiserver import __version__ as pver
|
|
|
|
resp.mustcontain(pver)
|
|
|
|
|
2014-11-14 00:36:32 +01:00
|
|
|
|
2015-02-21 00:34:37 +01:00
|
|
|
def test_root_welcome_msg_antiXSS(testapp):
|
2015-02-23 01:45:35 +01:00
|
|
|
"""https://github.com/pypiserver/pypiserver/issues/77"""
|
2015-09-17 19:58:22 +02:00
|
|
|
resp = testapp.get(
|
|
|
|
"/?<alert>Red</alert>", headers={"Host": "somehost.org"})
|
2015-02-21 00:34:37 +01:00
|
|
|
resp.mustcontain("alert", "somehost.org", no="<alert>")
|
2014-11-14 00:36:32 +01:00
|
|
|
|
2015-02-23 01:45:35 +01:00
|
|
|
|
|
|
|
def test_root_remove_not_found_msg_antiXSS(testapp):
|
|
|
|
"""https://github.com/pypiserver/pypiserver/issues/77"""
|
|
|
|
resp = testapp.post("/", expect_errors=True,
|
|
|
|
headers={"Host": "somehost.org"},
|
|
|
|
params={':action': 'remove_pkg',
|
|
|
|
'name': '<alert>Red</alert>',
|
2015-09-17 19:58:22 +02:00
|
|
|
'version': '1.1.1'})
|
2015-02-23 01:45:35 +01:00
|
|
|
resp.mustcontain("alert", "somehost.org", no="<alert>")
|
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_packages_empty(testapp):
|
|
|
|
resp = testapp.get("/packages")
|
|
|
|
assert len(resp.html("a")) == 0
|
2011-08-31 21:22:52 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_favicon(testapp):
|
|
|
|
testapp.get("/favicon.ico", status=404)
|
2011-08-31 21:22:52 +02:00
|
|
|
|
2011-08-31 22:00:09 +02:00
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_fallback(root, _app, testapp):
|
2012-04-07 22:30:54 +02:00
|
|
|
assert _app.config.redirect_to_fallback
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/pypiserver/", status=302)
|
2015-09-17 19:58:22 +02:00
|
|
|
assert resp.headers[
|
|
|
|
"Location"] == "http://pypi.python.org/simple/pypiserver/"
|
2011-08-31 22:00:09 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_no_fallback(root, _app, testapp):
|
2012-04-07 22:30:54 +02:00
|
|
|
_app.config.redirect_to_fallback = False
|
2012-12-02 01:15:18 +01:00
|
|
|
testapp.get("/simple/pypiserver/", status=404)
|
2011-09-01 00:07:40 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_serve_no_dotfiles(root, testapp):
|
2011-09-01 00:07:40 +02:00
|
|
|
root.join(".foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
testapp.get("/packages/.foo-1.0.zip", status=404)
|
2011-09-01 00:07:40 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_packages_list_no_dotfiles(root, testapp):
|
2011-09-01 00:07:40 +02:00
|
|
|
root.join(".foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/packages/")
|
|
|
|
assert "foo" not in resp
|
2011-09-01 00:07:40 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_list_no_dotfiles(root, testapp):
|
2011-09-01 00:07:40 +02:00
|
|
|
root.join(".foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert "foo" not in resp
|
2011-09-01 00:07:40 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_list_no_dotfiles2(root, testapp):
|
2011-09-01 00:07:40 +02:00
|
|
|
root.join(".foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert resp.html("a") == []
|
2011-09-01 00:19:14 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_serve_no_dotdir(root, testapp):
|
2011-10-07 20:31:51 +02:00
|
|
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
testapp.get("/packages/.subdir/foo-1.0.zip", status=404)
|
2011-10-07 20:31:51 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_packages_list_no_dotdir(root, testapp):
|
2011-10-07 20:31:51 +02:00
|
|
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/packages/")
|
|
|
|
assert "foo" not in resp
|
2011-10-07 20:31:51 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_list_no_dotdir(root, testapp):
|
2011-10-07 20:31:51 +02:00
|
|
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert "foo" not in resp
|
2011-10-07 20:31:51 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_list_no_dotdir2(root, testapp):
|
2011-10-07 20:31:51 +02:00
|
|
|
root.mkdir(".subdir").join("foo-1.0.zip").write("secret")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/foo/")
|
|
|
|
assert resp.html("a") == []
|
2011-10-07 20:31:51 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_index(root, testapp):
|
2011-09-01 00:19:14 +02:00
|
|
|
root.join("foobar-1.0.zip").write("")
|
|
|
|
root.join("foobar-1.1.zip").write("")
|
|
|
|
root.join("foobarbaz-1.1.zip").write("")
|
|
|
|
root.join("foobar.baz-1.1.zip").write("")
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/foobar")
|
|
|
|
assert len(resp.html("a")) == 2
|
2011-09-01 00:19:14 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_index_list(root, testapp):
|
2011-09-01 00:19:14 +02:00
|
|
|
root.join("foobar-1.0.zip").write("")
|
|
|
|
root.join("foobar-1.1.zip").write("")
|
|
|
|
root.join("foobarbaz-1.1.zip").write("")
|
|
|
|
root.join("foobar.baz-1.1.zip").write("")
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert len(resp.html("a")) == 3
|
2011-09-01 00:19:14 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_simple_index_case(root, testapp):
|
2011-09-01 00:19:14 +02:00
|
|
|
root.join("FooBar-1.0.zip").write("")
|
|
|
|
root.join("FooBar-1.1.zip").write("")
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testapp.get("/simple/foobar")
|
|
|
|
assert len(resp.html("a")) == 2
|
2012-04-03 22:49:47 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_nonroot_root(testpriv):
|
|
|
|
resp = testpriv.get("/priv/", headers={"Host": "nonroot"})
|
|
|
|
resp.mustcontain("easy_install -i http://nonroot/priv/simple/ PACKAGE")
|
2012-04-03 22:49:47 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_nonroot_simple_index(root, testpriv):
|
2012-04-03 22:49:47 +02:00
|
|
|
root.join("foobar-1.0.zip").write("")
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
for path in ["/priv/simple/foobar",
|
2015-09-17 19:58:22 +02:00
|
|
|
"/priv/simple/foobar/"]:
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testpriv.get(path)
|
|
|
|
links = resp.html("a")
|
2012-04-03 22:49:47 +02:00
|
|
|
assert len(links) == 1
|
2015-12-20 00:42:44 +01:00
|
|
|
assert links[0]["href"].startswith("/priv/packages/foobar-1.0.zip#")
|
2012-04-03 22:49:47 +02:00
|
|
|
|
|
|
|
|
2012-12-02 01:15:18 +01:00
|
|
|
def test_nonroot_simple_packages(root, testpriv):
|
2012-04-03 22:49:47 +02:00
|
|
|
root.join("foobar-1.0.zip").write("123")
|
2012-12-02 01:15:18 +01:00
|
|
|
for path in ["/priv/packages",
|
2015-09-17 19:58:22 +02:00
|
|
|
"/priv/packages/"]:
|
2012-12-02 01:15:18 +01:00
|
|
|
resp = testpriv.get(path)
|
|
|
|
links = resp.html("a")
|
2012-04-03 22:49:47 +02:00
|
|
|
assert len(links) == 1
|
2015-12-20 00:42:44 +01:00
|
|
|
assert links[0]["href"].startswith("/priv/packages/foobar-1.0.zip#")
|
2012-12-02 23:07:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_root_no_relative_paths(testpriv):
|
2015-02-27 23:02:07 +01:00
|
|
|
"""https://github.com/pypiserver/pypiserver/issues/25"""
|
2012-12-02 23:07:48 +01:00
|
|
|
resp = testpriv.get("/priv/")
|
|
|
|
hrefs = [x["href"] for x in resp.html("a")]
|
2015-09-17 19:58:22 +02:00
|
|
|
assert hrefs == ['/priv/packages/', '/priv/simple/',
|
|
|
|
'http://pypi.python.org/pypi/pypiserver']
|
2013-04-02 01:49:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_simple_index_list_no_duplicates(root, testapp):
|
|
|
|
root.join("foo-bar-1.0.tar.gz").write("")
|
|
|
|
root.join("foo_bar-1.0-py2.7.egg").write("")
|
|
|
|
|
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert len(resp.html("a")) == 1
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_index_list_name_with_underscore(root, testapp):
|
|
|
|
root.join("foo_bar-1.0.tar.gz").write("")
|
|
|
|
root.join("foo_bar-1.0-py2.7.egg").write("")
|
|
|
|
|
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert len(resp.html("a")) == 1
|
|
|
|
hrefs = [x["href"] for x in resp.html("a")]
|
|
|
|
assert hrefs == ["foo_bar/"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_simple_index_egg_and_tarball(root, testapp):
|
|
|
|
root.join("foo-bar-1.0.tar.gz").write("")
|
|
|
|
root.join("foo_bar-1.0-py2.7.egg").write("")
|
|
|
|
|
|
|
|
resp = testapp.get("/simple/foo-bar")
|
|
|
|
assert len(resp.html("a")) == 2
|
2013-04-02 22:03:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_simple_index_list_name_with_underscore_no_egg(root, testapp):
|
|
|
|
root.join("foo_bar-1.0.tar.gz").write("")
|
|
|
|
root.join("foo-bar-1.1.tar.gz").write("")
|
|
|
|
|
|
|
|
resp = testapp.get("/simple/")
|
|
|
|
assert len(resp.html("a")) == 2
|
|
|
|
hrefs = set([x["href"] for x in resp.html("a")])
|
|
|
|
assert hrefs == set(["foo_bar/", "foo-bar/"])
|
2015-01-10 18:18:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_no_cache_control_set(root, _app, testapp):
|
|
|
|
assert not _app.config.cache_control
|
|
|
|
root.join("foo_bar-1.0.tar.gz").write("")
|
|
|
|
resp = testapp.get("/packages/foo_bar-1.0.tar.gz")
|
|
|
|
assert "Cache-Control" not in resp.headers
|
|
|
|
|
|
|
|
|
|
|
|
def test_cache_control_set(root):
|
|
|
|
from pypiserver import app
|
|
|
|
AGE = 86400
|
|
|
|
app_with_cache = webtest.TestApp(app(root=root.strpath, cache_control=AGE))
|
|
|
|
root.join("foo_bar-1.0.tar.gz").write("")
|
|
|
|
resp = app_with_cache.get("/packages/foo_bar-1.0.tar.gz")
|
|
|
|
assert "Cache-Control" in resp.headers
|
2015-02-21 00:34:37 +01:00
|
|
|
assert resp.headers["Cache-Control"] == 'public, max-age=%s' % AGE
|
2016-01-17 21:57:16 +01:00
|
|
|
|
|
|
|
def test_upload_noAction(root, testapp):
|
|
|
|
resp = testapp.post("/", expect_errors=1)
|
|
|
|
assert resp.status == '400 Bad Request'
|
2016-01-19 12:52:34 +01:00
|
|
|
assert "Missing ':action' field!" in hp.unescape(resp.text)
|
2016-01-17 21:57:16 +01:00
|
|
|
|
|
|
|
def test_upload_badAction(root, testapp):
|
|
|
|
resp = testapp.post("/", params={':action': 'BAD'}, expect_errors=1)
|
|
|
|
assert resp.status == '400 Bad Request'
|
2016-01-19 12:52:34 +01:00
|
|
|
assert "Unsupported ':action' field: BAD" in hp.unescape(resp.text)
|
2016-01-17 21:57:16 +01:00
|
|
|
|
2016-01-19 13:35:41 +01:00
|
|
|
@pytest.mark.parametrize(("package"), [f[0]
|
|
|
|
for f in test_core.files
|
|
|
|
if f[1] and '/' not in f[0]])
|
2016-01-17 21:57:16 +01:00
|
|
|
def test_upload(package, root, testapp):
|
|
|
|
resp = testapp.post("/", params={':action': 'file_upload'},
|
|
|
|
upload_files=[('content', package, b'')])
|
|
|
|
assert resp.status_int == 200
|
|
|
|
uploaded_pkgs = [f.basename for f in root.listdir()]
|
|
|
|
assert len(uploaded_pkgs) == 1
|
|
|
|
assert uploaded_pkgs[0].lower() == package.lower()
|
|
|
|
|
2016-01-19 18:46:51 +01:00
|
|
|
@pytest.mark.parametrize(("package"), [f[0]
|
|
|
|
for f in test_core.files
|
|
|
|
if f[1] and '/' not in f[0]])
|
|
|
|
def test_upload_with_signature(package, root, testapp):
|
|
|
|
resp = testapp.post("/", params={':action': 'file_upload'},
|
|
|
|
upload_files=[
|
|
|
|
('content', package, b''),
|
|
|
|
('gpg_signature', '%s.asc' % package, b'')])
|
|
|
|
assert resp.status_int == 200
|
2016-04-21 17:08:18 +02:00
|
|
|
uploaded_pkgs = [f.basename.lower() for f in root.listdir()]
|
2016-01-19 18:46:51 +01:00
|
|
|
assert len(uploaded_pkgs) == 2
|
2016-04-21 17:08:18 +02:00
|
|
|
assert package.lower() in uploaded_pkgs
|
|
|
|
assert '%s.asc' % package.lower() in uploaded_pkgs
|
2016-01-19 18:46:51 +01:00
|
|
|
|
2016-01-17 21:57:16 +01:00
|
|
|
@pytest.mark.parametrize(("package"), [
|
|
|
|
f[0] for f in test_core.files
|
|
|
|
if f[1] is None])
|
|
|
|
def test_upload_badFilename(package, root, testapp):
|
|
|
|
resp = testapp.post("/", params={':action': 'file_upload'},
|
|
|
|
upload_files=[('content', package, b'')],
|
|
|
|
expect_errors=1)
|
|
|
|
assert resp.status == '400 Bad Request'
|
2016-01-19 12:52:34 +01:00
|
|
|
assert "Bad filename: %s" % package in resp.text
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(("name", "version"), [
|
|
|
|
(None, None),
|
|
|
|
(None, ''),
|
|
|
|
('', None),
|
|
|
|
(None, '1'),
|
|
|
|
('pkg', None),
|
|
|
|
('', '1'),
|
|
|
|
('pkg', ''),
|
|
|
|
])
|
|
|
|
def test_remove_pkg_missingNaveVersion(name, version, root, testapp):
|
|
|
|
msg = "Missing 'name'/'version' fields: name=%s, version=%s"
|
|
|
|
params = {':action': 'remove_pkg', 'name': name, 'version': version}
|
|
|
|
params = dict((k, v) for k,v in params.items() if v is not None)
|
|
|
|
resp = testapp.post("/", expect_errors=1, params=params)
|
|
|
|
|
2016-01-17 21:57:16 +01:00
|
|
|
assert resp.status == '400 Bad Request'
|
2016-01-19 12:52:34 +01:00
|
|
|
assert msg %(name, version) in hp.unescape(resp.text)
|
2016-01-17 21:57:16 +01:00
|
|
|
|
|
|
|
def test_remove_pkg_notFound(root, testapp):
|
|
|
|
resp = testapp.post("/", expect_errors=1,
|
|
|
|
params={
|
|
|
|
':action': 'remove_pkg',
|
|
|
|
'name': 'foo',
|
|
|
|
'version': '123',
|
|
|
|
})
|
|
|
|
assert resp.status == '404 Not Found'
|
2016-01-19 12:52:34 +01:00
|
|
|
assert "foo (123) not found" in hp.unescape(resp.text)
|
2016-01-17 21:57:16 +01:00
|
|
|
|
|
|
|
@pytest.mark.xfail()
|
|
|
|
def test_remove_pkg(root, testapp):
|
2016-04-21 17:08:18 +02:00
|
|
|
assert 0
|