aboutsummaryrefslogtreecommitdiff
path: root/tests/fixtures/rdf.py
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-09-30 11:02:37 +0300
committerBonfaceKilz2024-10-02 06:59:11 +0300
commit225f1f0976bbf3e0193cb935451a1c4ae76c77d9 (patch)
treeab88789546207a7146a9c7cecd00cc7510655da3 /tests/fixtures/rdf.py
parent04dc9fbcbce400265a916e8a60d358a26a22cb0b (diff)
downloadgenenetwork3-225f1f0976bbf3e0193cb935451a1c4ae76c77d9.tar.gz
Set a default password for sparql.
* tests/fixtures/rdf.py: Import config. (get_sparql_auth_conf): Load GN3 config from GN3_SECRETS and GN3_CONF if the respective envs are set. Set sane defaults for sparql_conf. (rdf_setup): Remove "fxtr_app_config". * tests/unit/db/rdf/test_wiki.py (test_get_wiki_entries_by_symbol): Ditto. (test_get_comment_history): Ditto. (test_update_wiki_comment): Ditto. Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'tests/fixtures/rdf.py')
-rw-r--r--tests/fixtures/rdf.py43
1 files changed, 34 insertions, 9 deletions
diff --git a/tests/fixtures/rdf.py b/tests/fixtures/rdf.py
index 9bf297b..028ef8d 100644
--- a/tests/fixtures/rdf.py
+++ b/tests/fixtures/rdf.py
@@ -1,19 +1,44 @@
"""Test fixtures to set up a test named graph for loading RDF data."""
import os
+from flask import config
import pytest
import requests
from requests.auth import HTTPDigestAuth
-def get_sparql_auth_conf(config_obj) -> dict:
- """Fetch SPARQL auth configuration from the configuration object."""
+def get_sparql_auth_conf() -> dict:
+ """Fetch SPARQL auth configuration from the configurafrom flask
+ import configuration object."""
+ # When loading from the environment, GN3_CONF precedes
+ # GN3_SECRETS. Don't change this order.
+ 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 os.environ.get("GN3_SECRETS"):
+ sparql_conf.from_envvar("GN3_SECRETS")
+ # If the sparql configurations aren't loaded, set sane defaults.
+ # This way, the genenetwork3 package builds.
return {
- "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"],
+ "sparql_user": sparql_conf.get("SPARQL_USER", "dba"),
+ "sparql_auth_uri": sparql_conf.get(
+ "SPARQL_AUTH_URI", "http://localhost:8890/sparql-auth/"
+ ),
+ "sparql_crud_auth_uri": sparql_conf.get(
+ "SPARQL_CRUD_AUTH_URI", "http://localhost:8890/sparql-graph-crud-auth"
+ ),
+ "sparql_endpoint": sparql_conf.get("SPARQL_ENDPOINT", "http://localhost:8890"),
+ "sparql_password": sparql_conf.get("SPARQL_PASSWORD", "dba"),
}
@@ -21,10 +46,10 @@ def get_sparql_auth_conf(config_obj) -> dict:
# This is not idempotent. Consider having a special virtuoso instance
# just for running tests.
@pytest.fixture(scope="module")
-def rdf_setup(fxtr_app_config):
+def rdf_setup():
"""Upload RDF to a Virtuoso named graph"""
# Define the URL and file
- sparql_conf = get_sparql_auth_conf(fxtr_app_config)
+ sparql_conf = get_sparql_auth_conf()
url = sparql_conf["sparql_crud_auth_uri"]
file_path = os.path.join(
os.path.dirname(__file__).split("fixtures")[0],