From 4da56a4e132e878801ad450da339b4f5dd399e2a Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:43:23 -0500 Subject: [PATCH] fix(ui): return correct templates --- Contents/Code/webapp.py | 16 ++++++++++------ tests/functional/test_webapp.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Contents/Code/webapp.py b/Contents/Code/webapp.py index b9f5ef55..878eb5a0 100644 --- a/Contents/Code/webapp.py +++ b/Contents/Code/webapp.py @@ -106,6 +106,11 @@ database_cache_lock = Lock() +responses = { + 500: Response(response='Internal Server Error', status=500, mimetype='text/plain') +} + + @babel.localeselector def get_locale(): # type: () -> str @@ -387,16 +392,15 @@ def home(): -------- >>> home() """ - items = [] + if not os.path.isfile(database_cache_file): + return render_template('home_db_not_cached.html', title='Home') + try: items = json.loads(Core.storage.load(filename=database_cache_file, binary=False)) except IOError: - pass + return responses[500] - if items: - return render_template('home.html', title='Home', items=items) - else: - return render_template('home_db_not_cached.html', title='Home') + return render_template('home.html', title='Home', items=items) @app.route("/", methods=["GET"]) diff --git a/tests/functional/test_webapp.py b/tests/functional/test_webapp.py index 1dda0acd..eefcc533 100644 --- a/tests/functional/test_webapp.py +++ b/tests/functional/test_webapp.py @@ -21,6 +21,23 @@ def test_home(test_client): response = test_client.get('/home') assert response.status_code == 200 + assert 'id="section_' in response.data.decode('utf-8') + + +def test_home_without_cache(empty_themerr_db_cache, test_client): + """ + WHEN the '/' page is requested (GET) + THEN check that the response is valid + """ + try: + response = test_client.get('/') + except AttributeError: + pytest.skip("cannot access Plex token/server") + else: + assert response.status_code == 200 + + assert 'Database is being cached' in response.data.decode('utf-8') + def test_image(test_client): """