Separate db config, testing session for pytest
This commit is contained in:
parent
cf4e42358e
commit
a31718d2b9
@ -5,19 +5,21 @@ from config import Config
|
|||||||
from sqlalchemy.orm import (sessionmaker, scoped_session)
|
from sqlalchemy.orm import (sessionmaker, scoped_session)
|
||||||
|
|
||||||
MM_ENV = os.environ.get('MM_ENV', 'PRODUCTION')
|
MM_ENV = os.environ.get('MM_ENV', 'PRODUCTION')
|
||||||
|
testing = False
|
||||||
|
|
||||||
if MM_ENV == 'PRODUCTION':
|
if MM_ENV == 'PRODUCTION':
|
||||||
dbname = os.environ.get('MM_PRODUCTION_DBNAME', 'musicmuster')
|
dbname = os.environ.get('MM_PRODUCTION_DBNAME', 'musicmuster_prod')
|
||||||
dbuser = os.environ.get('MM_PRODUCTION_DBUSER', 'musicmuster')
|
dbuser = os.environ.get('MM_PRODUCTION_DBUSER', 'musicmuster')
|
||||||
dbpw = os.environ.get('MM_PRODUCTION_DBPW', 'musicmuster')
|
dbpw = os.environ.get('MM_PRODUCTION_DBPW', 'musicmuster')
|
||||||
dbhost = os.environ.get('MM_PRODUCTION_DBHOST', 'localhost')
|
dbhost = os.environ.get('MM_PRODUCTION_DBHOST', 'localhost')
|
||||||
elif MM_ENV == 'TESTING':
|
elif MM_ENV == 'TESTING':
|
||||||
dbname = os.environ.get('MM_TESTING_DBNAME', 'musicmuster')
|
dbname = os.environ.get('MM_TESTING_DBNAME', 'musicmuster_testing')
|
||||||
dbuser = os.environ.get('MM_TESTING_DBUSER', 'musicmuster')
|
dbuser = os.environ.get('MM_TESTING_DBUSER', 'musicmuster_testing')
|
||||||
dbpw = os.environ.get('MM_TESTING_DBPW', 'musicmuster')
|
dbpw = os.environ.get('MM_TESTING_DBPW', 'musicmuster_testing')
|
||||||
dbhost = os.environ.get('MM_TESTING_DBHOST', 'localhost')
|
dbhost = os.environ.get('MM_TESTING_DBHOST', 'localhost')
|
||||||
|
testing = True
|
||||||
elif MM_ENV == 'DEVELOPMENT':
|
elif MM_ENV == 'DEVELOPMENT':
|
||||||
dbname = os.environ.get('MM_DEVELOPMENT_DBNAME', 'musicmuster')
|
dbname = os.environ.get('MM_DEVELOPMENT_DBNAME', 'musicmuster_dev')
|
||||||
dbuser = os.environ.get('MM_DEVELOPMENT_DBUSER', 'musicmuster')
|
dbuser = os.environ.get('MM_DEVELOPMENT_DBUSER', 'musicmuster')
|
||||||
dbpw = os.environ.get('MM_DEVELOPMENT_DBPW', 'musicmuster')
|
dbpw = os.environ.get('MM_DEVELOPMENT_DBPW', 'musicmuster')
|
||||||
dbhost = os.environ.get('MM_DEVELOPMENT_DBHOST', 'localhost')
|
dbhost = os.environ.get('MM_DEVELOPMENT_DBHOST', 'localhost')
|
||||||
@ -33,5 +35,4 @@ engine = sqlalchemy.create_engine(
|
|||||||
pool_pre_ping=True
|
pool_pre_ping=True
|
||||||
)
|
)
|
||||||
|
|
||||||
Session = scoped_session(sessionmaker(bind=engine))
|
session = scoped_session(sessionmaker(bind=engine))
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,12 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import dbconfig
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dbconfig import engine
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydub import AudioSegment
|
from pydub import AudioSegment
|
||||||
@ -38,15 +40,12 @@ from helpers import (
|
|||||||
)
|
)
|
||||||
from log import DEBUG, ERROR
|
from log import DEBUG, ERROR
|
||||||
|
|
||||||
|
Session = dbconfig.session
|
||||||
|
|
||||||
Base: DeclarativeMeta = declarative_base()
|
Base: DeclarativeMeta = declarative_base()
|
||||||
Base.metadata.create_all(engine)
|
Base.metadata.create_all(engine)
|
||||||
|
|
||||||
|
|
||||||
def db_init():
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
# Database classes
|
# Database classes
|
||||||
class NoteColours(Base):
|
class NoteColours(Base):
|
||||||
__tablename__ = 'notecolours'
|
__tablename__ = 'notecolours'
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import helpers
|
|||||||
import music
|
import music
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from models import (db_init, Playdates, Playlists, PlaylistTracks,
|
from models import (Playdates, Playlists, PlaylistTracks,
|
||||||
Session, Settings, Tracks)
|
Session, Settings, Tracks)
|
||||||
from playlists import PlaylistTab
|
from playlists import PlaylistTab
|
||||||
from utilities import create_track_from_file
|
from utilities import create_track_from_file
|
||||||
@ -101,6 +101,12 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
height = record.f_int or 981
|
height = record.f_int or 981
|
||||||
self.setGeometry(x, y, width, height)
|
self.setGeometry(x, y, width, height)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def kae():
|
||||||
|
with Session() as session:
|
||||||
|
db = session.bind.engine.url.database
|
||||||
|
print(f"kae(): {db=}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_audacity() -> None:
|
def check_audacity() -> None:
|
||||||
"""Offer to run Audacity if not running"""
|
"""Offer to run Audacity if not running"""
|
||||||
@ -976,7 +982,6 @@ class SelectPlaylistDialog(QDialog):
|
|||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
db_init()
|
|
||||||
win = Window()
|
win = Window()
|
||||||
win.show()
|
win.show()
|
||||||
sys.exit(app.exec())
|
sys.exit(app.exec())
|
||||||
|
|||||||
@ -7,7 +7,6 @@ from sqlalchemy import create_engine
|
|||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
from sqlalchemy.orm import scoped_session, sessionmaker
|
||||||
|
|
||||||
sys.path.append("app")
|
sys.path.append("app")
|
||||||
from app.models import Base # noqa E402
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
@ -38,6 +37,7 @@ def seed_database():
|
|||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def setup_database(connection):
|
def setup_database(connection):
|
||||||
|
from app.models import Base # noqa E402
|
||||||
Base.metadata.bind = connection
|
Base.metadata.bind = connection
|
||||||
Base.metadata.create_all()
|
Base.metadata.create_all()
|
||||||
# seed_database()
|
# seed_database()
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from PyQt5.QtCore import Qt
|
|||||||
|
|
||||||
from app.playlists import Notes, PlaylistTab, Tracks
|
from app.playlists import Notes, PlaylistTab, Tracks
|
||||||
from app.models import Playlists
|
from app.models import Playlists
|
||||||
from musicmuster import Window
|
import musicmuster
|
||||||
|
|
||||||
|
|
||||||
def test_init(qtbot, session):
|
def test_init(qtbot, session):
|
||||||
@ -220,3 +220,9 @@ def test_set_next(qtbot, session):
|
|||||||
modifier=Qt.ControlModifier)
|
modifier=Qt.ControlModifier)
|
||||||
qtbot.wait(2000)
|
qtbot.wait(2000)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_kae(monkeypatch, session):
|
||||||
|
monkeypatch.setattr(musicmuster, "Session", session)
|
||||||
|
|
||||||
|
musicmuster.Window.kae()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user