Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run with flask #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
16 changes: 0 additions & 16 deletions run.py

This file was deleted.

10 changes: 6 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
32 changes: 13 additions & 19 deletions zeton/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)