From 084f7929bee90727f4c82403b45bc21223119a66 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 21 Mar 2019 13:09:49 +0000 Subject: [PATCH 1/8] Run app in development mode from npm start --- src/smif/app/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/smif/app/package.json b/src/smif/app/package.json index 1637e5345..653793eb6 100644 --- a/src/smif/app/package.json +++ b/src/smif/app/package.json @@ -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", From 75c6bc96933da27bd39b1fb93e779ae5e1025a4b Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 21 Mar 2019 13:10:19 +0000 Subject: [PATCH 2/8] Render template not found error message --- src/smif/http_api/register.py | 21 ++++++++++++++++++++- tests/http_api/test_crud.py | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/smif/http_api/register.py b/src/smif/http_api/register.py index 962535fed..c947c2931 100644 --- a/src/smif/http_api/register.py +++ b/src/smif/http_api/register.py @@ -1,3 +1,5 @@ +import logging +import jinja2.exceptions from flask import jsonify, render_template from smif.exception import (SmifDataExistsError, SmifDataMismatchError, SmifDataNotFoundError) @@ -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 """ + +

Error: smif app template not found

+

If you are running from a development build of smif, you may need to build the + app:

+
+cd ./src/smif/app
+npm install
+npm run build
+            
+
+

Otherwise, please report the issue, including as much detail as possible, on + GitHub.

+ """ def register_api_endpoints(app): diff --git a/tests/http_api/test_crud.py b/tests/http_api/test_crud.py index ec5b7ff78..35d5b285e 100644 --- a/tests/http_api/test_crud.py +++ b/tests/http_api/test_crud.py @@ -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( @@ -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): @@ -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 """ @@ -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 """ From 46a4bf92d952ce3148e08e5b5bcb23a9c94e06e4 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 21 Mar 2019 14:30:19 +0000 Subject: [PATCH 3/8] Relax conda channel priority for CI Python 3.6 was failing to resolve rtree dependencies --- ci/install.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/install.sh b/ci/install.sh index 2a4d8d299..8c379be33 100755 --- a/ci/install.sh +++ b/ci/install.sh @@ -25,8 +25,6 @@ if [[ "$DISTRIB" == "conda" ]]; then # Update conda conda update conda - # Follow channel priority strictly - conda config --set channel_priority strict # Don't change prompt conda config --set changeps1 false From 313b820b504b35f4fb25de90909a5c2154eb9bc3 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 21 Mar 2019 15:23:47 +0000 Subject: [PATCH 4/8] Test Python 3.7 on Appveyor --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 99bf76e53..0e2330cae 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,7 +8,7 @@ environment: PGPORT: 5432 PGPASSWORD: Password12! matrix: - - PYTHON_VERSION: 3.6 + - PYTHON_VERSION: 3.7 MINICONDA: C:\Miniconda3-x64 init: - "ECHO %PYTHON_VERSION% %MINICONDA%" @@ -17,7 +17,7 @@ install: - conda config --set always_yes yes --set changeps1 no - 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 \ From 0673435c654dba4a231c95fa3e1968f49133fa7c Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 21 Mar 2019 16:20:47 +0000 Subject: [PATCH 5/8] Run appveyor tests on conda pkgs/main (defaults) Failing to install rtree, likely related to: https://github.com/conda-forge/geopandas-feedstock/issues/53 --- .appveyor.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0e2330cae..18ec7038a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,8 +14,9 @@ init: - "ECHO %PYTHON_VERSION% %MINICONDA%" install: - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%" - - conda config --set always_yes yes --set changeps1 no - - conda config --add channels conda-forge + - conda config --set always_yes yes + - conda config --set changeps1 no + - conda config --set channel_priority strict - conda info -a - "conda create -n testenv python=%PYTHON_VERSION% \ fiona \ @@ -26,12 +27,10 @@ install: networkx \ numpy \ pandas \ - pint \ psycopg2 \ pyarrow \ pytest \ python-dateutil \ - ruamel.yaml \ rtree \ shapely \ xarray" From c7303494e72a688b962d9550f961628f582c4ac4 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Thu, 21 Mar 2019 17:02:38 +0000 Subject: [PATCH 6/8] Remove strict channel priority from Appveyor CI --- .appveyor.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 18ec7038a..b90039acd 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,7 +16,6 @@ install: - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%" - conda config --set always_yes yes - conda config --set changeps1 no - - conda config --set channel_priority strict - conda info -a - "conda create -n testenv python=%PYTHON_VERSION% \ fiona \ From ad834df07889c36e40bea5932ae10e212e703964 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 22 Mar 2019 09:36:57 +0000 Subject: [PATCH 7/8] Attempt reverting CI changes --- .appveyor.yml | 9 +++++++-- ci/install.sh | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b90039acd..197d48838 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,8 +14,11 @@ init: - "ECHO %PYTHON_VERSION% %MINICONDA%" install: - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%" - - conda config --set always_yes yes - - conda config --set changeps1 no + - conda update conda + - conda config --set always_yes true + - conda config --set changeps1 false + - conda config --set channel_priority strict + - conda config --add channels conda-forge - conda info -a - "conda create -n testenv python=%PYTHON_VERSION% \ fiona \ @@ -26,11 +29,13 @@ install: networkx \ numpy \ pandas \ + pint \ psycopg2 \ pyarrow \ pytest \ python-dateutil \ rtree \ + ruamel.yaml \ shapely \ xarray" - activate testenv diff --git a/ci/install.sh b/ci/install.sh index 8c379be33..1543cbcfa 100755 --- a/ci/install.sh +++ b/ci/install.sh @@ -24,7 +24,8 @@ 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 conda config --set changeps1 false From f783748053474aadb9b618aadf7a5ba61553c471 Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Fri, 22 Mar 2019 09:48:33 +0000 Subject: [PATCH 8/8] Set always_yes in appveyor config --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 197d48838..7cd7b73c5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,8 +14,8 @@ init: - "ECHO %PYTHON_VERSION% %MINICONDA%" install: - "set PATH=%MINICONDA%;%MINICONDA%\\Scripts;%PATH%" - - conda update conda - 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