diff options
-rw-r--r-- | tests/fixtures/rdf.py | 34 | ||||
-rw-r--r-- | tests/unit/db/rdf/test_wiki.py | 11 |
2 files changed, 15 insertions, 30 deletions
diff --git a/tests/fixtures/rdf.py b/tests/fixtures/rdf.py index 0bafeaa..b942282 100644 --- a/tests/fixtures/rdf.py +++ b/tests/fixtures/rdf.py @@ -6,30 +6,14 @@ import requests import pytest -def get_sparql_auth_conf() -> dict: - """Fetch SPARQL auth configuration for the GN3_SECRETS file.""" - sparql_conf = config.Config("") - if os.environ.get("GN3_CONF"): - # Check whether GN3_CONF has been set, and ignore GN3_CONF - # otherwise. In CD, we use a mixed-text file, so we don't - # have an explicit PATH to point this to. - # https://git.genenetwork.org/gn-machines/tree/genenetwork-development.scm#n517 - sparql_conf.from_envvar("GN3_CONF") - # Set sane defaults for GN3_SECRETS to CD's secret file. In CD, - # this file is set in the genenetwork3 cd gexp: - # https://git.genenetwork.org/gn-machines/tree/genenetwork-development.scm#n516 - # However, during testing GN3_SECRETS isn't set; and by default, - # we run guix's default tests for python projects: `pytest` - # https://git.genenetwork.org/guix-bioinformatics/tree/gn/packages/genenetwork.scm#n182 - if not os.environ.get("GN3_SECRETS"): - os.environ["GN3_SECRETS"] = "/etc/genenetwork/conf/gn3/secrets.py" - sparql_conf.from_envvar("GN3_SECRETS") +def get_sparql_auth_conf(config_obj) -> dict: + """Fetch SPARQL auth configuration from the configuration object.""" return { - "sparql_user": sparql_conf["SPARQL_USER"], - "sparql_auth_uri": sparql_conf["SPARQL_AUTH_URI"], - "sparql_crud_auth_uri": sparql_conf["SPARQL_CRUD_AUTH_URI"], - "sparql_endpoint": sparql_conf["SPARQL_ENDPOINT"], - "sparql_password": sparql_conf["SPARQL_PASSWORD"], + "sparql_user": config_obj["SPARQL_USER"], + "sparql_auth_uri": config_obj["SPARQL_AUTH_URI"], + "sparql_crud_auth_uri": config_obj["SPARQL_CRUD_AUTH_URI"], + "sparql_endpoint": config_obj["SPARQL_ENDPOINT"], + "sparql_password": config_obj["SPARQL_PASSWORD"], } @@ -37,10 +21,10 @@ def get_sparql_auth_conf() -> dict: # This is not idempotent. Consider having a special virtuoso instance # just for running tests. @pytest.fixture(scope="module") -def rdf_setup(): +def rdf_setup(fxtr_app_config): """Upload RDF to a Virtuoso named graph""" # Define the URL and file - sparql_conf = get_sparql_auth_conf() + sparql_conf = get_sparql_auth_conf(fxtr_app_config) url = sparql_conf["sparql_crud_auth_uri"] file_path = os.path.join( os.path.dirname(__file__).split("fixtures")[0], diff --git a/tests/unit/db/rdf/test_wiki.py b/tests/unit/db/rdf/test_wiki.py index 5f36034..c737f29 100644 --- a/tests/unit/db/rdf/test_wiki.py +++ b/tests/unit/db/rdf/test_wiki.py @@ -29,8 +29,6 @@ from gn3.db.rdf.wiki import ( update_wiki_comment, ) - -SPARQL_CONF = get_sparql_auth_conf() GRAPH = "<http://cd-test.genenetwork.org>" @@ -187,8 +185,9 @@ def test_sanitize_result(result, expected): @pytest.mark.rdf -def test_get_wiki_entries_by_symbol(rdf_setup): # pylint: disable=W0613,W0621 +def test_get_wiki_entries_by_symbol(fxtr_app_config, rdf_setup): # pylint: disable=W0613,W0621 """Test that wiki entries are fetched correctly by symbol""" + SPARQL_CONF = get_sparql_auth_conf(fxtr_app_config) result = get_wiki_entries_by_symbol( symbol="ckb", sparql_uri=SPARQL_CONF["sparql_endpoint"], @@ -261,8 +260,9 @@ and C1QL3 (CTRP13).", @pytest.mark.rdf -def test_get_comment_history(rdf_setup): # pylint: disable=W0613,W0621 +def test_get_comment_history(fxtr_app_config, rdf_setup): # pylint: disable=W0613,W0621 """Test fetching a comment's history from RDF""" + SPARQL_CONF = get_sparql_auth_conf(fxtr_app_config) result = get_comment_history( comment_id=1158, sparql_uri=SPARQL_CONF["sparql_endpoint"], @@ -353,8 +353,9 @@ Possible 3' UTR variants.", @pytest.mark.rdf -def test_update_wiki_comment(rdf_setup): # pylint: disable=W0613,W0621 +def test_update_wiki_comment(fxtr_app_config, rdf_setup): # pylint: disable=W0613,W0621 """Test that a comment is updated correctly""" + SPARQL_CONF = get_sparql_auth_conf(fxtr_app_config) update_wiki_comment( insert_dict={ "Id": 230, |