Skip to content

Commit 05d6194

Browse files
MaxNumeriquegithub-actions[bot]
authored andcommitted
Apply prepare changes
1 parent 21a2f54 commit 05d6194

6 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/opengeodeweb_microservice/app_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import os
22
from .database.connection import DATABASE_FILENAME
33

4+
45
class Config:
56
pass
67

8+
79
class ProdConfig(Config):
810
DATA_FOLDER_PATH = "/data"
911
SQLALCHEMY_DATABASE_URI = f"sqlite:///{os.path.abspath(

src/opengeodeweb_microservice/database/connection.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
db: Optional[SQLAlchemy] = None
1111

12+
1213
def init_database(app: Flask, db_filename: str = DATABASE_FILENAME) -> SQLAlchemy:
1314
global db
1415
if db is None:
@@ -18,13 +19,16 @@ def init_database(app: Flask, db_filename: str = DATABASE_FILENAME) -> SQLAlchem
1819
db.create_all()
1920
return db
2021

22+
2123
def get_database() -> Optional[SQLAlchemy]:
2224
return db
2325

26+
2427
def get_session():
2528
if db is None:
2629
return None
2730
return db.session
2831

32+
2933
def get_database_connection():
3034
return get_database()

src/opengeodeweb_microservice/microservice/data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .base import Base
55
import uuid
66

7+
78
class Data(Base):
89
__tablename__ = "datas"
910

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from src.opengeodeweb_microservice.database.connection import init_database, get_session
55
from src.opengeodeweb_microservice.microservice.data import Data
66

7+
78
@pytest.fixture(scope="session")
89
def app():
910
app = Flask(__name__)
@@ -18,6 +19,7 @@ def app():
1819
_cleanup_database_connections()
1920
_remove_test_database(db_path)
2021

22+
2123
def _cleanup_database_connections():
2224
try:
2325
session = get_session()
@@ -26,18 +28,21 @@ def _cleanup_database_connections():
2628
except Exception:
2729
pass
2830

31+
2932
def _remove_test_database(db_path: str):
3033
if os.path.exists(db_path):
3134
try:
3235
os.remove(db_path)
3336
except PermissionError:
3437
pass
3538

39+
3640
@pytest.fixture
3741
def app_context(app):
3842
with app.app_context():
3943
yield
4044

45+
4146
@pytest.fixture
4247
def clean_database(app_context):
4348
session = get_session()

tests/test_connection.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
)
55
from src.opengeodeweb_microservice.microservice.data import Data
66

7+
78
def test_database_connection_basic(app_context):
89
session = get_session()
910
assert session is not None

tests/test_database.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from src.opengeodeweb_microservice.database.connection import get_session
22
from src.opengeodeweb_microservice.microservice.data import Data
33

4+
45
def test_data_crud_operations():
56
data = Data.create(geode_object="test_object", input_file="test.txt")
67
assert data.id is not None
@@ -12,6 +13,7 @@ def test_data_crud_operations():
1213
non_existent = Data.get("fake_id")
1314
assert non_existent is None
1415

16+
1517
def test_data_with_additional_files():
1618
files = ["file1.txt", "file2.txt"]
1719
data = Data.create(geode_object="test_files", additional_files=files)

0 commit comments

Comments
 (0)