diff --git a/README.md b/README.md index 274eab10..ddd9bc94 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ oraz wymienianie ich na nagrody. ## Uruchomienie: - `pip install -r requirements.txt` - instalacja zależności - `python recreate_db.py` - stworzenie tabeli w bazie -- `python run.py` - uruchomienie serwera +- `export FLASK_APP="zeton"; flask run` - uruchomienie serwera ### Testowi użytkownicy: - na ten moment użytkownicy i ich hasła zapisane są w wykomentowanym kodzie w `recreate_db.py` diff --git a/run.py b/run.py deleted file mode 100644 index 66990545..00000000 --- a/run.py +++ /dev/null @@ -1,16 +0,0 @@ -import sys, os - -sys.path.append(os.getcwd()) - -import zeton - -app = zeton.create_app() - -if __name__ == '__main__': - # if you want test on computer use this command - app.run(debug=True) - - # # If you want test on mobile use this command - # # also you must use your local ip in your browser - # # Only one statment app.run is allowed - # app.run(host='0.0.0.0', port=80, debug=True) diff --git a/tests/conftest.py b/tests/conftest.py index 00c84108..74b624b7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,7 +3,8 @@ import pytest -from zeton import create_app +# set up app will be used as fixture named app +from zeton import app as application from zeton.db import get_db # read in SQL for populating test data @@ -22,14 +23,15 @@ def app(): # create a temporary file to isolate the database for each test db_fd, db_path = tempfile.mkstemp() # create the app with common test config - app = create_app({"TESTING": True, "DATABASE": db_path}) + + application.config.from_mapping({"TESTING": True, "DATABASE": db_path}) # create the database and load test data - with app.app_context(): + with application.app_context(): get_db().executescript(_init_data_sql) get_db().executescript(_data_sql) - yield app + yield application # close and remove the temporary database os.close(db_fd) diff --git a/zeton/__init__.py b/zeton/__init__.py index f2cc722e..fdeb5a6b 100644 --- a/zeton/__init__.py +++ b/zeton/__init__.py @@ -11,28 +11,22 @@ from zeton.data_access import users -def create_app(test_config=None): - app = Flask(__name__, instance_relative_config=True) +app = Flask(__name__, instance_relative_config=True) - app.config.from_mapping( - SECRET_KEY='AplikacjaDlaStasia', - DATABASE=os.path.join(app.root_path, '..', 'db.sqlite'), - SITE_NAME='Zeton' - ) +app.config.from_mapping( + SECRET_KEY='AplikacjaDlaStasia', + DATABASE=os.path.join(app.root_path, '..', 'db.sqlite'), + SITE_NAME='Zeton' +) - if test_config is None: - app.config.from_pyfile('config.py', silent=True) - else: - app.config.from_mapping(test_config) +app.config.from_pyfile('config.py', silent=True) - app.teardown_appcontext(db.close_db) +app.teardown_appcontext(db.close_db) - app.add_template_filter(jinja2_ban_datetime_filter, 'ban_time') +app.add_template_filter(jinja2_ban_datetime_filter, 'ban_time') - app.register_blueprint(auth.bp) - app.register_blueprint(views.bp) - app.register_blueprint(api.bp) +app.register_blueprint(auth.bp) +app.register_blueprint(views.bp) +app.register_blueprint(api.bp) - app.before_request(users.load_logged_in_user_data) - - return app +app.before_request(users.load_logged_in_user_data)