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

fix(ui): return correct templates #310

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
--------
>>> 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]

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
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
Loading