Skip to content

Commit

Permalink
Merge pull request #330 from tomalrussell/fix/app_template_not_found
Browse files Browse the repository at this point in the history
Fix/app template not found
  • Loading branch information
willu47 authored Mar 25, 2019
2 parents d0f54ff + f783748 commit 13d0383
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 8 deletions.
11 changes: 7 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ environment:
PGPORT: 5432
PGPASSWORD: Password12!
matrix:
- PYTHON_VERSION: 3.6
- PYTHON_VERSION: 3.7
MINICONDA: C:\Miniconda3-x64
init:
- "ECHO %PYTHON_VERSION% %MINICONDA%"
install:
- "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%"
- conda config --set always_yes yes --set changeps1 no
- conda config --set always_yes true
- conda update conda
- conda config --set changeps1 false
- conda config --set channel_priority strict
- conda config --add channels conda-forge
- conda info -a
- "conda create -n testenv --yes python=%PYTHON_VERSION% \
- "conda create -n testenv python=%PYTHON_VERSION% \
fiona \
flask \
gdal \
Expand All @@ -31,8 +34,8 @@ install:
pyarrow \
pytest \
python-dateutil \
ruamel.yaml \
rtree \
ruamel.yaml \
shapely \
xarray"
- activate testenv
Expand Down
1 change: 0 additions & 1 deletion ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ if [[ "$DISTRIB" == "conda" ]]; then
conda config --set always_yes true
# Update conda
conda update conda

# Follow channel priority strictly
conda config --set channel_priority strict
# Don't change prompt
Expand Down
2 changes: 1 addition & 1 deletion src/smif/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"report": "nyc report --reporter=lcov > coverage.lcov",
"build": "webpack --mode production",
"watch": "webpack --progress --watch --mode development",
"start": "webpack-dev-server --open"
"start": "webpack-dev-server --open --mode development"
},
"author": "Tom Russell",
"license": "MIT",
Expand Down
21 changes: 20 additions & 1 deletion src/smif/http_api/register.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
import jinja2.exceptions
from flask import jsonify, render_template
from smif.exception import (SmifDataExistsError, SmifDataMismatchError,
SmifDataNotFoundError)
Expand All @@ -16,7 +18,24 @@ def register_routes(app):
def home(path=None):
"""Render single page
"""
return render_template('index.html')
try:
return render_template('index.html')
except jinja2.exceptions.TemplateNotFound as ex:
logging.error(ex, exc_info=True)
return """<!doctype html>
<style>html, body { font-family: sans-serif; }</style>
<h1>Error: smif app template not found</h1>
<p>If you are running from a development build of smif, you may need to build the
app:</p>
<code><pre>
cd ./src/smif/app
npm install
npm run build
</pre>
</code>
<p>Otherwise, please report the issue, including as much detail as possible, on
<a href="https://github.com/nismod/smif/issues">GitHub</a>.</p>
"""


def register_api_endpoints(app):
Expand Down
35 changes: 34 additions & 1 deletion tests/http_api/test_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def _check_exist(config, name):

@pytest.fixture
def app(request, mock_scheduler, mock_data_interface):

"""Return an app
"""
test_app = create_app(
Expand All @@ -98,6 +97,20 @@ def app(request, mock_scheduler, mock_data_interface):
with test_app.app_context():
yield test_app

@pytest.fixture
def app_fail(request, mock_scheduler, mock_data_interface):
"""Return an app which will fail to find templates
"""
test_app = create_app(
static_folder=os.path.join(os.path.dirname(__file__), '..', 'fixtures', '404'),
template_folder=os.path.join(os.path.dirname(__file__), '..', 'fixtures', '404'),
data_interface=mock_data_interface,
scheduler=mock_scheduler
)

with test_app.app_context():
yield test_app


@pytest.fixture
def client(request, app):
Expand All @@ -112,6 +125,19 @@ def teardown():
return test_client


@pytest.fixture
def client_fail(request, app_fail):
"""Return an API client which will fail on request for home page
"""
test_client = app_fail.test_client()

def teardown():
pass

request.addfinalizer(teardown)
return test_client


def parse_json(response):
"""Parse response data
"""
Expand All @@ -136,6 +162,13 @@ def test_hello(client):
assert "Welcome to smif" in str(response.data)


def test_template_not_found(client_fail):
"""Clear error if template not found
"""
response = client_fail.get('/')
assert "Error: smif app template not found" in str(response.data)


def test_get_smif(client):
"""GET smif details
"""
Expand Down

0 comments on commit 13d0383

Please sign in to comment.