diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 00000000..ccbf0e39 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,36 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ master, flask-tests ] + pull_request: + branches: [ master, flask-tests ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + # - name: Lint with flake8 + # run: | + # # stop the build if there are Python syntax errors or undefined names + # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + # flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + python -m pytest UIserver/tests diff --git a/UIserver/__init__.py b/UIserver/__init__.py index 6e41021f..d047518f 100644 --- a/UIserver/__init__.py +++ b/UIserver/__init__.py @@ -45,7 +45,7 @@ app.config['UPLOAD_FOLDER'] = "./UIserver/static/Drawings" socketio = SocketIO(app) -file_path = os.path.abspath(os.getcwd())+"\database.db" +file_path = os.path.join(os.path.abspath(os.getcwd()), "database.db") app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+file_path app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) @@ -53,7 +53,8 @@ # scss compiler (already minified) -sass.compile(dirname=(os.path.abspath(os.getcwd())+"/UIserver/static/scss", os.path.abspath(os.getcwd())+"/UIserver/static/css"), output_style='compressed') +if os.path.isdir('./UIserver/static/js/node_modules/bootstrap'): # check if the bootstrap folder is available (it will not be available in the github workflow for testing) + sass.compile(dirname=(os.path.abspath(os.getcwd())+"/UIserver/static/scss", os.path.abspath(os.getcwd())+"/UIserver/static/css"), output_style='compressed') # js and html minifier (on request) minify(app=app, html=True, js=False) diff --git a/UIserver/tests/test_app.py b/UIserver/tests/test_app.py new file mode 100644 index 00000000..d08b51a0 --- /dev/null +++ b/UIserver/tests/test_app.py @@ -0,0 +1,31 @@ +import os +import tempfile +from flask_sqlalchemy import SQLAlchemy + +import pytest + +from UIserver import UIserver + +# to run tests use "python -m pytest UIserver/tests" in the main project folder +# at the moment there is a deprecation waring related to the "future" library + + +@pytest.fixture +def client(): + db_fd, UIserver.app.config['SQLALCHEMY_DATABASE_URI'] = tempfile.mkstemp() + UIserver.app.config['TESTING'] = True + + with UIserver.app.test_client() as client: + with UIserver.app.app_context(): + UIserver.db = SQLAlchemy(UIserver.app) + yield client + + os.close(db_fd) + os.unlink(UIserver.app.config['SQLALCHEMY_DATABASE_URI']) + +def test_empty_database(client): + """Start with a blank database.""" + + rv = client.get('/') + assert rv.location == 'http://localhost/preview' + assert rv.default_status == 200 \ No newline at end of file diff --git a/UIserver/utils/settings_utils.py b/UIserver/utils/settings_utils.py index f48a8469..ffd0972c 100644 --- a/UIserver/utils/settings_utils.py +++ b/UIserver/utils/settings_utils.py @@ -19,7 +19,9 @@ def save_settings(settings): def load_settings(): settings = "" - with open(settings_path) as f: + if not os.path.isfile(settings_path): # for python tests + tmp_settings_path = defaults_path + with open(tmp_settings_path) as f: settings = json.load(f) return settings diff --git a/requirements.txt b/requirements.txt index f2e229c6..21aa2359 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,11 @@ alembic==1.4.2 +astroid==2.4.2 +atomicwrites==1.4.0 +attrs==20.2.0 certifi==2020.4.5.1 chardet==3.0.4 click==7.1.2 +colorama==0.4.3 ecdsa==0.15 Flask==1.1.2 Flask-Migrate==2.5.3 @@ -11,24 +15,33 @@ Flask-SQLAlchemy==2.4.2 future==0.18.2 htmlmin==0.1.12 idna==2.9 +importlib-metadata==2.0.0 +iniconfig==1.0.1 iso8601==0.1.12 +isort==4.3.21 itsdangerous==1.1.0 Jinja2==2.11.2 jsmin==2.2.2 +lazy-object-proxy==1.4.3 lesscpy==0.14.0 libsass==0.20.1 Mako==1.1.3 MarkupSafe==1.1.1 +mccabe==0.6.1 packaging==20.4 pid==3.0.3 Pillow==7.1.2 pip==20.2.3 +pluggy==0.13.1 ply==3.11 psutil==5.7.0 +py==1.9.0 pyaes==1.6.1 +pylint==2.5.3 pyparsing==2.4.7 pyScss==1.3.7 pyserial==3.4 +pytest==6.1.1 python-dateutil==2.8.1 python-dotenv==0.13.0 python-editor==1.0.4 @@ -40,7 +53,12 @@ serial==0.0.97 setuptools==47.1.1 six==1.15.0 SQLAlchemy==1.3.17 +toml==0.10.1 +typed-ast==1.4.1 urllib3==1.25.9 webassets==2.0 Werkzeug==1.0.1 +wheel==0.34.2 +wrapt==1.12.1 xxhash==2.0.0 +zipp==3.3.0