Skip to content

Commit fefecf1

Browse files
committed
refacto
1 parent 21a2f54 commit fefecf1

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/opengeodeweb_microservice/database/connection.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ..microservice.base import Base
77

88
DATABASE_FILENAME = "project.db"
9-
109
db: Optional[SQLAlchemy] = None
1110

1211
def init_database(app: Flask, db_filename: str = DATABASE_FILENAME) -> SQLAlchemy:
@@ -22,9 +21,6 @@ def get_database() -> Optional[SQLAlchemy]:
2221
return db
2322

2423
def get_session():
25-
if db is None:
26-
return None
27-
return db.session
24+
return db.session if db else None
2825

29-
def get_database_connection():
30-
return get_database()
26+
get_database_connection = get_database

tests/conftest.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,24 @@
77
@pytest.fixture(scope="session")
88
def app():
99
app = Flask(__name__)
10-
app.config["TESTING"] = True
11-
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
12-
db_path = os.path.join(BASE_DIR, "test_project.db")
13-
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_path}"
14-
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
10+
app.config.update({
11+
"TESTING": True,
12+
"SQLALCHEMY_DATABASE_URI": f"sqlite:///{os.path.join(os.path.dirname(__file__), 'test_project.db')}",
13+
"SQLALCHEMY_TRACK_MODIFICATIONS": False
14+
})
1515
with app.app_context():
1616
init_database(app, "test_project.db")
1717
yield app
18-
_cleanup_database_connections()
19-
_remove_test_database(db_path)
18+
_cleanup_database()
2019

21-
def _cleanup_database_connections():
20+
def _cleanup_database():
2221
try:
2322
session = get_session()
2423
if session:
2524
session.close()
2625
except Exception:
2726
pass
28-
29-
def _remove_test_database(db_path: str):
27+
db_path = os.path.join(os.path.dirname(__file__), "test_project.db")
3028
if os.path.exists(db_path):
3129
try:
3230
os.remove(db_path)

0 commit comments

Comments
 (0)