diff --git a/qcarchivetesting/qcarchivetesting/__init__.py b/qcarchivetesting/qcarchivetesting/__init__.py index 1d62a8c7e..a938d7fab 100644 --- a/qcarchivetesting/qcarchivetesting/__init__.py +++ b/qcarchivetesting/qcarchivetesting/__init__.py @@ -5,6 +5,8 @@ from .helpers import ( geoip_path, geoip_filename, + ip_testdata_path, + ip_tests_enabled, testconfig_path, migrationdata_path, test_users, diff --git a/qcarchivetesting/qcarchivetesting/helpers.py b/qcarchivetesting/qcarchivetesting/helpers.py index 76ef5f436..368b61ed2 100644 --- a/qcarchivetesting/qcarchivetesting/helpers.py +++ b/qcarchivetesting/qcarchivetesting/helpers.py @@ -24,6 +24,9 @@ geoip_path = os.path.join(_my_path, "MaxMind-DB", "test-data") geoip_filename = "GeoLite2-City-Test.mmdb" +ip_testdata_path = os.path.join(_my_path, "MaxMind-DB", "source-data", "GeoIP2-City-Test.json") + +ip_tests_enabled = os.path.exists(geoip_path) and os.path.exists(ip_testdata_path) testconfig_path = os.path.join(_my_path, "config_files") migrationdata_path = os.path.join(_my_path, "migration_data") @@ -148,9 +151,7 @@ def load_ip_test_data(): Loads data for testing IP logging """ - file_path = os.path.join(_my_path, "MaxMind-DB", "source-data", "GeoIP2-City-Test.json") - - with open(file_path, "r") as f: + with open(ip_testdata_path, "r") as f: d = json.load(f) # Stored as a list containing a dictionary with one key. Convert to a regular dict diff --git a/qcarchivetesting/qcarchivetesting/testing_classes.py b/qcarchivetesting/qcarchivetesting/testing_classes.py index 92b3a3647..a8c399eba 100644 --- a/qcarchivetesting/qcarchivetesting/testing_classes.py +++ b/qcarchivetesting/qcarchivetesting/testing_classes.py @@ -3,7 +3,7 @@ import logging from copy import deepcopy -from qcarchivetesting import geoip_path, geoip_filename +from qcarchivetesting import geoip_path, geoip_filename, ip_tests_enabled from qcfractal.config import DatabaseConfig, update_nested_dict from qcfractal.db_socket import SQLAlchemySocket from qcfractal.postgres_harness import PostgresHarness, create_snowflake_postgres @@ -150,8 +150,11 @@ def __init__( qcf_config["database"] = {"pool_size": 0} qcf_config["log_access"] = log_access - qcf_config["geoip2_dir"] = geoip_path - qcf_config["geoip2_filename"] = geoip_filename + + if ip_tests_enabled: + qcf_config["geoip2_dir"] = geoip_path + qcf_config["geoip2_filename"] = geoip_filename + qcf_config["auto_reset"] = {"enabled": False} # Merge in any other specified config diff --git a/qcarchivetesting/qcarchivetesting/testing_fixtures.py b/qcarchivetesting/qcarchivetesting/testing_fixtures.py index 1f319c5f0..57d296573 100644 --- a/qcarchivetesting/qcarchivetesting/testing_fixtures.py +++ b/qcarchivetesting/qcarchivetesting/testing_fixtures.py @@ -12,7 +12,7 @@ from qcfractal.db_socket.socket import SQLAlchemySocket from qcportal import PortalClient from qcportal.managers import ManagerName -from .helpers import geoip_path, geoip_filename, test_users +from .helpers import geoip_path, geoip_filename, ip_tests_enabled, test_users from .testing_classes import QCATestingPostgresServer, QCATestingSnowflake, _activated_manager_programs @@ -51,8 +51,11 @@ def session_storage_socket(postgres_server): cfg_dict["database"] = pg_harness.config.dict() cfg_dict["database"]["pool_size"] = 0 cfg_dict["log_access"] = True - cfg_dict["geoip2_dir"] = geoip_path - cfg_dict["geoip2_filename"] = geoip_filename + + if ip_tests_enabled: + cfg_dict["geoip2_dir"] = geoip_path + cfg_dict["geoip2_filename"] = geoip_filename + cfg_dict["api"] = {"secret_key": secrets.token_urlsafe(32), "jwt_secret_key": secrets.token_urlsafe(32)} qcf_config = FractalConfig(**cfg_dict) diff --git a/qcfractal/qcfractal/components/serverinfo/test_access_socket.py b/qcfractal/qcfractal/components/serverinfo/test_access_socket.py index 1a0cee03e..768bfd199 100644 --- a/qcfractal/qcfractal/components/serverinfo/test_access_socket.py +++ b/qcfractal/qcfractal/components/serverinfo/test_access_socket.py @@ -4,7 +4,9 @@ from datetime import datetime from typing import TYPE_CHECKING -from qcarchivetesting import load_ip_test_data +import pytest + +from qcarchivetesting import load_ip_test_data, ip_tests_enabled from qcarchivetesting.testing_classes import QCATestingSnowflake from qcfractal.testing_helpers import DummyJobProgress from qcportal.serverinfo.models import AccessLogQueryFilters @@ -24,6 +26,7 @@ ] +@pytest.mark.skipif(not ip_tests_enabled, reason="Test GeoIP data not found") def test_serverinfo_socket_save_access(secure_snowflake: QCATestingSnowflake): storage_socket = secure_snowflake.get_storage_socket()