Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
fix(ui): return correct templates (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Dec 22, 2023
1 parent d459ad2 commit 2bad2c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Contents/Code/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("/<path:img>", methods=["GET"])
Expand Down
35 changes: 35 additions & 0 deletions tests/functional/test_webapp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# -*- coding: utf-8 -*-

# standard imports
import os

# lib imports
import pytest

# local imports
from Code import webapp


@pytest.fixture(scope='function')
def remove_themerr_db_cache_file():
_backup_file_name = "{}.bak".format(webapp.database_cache_file)

# rename the file, so it is not found
os.rename(webapp.database_cache_file, _backup_file_name)
yield

# rename the file back
os.rename(_backup_file_name, webapp.database_cache_file)


def test_home(test_client):
"""
Expand All @@ -21,6 +39,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(remove_themerr_db_cache_file, 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):
"""
Expand Down

0 comments on commit 2bad2c0

Please sign in to comment.