Skip to content

Commit

Permalink
Adding tests to python (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
texx00 committed Oct 13, 2020
1 parent edbe977 commit 98fa73d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions UIserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@
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)
migrate = Migrate(app, db)


# 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)

Expand Down
31 changes: 31 additions & 0 deletions UIserver/tests/test_app.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion UIserver/utils/settings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit 98fa73d

Please sign in to comment.