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/', url='http://seba-geek.de/stuff/servefile/',
author='Sebastian Lohff', author='Sebastian Lohff',
author_email='seba@someserver.de', author_email='seba@someserver.de',
install_requires=['pyopenssl'],
scripts=['servefile'], scripts=['servefile'],
) )

View File

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