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
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Dec 22, 2023
1 parent d459ad2 commit 4da56a4
Show file tree
Hide file tree
Showing 2 changed files with 27 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')

Check warning on line 396 in Contents/Code/webapp.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/webapp.py#L396

Added line #L396 was not covered by tests

try:
items = json.loads(Core.storage.load(filename=database_cache_file, binary=False))
except IOError:
pass
return responses[500]

Check warning on line 401 in Contents/Code/webapp.py

View check run for this annotation

Codecov / codecov/patch

Contents/Code/webapp.py#L401

Added line #L401 was not covered by tests

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
17 changes: 17 additions & 0 deletions tests/functional/test_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 4da56a4

Please sign in to comment.