Compare commits

..

1 Commits

Author SHA1 Message Date
Sebastian Lohff 2db018a93e Initial tests 2019-02-12 21:12:10 +01:00
2 changed files with 9 additions and 16 deletions

View File

@ -12,7 +12,6 @@ setup(
url='http://seba-geek.de/stuff/servefile/',
author='Sebastian Lohff',
author_email='seba@someserver.de',
install_requires=['pyopenssl'],
scripts=['servefile'],
)

View File

@ -8,7 +8,6 @@ import urllib3
# crudly written to learn more about pytest and to have a base for refactoring
@pytest.fixture
def run_servefile():
instances = []
@ -18,7 +17,7 @@ def run_servefile():
args = [args]
print("running with args", args)
p = subprocess.Popen(['servefile'] + args, **kwargs)
time.sleep(kwargs.get('timeout', 0.3))
time.sleep(kwargs.get('timeout', 0.1))
instances.append(p)
return p
@ -172,7 +171,6 @@ def test_serve_directory(run_servefile, datadir):
# download
check_download('jup!', '/bar/thisisaverylongfilenamefortestingthatthisstillworksproperly')
def test_upload(run_servefile, tmp_path):
data = ('this is my live now\n'
'uploading strings to servers\n'
@ -209,21 +207,17 @@ def test_upload(run_servefile, tmp_path):
def test_upload_size_limit(run_servefile, tmp_path):
uploaddir = tmp_path / 'upload'
run_servefile(['-s', '2kb', '-u', str(uploaddir)])
run_servefile(['-s', '2kb''-u', str(uploaddir)])
# upload file that is too big
files = {'file': ('toobig', "x" * 2049)}
r = make_request(method='post', files=files)
assert 'Your file was too big' in r.text
assert r.status_code == 413
assert r.status_code == 200
assert not (uploaddir / 'toobig').exists()
# upload file that should fit
# the size has to be smaller than 2kb, as the sent size also includes mime-headers
files = {'file': ('justright', "x" * 1900)}
r = make_request(method='post', files=files)
assert r.status_code == 200
assert False
def test_tar_mode(run_servefile, datadir):
d = {
@ -252,12 +246,10 @@ def test_tar_mode(run_servefile, datadir):
def test_tar_compression(run_servefile, datadir):
pass
def test_https(run_servefile, datadir):
data = "NOOT NOOT"
p = datadir({'testfile': data}) / 'testfile'
run_servefile(['--ssl', str(p)])
time.sleep(0.2) # time for generating ssl certificates
run_servefile(['--ssl', str(p)], stdout=subprocess.PIPE)
# fingerprint = None
# while not fingerprint:
@ -271,5 +263,7 @@ def test_https(run_servefile, datadir):
# break
# assert fingerprint
urllib3.disable_warnings()
check_download(data, protocol='https', verify=False)
urllib3
check_download(protocol='https')