Compare commits

..

1 Commits

Author SHA1 Message Date
Sebastian Lohff d7127244be Initial tests 2019-02-13 01:00:08 +01:00
2 changed files with 16 additions and 9 deletions

View File

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

View File

@ -8,6 +8,7 @@ import urllib3
# crudly written to learn more about pytest and to have a base for refactoring
@pytest.fixture
def run_servefile():
instances = []
@ -17,7 +18,7 @@ def run_servefile():
args = [args]
print("running with args", args)
p = subprocess.Popen(['servefile'] + args, **kwargs)
time.sleep(kwargs.get('timeout', 0.1))
time.sleep(kwargs.get('timeout', 0.3))
instances.append(p)
return p
@ -171,6 +172,7 @@ 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'
@ -207,17 +209,21 @@ 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 == 200
assert r.status_code == 413
assert not (uploaddir / 'toobig').exists()
# upload file that should fit
assert False
# 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
def test_tar_mode(run_servefile, datadir):
d = {
@ -246,10 +252,12 @@ 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)], stdout=subprocess.PIPE)
run_servefile(['--ssl', str(p)])
time.sleep(0.2) # time for generating ssl certificates
# fingerprint = None
# while not fingerprint:
@ -263,7 +271,5 @@ def test_https(run_servefile, datadir):
# break
# assert fingerprint
urllib3
check_download(protocol='https')
urllib3.disable_warnings()
check_download(data, protocol='https', verify=False)