From f0be9b6a1577a327909b3c8fe7c90eee85d402f3 Mon Sep 17 00:00:00 2001 From: Philip Feairheller Date: Sun, 7 Apr 2024 19:28:06 -0700 Subject: [PATCH] Update tests to ensure config files are accessed from absolute paths, not relative to where the test is being run. (#227) Signed-off-by: pfeairheller --- src/keria/testing/testing_helper.py | 5 ++- tests/app/test_agenting.py | 11 ++++--- tests/app/test_aiding.py | 5 +-- tests/testing/test_testing_helper.py | 47 ---------------------------- 4 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 tests/testing/test_testing_helper.py diff --git a/src/keria/testing/testing_helper.py b/src/keria/testing/testing_helper.py index e6cece6e..48521464 100644 --- a/src/keria/testing/testing_helper.py +++ b/src/keria/testing/testing_helper.py @@ -4,6 +4,7 @@ """ import json import os +import pathlib import shutil from contextlib import contextmanager @@ -23,6 +24,8 @@ from keria.app import agenting, indirecting +SCRIPTS_DIR = str(pathlib.Path(str(pathlib.Path(__file__).parent.resolve()), "../../../tests/scripts").resolve()) + WitnessUrls = { "wan:tcp": "tcp://127.0.0.1:5632/", "wan:http": "http://127.0.0.1:5642/", @@ -521,7 +524,7 @@ def openKeria(salter=None, cf=None, temp=True): salter = coring.Salter(raw=salt) if cf is None: - cf = configing.Configer(name="keria", headDirPath="tests/scripts", reopen=True, clear=False) + cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, reopen=True, clear=False) with habbing.openHby(name="keria", salt=salter.qb64, temp=temp, cf=cf) as hby: ims = eventing.messagize(serder, sigers=sigers) diff --git a/tests/app/test_agenting.py b/tests/app/test_agenting.py index 42a05a56..ce604d93 100644 --- a/tests/app/test_agenting.py +++ b/tests/app/test_agenting.py @@ -26,6 +26,7 @@ from keria.app import agenting, aiding from keria.core import longrunning +from keria.testing.testing_helper import SCRIPTS_DIR def test_setup_no_http(): @@ -63,13 +64,13 @@ def test_load_ends(helpers): def test_agency(): salt = b'0123456789abcdef' salter = coring.Salter(raw=salt) - cf = configing.Configer(name="keria", headDirPath="scripts", temp=True, reopen=True, clear=False) + cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False) with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby: hab = hby.makeHab(name="test") agency = agenting.Agency(name="agency", base="", bran=None, temp=True, configFile="keria", - configDir="scripts") + configDir=SCRIPTS_DIR) assert agency.cf is not None assert agency.cf.path.endswith("scripts/keri/cf/keria.json") is True @@ -111,7 +112,7 @@ def test_agency(): shutil.rmtree(f'/usr/local/var/keri/adb/{base}') agency = agenting.Agency(name="agency", base=base, bran=None, configFile="keria", - configDir="scripts") + configDir=SCRIPTS_DIR) assert agency.cf is not None assert agency.cf.path.endswith("scripts/keri/cf/keria.json") is True @@ -126,7 +127,7 @@ def test_agency(): # Rcreate the agency to see if agent is reloaded from disk agency = agenting.Agency(name="agency", base=base, bran=None, configFile="keria", - configDir="scripts") + configDir=SCRIPTS_DIR) doist.enter(doers=[agency]) agent = agency.get(caid) @@ -199,7 +200,7 @@ def test_keystate_ends(helpers): caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" salt = b'0123456789abcdef' salter = coring.Salter(raw=salt) - cf = configing.Configer(name="keria", headDirPath="scripts", temp=True, reopen=True, clear=False) + cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False) with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby: hab = hby.makeHab(name="test") diff --git a/tests/app/test_aiding.py b/tests/app/test_aiding.py index 0c5bde34..b0a16b1c 100644 --- a/tests/app/test_aiding.py +++ b/tests/app/test_aiding.py @@ -26,6 +26,7 @@ from keria.app import aiding, agenting from keria.app.aiding import IdentifierOOBICollectionEnd, RpyEscrowCollectionEnd from keria.core import longrunning +from keria.testing.testing_helper import SCRIPTS_DIR def test_load_ends(helpers): @@ -1426,7 +1427,7 @@ def test_approve_delegation(helpers): caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" salt = b'0123456789abcdef' salter = coring.Salter(raw=salt) - cf = configing.Configer(name="keria", headDirPath="scripts", temp=True, reopen=True, clear=False) + cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False) with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby: hab = hby.makeHab(name="test") @@ -1506,7 +1507,7 @@ def test_rotation(helpers): caid = "ELI7pg979AdhmvrjDeam2eAO2SR5niCgnjAJXJHtJose" salt = b'0123456789abcdef' salter = coring.Salter(raw=salt) - cf = configing.Configer(name="keria", headDirPath="scripts", temp=True, reopen=True, clear=False) + cf = configing.Configer(name="keria", headDirPath=SCRIPTS_DIR, temp=True, reopen=True, clear=False) with habbing.openHby(name="keria", salt=salter.qb64, temp=True, cf=cf) as hby: hab = hby.makeHab(name="test") diff --git a/tests/testing/test_testing_helper.py b/tests/testing/test_testing_helper.py deleted file mode 100644 index 551f5366..00000000 --- a/tests/testing/test_testing_helper.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- encoding: utf-8 -*- -""" -KERIA -keria.app.testing.testing_helper module - -Testing the test helper -""" -from datetime import datetime - -import json -import os -import shutil - - -from keria.testing.testing_helper import Helpers - -dirs=['cf','db','ks','mbx','not','opr','reg','reg/agent-fake','rks'] -files=dict() -files['cf']='fake.json' - -def test_helper(): - helpers = Helpers() - pDir = "tmpUnitTestDir" - - if not os.path.exists(pDir): - os.mkdir(pDir) - assert True == os.path.exists(pDir) - helpers.remove_test_dirs("fake",pDir) - assert True == os.path.exists(pDir) - - for dir in dirs: - tDir = pDir+f"/{dir}" - if not os.path.exists(tDir): - os.mkdir(tDir) - if not os.path.exists(tDir+"/fake"): - os.mkdir(tDir+"/fake") - assert True == os.path.exists(tDir) - helpers.remove_test_dirs("fake",pDir) - assert False == os.path.exists(tDir+"/fake") - assert True == os.path.exists(pDir) - - shutil.rmtree(pDir) - -def test_helper_mocks(): - assert Helpers.mockNowUTC().strftime('%Y-%m-%dT%H:%M:%S') == "2021-01-01T00:00:00" - assert Helpers.mockNowIso8601() == "2021-06-27T21:26:21.233257+00:00" - assert Helpers.mockRandomNonce() == "A9XfpxIl1LcIkMhUSCCC8fgvkuX8gG9xK3SM-S8a8Y_U" \ No newline at end of file