Add test_server TCs with twine<-->real process.

+ TC for #82 uploading `dentodeps` package with 200 deps.
This commit is contained in:
Kostis Anagnostopoulos 2015-09-17 19:58:22 +02:00
parent cda0fad7a9
commit e32ca3425b
8 changed files with 99 additions and 14 deletions

3
.gitignore vendored

@ -17,8 +17,7 @@ ID
__pycache__/
/build/
/dist/
/*.egg
/.eggs
/*.egg*
/MANIFEST
/README.html
/pypi-server-standalone.py

@ -4,7 +4,7 @@ import sys
from setuptools import setup
tests_require = ['pytest']
tests_require = ['pytest', 'twine']
if sys.version_info >= (3, 0):
exec("def do_exec(co, loc): exec(co, loc)\n")
else:

4
tests/centodeps/.gitignore vendored Normal file

@ -0,0 +1,4 @@
/wheelhouse
/build
/*egg*

Binary file not shown.

15
tests/centodeps/setup.py Normal file

@ -0,0 +1,15 @@
## A test-distribution to check if
# bottle supports uploading 100's of packages,
# see: https://github.com/pypiserver/pypiserver/issues/82
#
# Has been run once `pip wheel .`, just to generate:
# ./wheelhouse/centodeps-0.0.0-cp34-none-win_amd64.whl
#
from setuptools import setup
setup(
name='centodeps',
install_requires=['a==1.0'] * 200,
options={
'bdist_wheel': {'universal': True},
},
)

@ -1,13 +1,22 @@
#! /usr/bin/env py.test
from pypiserver import __main__, bottle
import pytest, webtest
import contextlib
import glob
import logging
import os
import subprocess
## Enable logging to detect any problems with it
import pytest
import webtest
from pypiserver import __main__, bottle
# Enable logging to detect any problems with it
##
__main__.init_logging(level=logging.NOTSET)
@pytest.fixture()
def _app(app):
return app.module
@ -41,7 +50,7 @@ def testpriv(priv):
return webtest.TestApp(priv)
@pytest.fixture(params=[" ", ## Mustcontain test below fails when string is empty.
@pytest.fixture(params=[" ", # Mustcontain test below fails when string is empty.
"Hey there!",
"<html><body>Hey there!</body></html>",
])
@ -54,7 +63,7 @@ def welcome_file_no_vars(request, root):
@pytest.fixture()
def welcome_file_all_vars(request, root):
msg ="""
msg = """
{{URL}}
{{VERSION}}
{{NUMPKGS}}
@ -102,7 +111,8 @@ def test_root_welcome_msg_all_vars(root, welcome_file_all_vars):
def test_root_welcome_msg_antiXSS(testapp):
"""https://github.com/pypiserver/pypiserver/issues/77"""
resp = testapp.get("/?<alert>Red</alert>", headers={"Host": "somehost.org"})
resp = testapp.get(
"/?<alert>Red</alert>", headers={"Host": "somehost.org"})
resp.mustcontain("alert", "somehost.org", no="<alert>")
@ -112,7 +122,7 @@ def test_root_remove_not_found_msg_antiXSS(testapp):
headers={"Host": "somehost.org"},
params={':action': 'remove_pkg',
'name': '<alert>Red</alert>',
'version':'1.1.1'})
'version': '1.1.1'})
resp.mustcontain("alert", "somehost.org", no="<alert>")
@ -128,7 +138,8 @@ def test_favicon(testapp):
def test_fallback(root, _app, testapp):
assert _app.config.redirect_to_fallback
resp = testapp.get("/simple/pypiserver/", status=302)
assert resp.headers["Location"] == "http://pypi.python.org/simple/pypiserver/"
assert resp.headers[
"Location"] == "http://pypi.python.org/simple/pypiserver/"
def test_no_fallback(root, _app, testapp):
@ -218,7 +229,7 @@ def test_nonroot_simple_index(root, testpriv):
root.join("foobar-1.0.zip").write("")
for path in ["/priv/simple/foobar",
"/priv/simple/foobar/"]:
"/priv/simple/foobar/"]:
resp = testpriv.get(path)
links = resp.html("a")
assert len(links) == 1
@ -228,7 +239,7 @@ def test_nonroot_simple_index(root, testpriv):
def test_nonroot_simple_packages(root, testpriv):
root.join("foobar-1.0.zip").write("123")
for path in ["/priv/packages",
"/priv/packages/"]:
"/priv/packages/"]:
resp = testpriv.get(path)
links = resp.html("a")
assert len(links) == 1
@ -239,7 +250,8 @@ def test_root_no_relative_paths(testpriv):
"""https://github.com/pypiserver/pypiserver/issues/25"""
resp = testpriv.get("/priv/")
hrefs = [x["href"] for x in resp.html("a")]
assert hrefs == ['/priv/packages/', '/priv/simple/', 'http://pypi.python.org/pypi/pypiserver']
assert hrefs == ['/priv/packages/', '/priv/simple/',
'http://pypi.python.org/pypi/pypiserver']
def test_simple_index_list_no_duplicates(root, testapp):

54
tests/test_server.py Normal file

@ -0,0 +1,54 @@
#! /usr/bin/env py.test
import contextlib
import subprocess
import time
from py import path # @UnresolvedImport
import pytest
@pytest.fixture
def packdir(tmpdir):
return tmpdir.mkdir("dists")
@contextlib.contextmanager
def server(packdir):
cmd = "python -m pypiserver.__main__ -P. -a. %s" % packdir
try:
proc = subprocess.Popen(
cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
yield proc
finally:
try:
proc.terminate()
time.sleep(1)
finally:
proc.kill()
def test_centodeps(packdir, monkeypatch):
from twine.commands import upload
pypirc_config = {"test": {"repository": "http://localhost:8080",
"username": 'a',
"password": 'a'
}
}
monkeypatch.setattr(upload, 'get_repository_from_config',
lambda *x: pypirc_config)
dist_path = path.local('tests/centodeps/wheelhouse/centodeps*.whl')
with server(packdir) as srv:
upload.upload([str(dist_path)], repository='test',
sign=None, identity=None,
username='a', password='a',
comment=None, sign_with=None)
time.sleep(1)
assert list(packdir.visit('centodeps*.whl'))
out = srv.communicate()
assert "serving on http:" in str(out[0])
assert "Listening on http:" in str(out[1])

@ -6,6 +6,7 @@ deps=pytest>=2.3
webtest
beautifulsoup4
mock
twine>=1.6.0
commands=py.test []
sitepackages=False