Make alembic.ini safe
All database URLs are commented out. The appropriate one should be uncommented when needed.
This commit is contained in:
parent
3cab7a8376
commit
db86d04b9a
@ -39,8 +39,10 @@ prepend_sys_path = .
|
|||||||
# are written from script.py.mako
|
# are written from script.py.mako
|
||||||
# output_encoding = utf-8
|
# output_encoding = utf-8
|
||||||
|
|
||||||
sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_dev
|
sqlalchemy.url = SET
|
||||||
# sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_prod
|
# sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_prod
|
||||||
|
# sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_dev
|
||||||
|
# sqlalchemy.url = mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_v2
|
||||||
|
|
||||||
[post_write_hooks]
|
[post_write_hooks]
|
||||||
# post_write_hooks defines scripts or Python functions that are run
|
# post_write_hooks defines scripts or Python functions that are run
|
||||||
|
|||||||
@ -45,7 +45,7 @@ class NoteColours(Base):
|
|||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
substring = Column(String(256), index=False)
|
substring = Column(String(256), index=False)
|
||||||
hexcolour = Column(String(6), index=False)
|
colour = Column(String(21), index=False)
|
||||||
enabled = Column(Boolean, default=True, index=True)
|
enabled = Column(Boolean, default=True, index=True)
|
||||||
is_regex = Column(Boolean, default=False, index=False)
|
is_regex = Column(Boolean, default=False, index=False)
|
||||||
is_casesensitive = Column(Boolean, default=False, index=False)
|
is_casesensitive = Column(Boolean, default=False, index=False)
|
||||||
@ -53,9 +53,16 @@ class NoteColours(Base):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return (
|
return (
|
||||||
f"<NoteColour(id={self.id}, substring={self.substring}, colour={self.hexcolour}>"
|
f"<NoteColour(id={self.id}, substring={self.substring}, "
|
||||||
|
f"colour={self.colour}>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all(self):
|
||||||
|
"""Return all records"""
|
||||||
|
|
||||||
|
return session.query(cls).all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_colour(session, text):
|
def get_colour(session, text):
|
||||||
"""
|
"""
|
||||||
@ -66,24 +73,24 @@ class NoteColours(Base):
|
|||||||
|
|
||||||
for rec in (
|
for rec in (
|
||||||
session.query(NoteColours)
|
session.query(NoteColours)
|
||||||
.filter(NoteColours.enabled == True)
|
.filter(NoteColours.enabled.is_(True))
|
||||||
.order_by(NoteColours.order)
|
.order_by(NoteColours.order)
|
||||||
.all()
|
.all()
|
||||||
):
|
):
|
||||||
if rec.is_regex:
|
if rec.is_regex:
|
||||||
if rec.is_casesensitive:
|
flags = re.UNICODE
|
||||||
p = re.compile(rec.substring)
|
if not rec.is_casesensitive:
|
||||||
else:
|
flags |= re.IGNORECASE
|
||||||
p = re.compile(rec.substring, re.IGNORECASE)
|
p = re.compile(rec.substring, flags)
|
||||||
if p.match(text):
|
if p.match(text):
|
||||||
return '#' + rec.hexcolour
|
return rec.colour
|
||||||
else:
|
else:
|
||||||
if rec.is_casesensitive:
|
if rec.is_casesensitive:
|
||||||
if rec.substring in text:
|
if rec.substring in text:
|
||||||
return '#' + rec.hexcolour
|
return rec.colour
|
||||||
else:
|
else:
|
||||||
if rec.substring.lower() in text.lower():
|
if rec.substring.lower() in text.lower():
|
||||||
return '#' + rec.hexcolour
|
return rec.colour
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
83
conftest.py
Normal file
83
conftest.py
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# https://stewartadam.io/blog/2019/04/04/testing-flask-applications-code-database-views-flask-config-and-app-context-pytest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append("app")
|
||||||
|
|
||||||
|
from config import Config # noqa E402
|
||||||
|
from flask import g # noqa E402
|
||||||
|
from kpi import create_app # noqa E402
|
||||||
|
from kpi import db as _db # noqa E402
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfig(Config):
|
||||||
|
# TESTING = True
|
||||||
|
SQLALCHEMY_DATABASE_URI = 'sqlite://'
|
||||||
|
PYTESTING = True
|
||||||
|
|
||||||
|
# @pytest.fixture(scope="module")
|
||||||
|
# def app():
|
||||||
|
# app = create_app(TestConfig)
|
||||||
|
# app_context = app.app_context()
|
||||||
|
# app_context.push()
|
||||||
|
# db.create_all()
|
||||||
|
# return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def no_bank_holidays():
|
||||||
|
"Set no bank holidays"
|
||||||
|
|
||||||
|
g.BankHolidays = []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def app(request):
|
||||||
|
"""Test session-wide test `Flask` application."""
|
||||||
|
|
||||||
|
app = create_app(TestConfig)
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _setup_app_context_for_test(request, app):
|
||||||
|
"""
|
||||||
|
Given app is session-wide, sets up a app context per test to ensure that
|
||||||
|
app and request stack is not shared between tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
ctx = app.app_context()
|
||||||
|
ctx.push()
|
||||||
|
yield # tests will run here
|
||||||
|
ctx.pop()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def db(app, request):
|
||||||
|
"""Returns session-wide initialized database"""
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
_db.create_all()
|
||||||
|
yield _db
|
||||||
|
_db.drop_all()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def session(app, db, request):
|
||||||
|
"""Creates a new database session for each test,
|
||||||
|
rolling back changes afterwards"""
|
||||||
|
|
||||||
|
connection = _db.engine.connect()
|
||||||
|
transaction = connection.begin()
|
||||||
|
|
||||||
|
options = dict(bind=connection, binds={})
|
||||||
|
session = _db.create_scoped_session(options=options)
|
||||||
|
|
||||||
|
_db.session = session
|
||||||
|
|
||||||
|
yield session
|
||||||
|
|
||||||
|
transaction.rollback()
|
||||||
|
connection.close()
|
||||||
|
session.remove()
|
||||||
83
conftest.py.2b
Normal file
83
conftest.py.2b
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
# https://stewartadam.io/blog/2019/04/04/testing-flask-applications-code-database-views-flask-config-and-app-context-pytest
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import sys
|
||||||
|
|
||||||
|
sys.path.append("app")
|
||||||
|
|
||||||
|
from config import Config # noqa E402
|
||||||
|
from flask import g # noqa E402
|
||||||
|
from kpi import create_app # noqa E402
|
||||||
|
from kpi import db as _db # noqa E402
|
||||||
|
|
||||||
|
|
||||||
|
class TestConfig(Config):
|
||||||
|
# TESTING = True
|
||||||
|
SQLALCHEMY_DATABASE_URI = 'sqlite://'
|
||||||
|
PYTESTING = True
|
||||||
|
|
||||||
|
# @pytest.fixture(scope="module")
|
||||||
|
# def app():
|
||||||
|
# app = create_app(TestConfig)
|
||||||
|
# app_context = app.app_context()
|
||||||
|
# app_context.push()
|
||||||
|
# db.create_all()
|
||||||
|
# return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def no_bank_holidays():
|
||||||
|
"Set no bank holidays"
|
||||||
|
|
||||||
|
g.BankHolidays = []
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def app(request):
|
||||||
|
"""Test session-wide test `Flask` application."""
|
||||||
|
|
||||||
|
app = create_app(TestConfig)
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _setup_app_context_for_test(request, app):
|
||||||
|
"""
|
||||||
|
Given app is session-wide, sets up a app context per test to ensure that
|
||||||
|
app and request stack is not shared between tests.
|
||||||
|
"""
|
||||||
|
|
||||||
|
ctx = app.app_context()
|
||||||
|
ctx.push()
|
||||||
|
yield # tests will run here
|
||||||
|
ctx.pop()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def db(app, request):
|
||||||
|
"""Returns session-wide initialized database"""
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
_db.create_all()
|
||||||
|
yield _db
|
||||||
|
_db.drop_all()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="function")
|
||||||
|
def session(app, db, request):
|
||||||
|
"""Creates a new database session for each test,
|
||||||
|
rolling back changes afterwards"""
|
||||||
|
|
||||||
|
connection = _db.engine.connect()
|
||||||
|
transaction = connection.begin()
|
||||||
|
|
||||||
|
options = dict(bind=connection, binds={})
|
||||||
|
session = _db.create_scoped_session(options=options)
|
||||||
|
|
||||||
|
_db.session = session
|
||||||
|
|
||||||
|
yield session
|
||||||
|
|
||||||
|
transaction.rollback()
|
||||||
|
connection.close()
|
||||||
|
session.remove()
|
||||||
7
test_model.py
Normal file
7
test_model.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from model import Playlists, Session
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_colour():
|
||||||
|
with Session() as session:
|
||||||
|
x = Playlists.get_all_playlists(session)
|
||||||
|
assert False
|
||||||
@ -1,2 +0,0 @@
|
|||||||
def test_get_colour():
|
|
||||||
assert False
|
|
||||||
Loading…
Reference in New Issue
Block a user