Skip to content

Commit

Permalink
Merge pull request #752 from MolSSI/next
Browse files Browse the repository at this point in the history
Detect geoip test data and skip if not there
  • Loading branch information
bennybp committed Sep 15, 2023
2 parents d06773d + 230386b commit ee3504f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions qcarchivetesting/qcarchivetesting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from .helpers import (
geoip_path,
geoip_filename,
ip_testdata_path,
ip_tests_enabled,
testconfig_path,
migrationdata_path,
test_users,
Expand Down
7 changes: 4 additions & 3 deletions qcarchivetesting/qcarchivetesting/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions qcarchivetesting/qcarchivetesting/testing_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions qcarchivetesting/qcarchivetesting/testing_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit ee3504f

Please sign in to comment.