From ef434df8c5cd69b62b971f3e1f83d6d4459b1a0a Mon Sep 17 00:00:00 2001 From: devsjc <47188100+devsjc@users.noreply.github.com> Date: Wed, 31 May 2023 15:03:30 +0000 Subject: [PATCH 1/4] Remove ability to use non-sqlite db in tests --- nowcasting_datamodel/connection.py | 4 ++-- tests/conftest.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nowcasting_datamodel/connection.py b/nowcasting_datamodel/connection.py index 9dc57089..a2126965 100644 --- a/nowcasting_datamodel/connection.py +++ b/nowcasting_datamodel/connection.py @@ -34,7 +34,7 @@ def __init__(self, url, base=Base_Forecast, echo: bool = True): def create_all(self): """Create all paritions and tables""" - self.base.metadata.drop_all(self.engine) + self.base.metadata.__drop_all(self.engine) self.base.metadata.create_all(self.engine) def make_partitions(self): @@ -49,7 +49,7 @@ def make_partitions(self): ): partition.__table__.create(bind=self.engine) - def drop_all(self): + def __drop_all(self): """Drop all partitions and tables""" # drop partitions for partition in self.partitions: diff --git a/tests/conftest.py b/tests/conftest.py index 8ac64929..3d8fa7be 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,7 +52,10 @@ def forecasts_all(db_session) -> List[ForecastSQL]: @pytest.fixture def db_connection(): - url = os.getenv("DB_URL", "sqlite:///test.db") + url = "sqlite:///test.db" + + if not "sqlite" in url: + raise connection = DatabaseConnection(url=url, echo=False) connection.create_all() @@ -80,7 +83,7 @@ def db_session(db_connection): @pytest.fixture def db_connection_pv(): - url = os.getenv("DB_URL_PV", "sqlite:///test_pv.db") + url = "sqlite:///test_pv.db" connection = DatabaseConnection(url=url, base=Base_PV) Base_PV.metadata.create_all(connection.engine) From 06806cc766077e01dd8cc27d0c75ad27f52b90e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 15:04:54 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3d8fa7be..b078b5f9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -55,7 +55,7 @@ def db_connection(): url = "sqlite:///test.db" if not "sqlite" in url: - raise + raise connection = DatabaseConnection(url=url, echo=False) connection.create_all() From 5145b963bfeef52eb51da1c470d664793d933e3d Mon Sep 17 00:00:00 2001 From: devsjc <47188100+devsjc@users.noreply.github.com> Date: Wed, 31 May 2023 15:08:36 +0000 Subject: [PATCH 3/4] Woops --- tests/conftest.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b078b5f9..43359d0d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,9 +54,6 @@ def forecasts_all(db_session) -> List[ForecastSQL]: def db_connection(): url = "sqlite:///test.db" - if not "sqlite" in url: - raise - connection = DatabaseConnection(url=url, echo=False) connection.create_all() From 0bb988186933ea38481410f9460f6b6d3055d7e5 Mon Sep 17 00:00:00 2001 From: devsjc <47188100+devsjc@users.noreply.github.com> Date: Wed, 31 May 2023 17:00:07 +0000 Subject: [PATCH 4/4] Missed another bit --- nowcasting_datamodel/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nowcasting_datamodel/connection.py b/nowcasting_datamodel/connection.py index a2126965..a705e93a 100644 --- a/nowcasting_datamodel/connection.py +++ b/nowcasting_datamodel/connection.py @@ -34,7 +34,7 @@ def __init__(self, url, base=Base_Forecast, echo: bool = True): def create_all(self): """Create all paritions and tables""" - self.base.metadata.__drop_all(self.engine) + self.base.metadata.drop_all(self.engine) self.base.metadata.create_all(self.engine) def make_partitions(self):