Implemented test: test_share_mode_close_after_first_download

This commit is contained in:
Micah Lee 2018-04-29 18:00:10 -07:00
parent 70385dd6ac
commit 7ec993d2e0
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 26 additions and 4 deletions

View File

@ -246,9 +246,13 @@ class Web(object):
# Close the server, if necessary # Close the server, if necessary
if not self.stay_open and not canceled: if not self.stay_open and not canceled:
print(strings._("closing_automatically")) print(strings._("closing_automatically"))
if shutdown_func is None: self.running = False
raise RuntimeError('Not running with the Werkzeug Server') try:
shutdown_func() if shutdown_func is None:
raise RuntimeError('Not running with the Werkzeug Server')
shutdown_func()
except:
pass
r = Response(generate()) r = Response(generate())
r.headers.set('Content-Length', self.zip_filesize) r.headers.set('Content-Length', self.zip_filesize)

View File

@ -42,6 +42,8 @@ def web_obj(common_obj, recieve_mode, num_files=0):
web = Web(common_obj, False, recieve_mode) web = Web(common_obj, False, recieve_mode)
web.generate_slug() web.generate_slug()
web.stay_open = True web.stay_open = True
web.running = True
web.app.testing = True web.app.testing = True
# Share mode # Share mode
@ -67,22 +69,38 @@ class TestWeb:
with web.app.test_client() as c: with web.app.test_client() as c:
# Load 404 pages # Load 404 pages
res = c.get('/') res = c.get('/')
res.get_data()
assert res.status_code == 404 assert res.status_code == 404
res = c.get('/invalidslug'.format(web.slug)) res = c.get('/invalidslug'.format(web.slug))
res.get_data()
assert res.status_code == 404 assert res.status_code == 404
# Load download page # Load download page
res = c.get('/{}'.format(web.slug)) res = c.get('/{}'.format(web.slug))
res.get_data()
assert res.status_code == 200 assert res.status_code == 200
# Download # Download
res = c.get('/{}/download'.format(web.slug)) res = c.get('/{}/download'.format(web.slug))
res.get_data()
assert res.status_code == 200 assert res.status_code == 200
assert res.mimetype == 'application/zip' assert res.mimetype == 'application/zip'
def test_share_mode_close_after_first_download(self, common_obj, temp_file_1024): def test_share_mode_close_after_first_download(self, common_obj, temp_file_1024):
pass web = web_obj(common_obj, False, 3)
web.stay_open = False
assert web.running == True
with web.app.test_client() as c:
# Download the first time
res = c.get('/{}/download'.format(web.slug))
res.get_data()
assert res.status_code == 200
assert res.mimetype == 'application/zip'
assert web.running == False
class TestZipWriterDefault: class TestZipWriterDefault: