Skip to content

Commit 347dbde

Browse files
committed
add session clear endpoint
1 parent cd7f759 commit 347dbde

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

picasso/picasso.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import io
3030
import time
3131
import inspect
32+
import shutil
3233
from operator import itemgetter
3334
from tempfile import mkdtemp
3435
from importlib import import_module
@@ -102,7 +103,6 @@ def initialize_new_session():
102103
session['img_input_dir'] = mkdtemp()
103104
session['img_output_dir'] = mkdtemp()
104105

105-
106106
def get_visualizations():
107107
"""Get visualization classes in context
108108
@@ -221,6 +221,14 @@ def api_visualize():
221221
return jsonify(output=output)
222222

223223

224+
@app.route('/api/reset', methods=['GET'])
225+
def end_session():
226+
shutil.rmtree(session['img_input_dir'])
227+
shutil.rmtree(session['img_output_dir'])
228+
session.clear()
229+
return jsonify(ok='true')
230+
231+
224232
@app.route('/', methods=['GET', 'POST'])
225233
def landing():
226234
"""Landing page for the application

tests/test_picasso.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def test_listing_images(self, client):
103103
response = client.get(url_for('api_images'))
104104
assert response.status_code == 200
105105

106+
def test_end_session(self, client):
107+
response = client.get(url_for('end_session'))
108+
assert response.status_code == 200
109+
106110

107111
class TestBaseModel:
108112

0 commit comments

Comments
 (0)