Skip to content

Commit 947e5b4

Browse files
committed
Fix tests requiring database timezone to be UTC
1 parent 5e747ce commit 947e5b4

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

cubedash/testutils/database.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ def odc_test_db(cfg_env):
147147
# during testing, and need any performance gains we can get.
148148

149149
with index._db._engine.begin() as conn: # type: ignore[attr-defined]
150+
# Some tests are sensitive to the timezone of the database, and expect it to be UTC
151+
quoted_db_name = conn.dialect.identifier_preparer.quote(
152+
index._db._engine.url.database # type: ignore[attr-defined]
153+
)
154+
conn.execute(text(f"ALTER DATABASE {quoted_db_name} SET timezone TO 'UTC'"))
155+
150156
if index.name == "pg_index":
151157
for table in [
152158
"agdc.dataset_location",

integration_tests/test_page_loads.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,11 @@ def test_invalid_product_returns_not_found(client: FlaskClient) -> None:
790790

791791

792792
@pytest.mark.parametrize("env_name", ("default",), indirect=True)
793-
def test_show_summary_cli(clirunner, client: FlaskClient, fix_utc_timezone) -> None:
793+
def test_show_summary_cli(clirunner, client: FlaskClient) -> None:
794794
"""
795795
You should be able to view a product with cubedash-view command-line program.
796+
797+
This test expects the database timezone to be UTC
796798
"""
797799
# ls7_nbar_scene, 2017, May
798800
res = clirunner(show.cli, ["ls7_nbar_scene", "2017", "5"])
@@ -810,7 +812,8 @@ def test_show_summary_cli(clirunner, client: FlaskClient, fix_utc_timezone) -> N
810812
f" to {expected_to.isoformat()} ",
811813
)
812814
)
813-
assert res.output.startswith(expected_header)
815+
result_header = "\n".join(res.output.splitlines()[:5])
816+
assert expected_header == result_header
814817
expected_metadata = "\n".join( # noqa: FLY002
815818
(
816819
"Metadata",

integration_tests/test_stac.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,12 @@ def test_arrivals_page_validation(stac_client: FlaskClient) -> None:
632632

633633

634634
@pytest.mark.parametrize("env_name", ("default",), indirect=True)
635-
def test_stac_collection(stac_client: FlaskClient, fix_utc_timezone):
635+
def test_stac_collection(stac_client: FlaskClient):
636636
"""
637637
Follow the links to the "high_tide_comp_20p" collection and ensure it includes
638638
all of our tests data.
639+
640+
This test expects the database timezone to be UTC
639641
"""
640642

641643
collections = get_json(stac_client, "/stac")

0 commit comments

Comments
 (0)