From 3dd034c234e23388ca18525ea6431033dfc4aa8d Mon Sep 17 00:00:00 2001
From: Alexander Minges <alexander.minges@uni-due.de>
Date: Fri, 21 Mar 2025 16:06:28 +0100
Subject: [PATCH] Use example config for tests

---
 .forgejo/workflows/run_tests.yaml |  4 ----
 tests/config_test.yaml            | 23 +++++++++++++++++++++++
 tests/test_fetch_doi_mock.py      | 18 ++++++++++++------
 3 files changed, 35 insertions(+), 10 deletions(-)
 create mode 100644 tests/config_test.yaml

diff --git a/.forgejo/workflows/run_tests.yaml b/.forgejo/workflows/run_tests.yaml
index e19f51f..e84b670 100644
--- a/.forgejo/workflows/run_tests.yaml
+++ b/.forgejo/workflows/run_tests.yaml
@@ -18,10 +18,6 @@ jobs:
           pip install -r requirements.txt
           pip install -r requirements-dev.txt
 
-      - name: Copy example config
-        run: |
-          cp config_example.yaml config.yaml
-
       - name: Run tests
         run: |
           pytest
diff --git a/tests/config_test.yaml b/tests/config_test.yaml
new file mode 100644
index 0000000..e17f88d
--- /dev/null
+++ b/tests/config_test.yaml
@@ -0,0 +1,23 @@
+default_grant:
+  - funder: "Awesome Funding Agency"
+    id: "ABC12345"
+
+phase:
+  "Phase 1 (2021/2025)":
+    start: 2021
+    end: 2025
+
+pis:
+  - family_name: "Doe"
+    given_name: "Jon"
+    orcid: "0000-0000-0000-0000"
+    email: "jon.doe@iana.org"
+    affiliation: "Institute of Science, Some University"
+    project: ["Project A01"]
+
+  - family_name: "Doe"
+    given_name: "Jane"
+    orcid: "0000-0000-0000-0001"
+    email: "jane.doe@iana.org"
+    affiliation: "Institute of Science, Some University"
+    project: ["Project A02"]
diff --git a/tests/test_fetch_doi_mock.py b/tests/test_fetch_doi_mock.py
index a5de463..be892bd 100644
--- a/tests/test_fetch_doi_mock.py
+++ b/tests/test_fetch_doi_mock.py
@@ -1,12 +1,9 @@
 import json
 import os
-import sys
-
-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
 
 import pytest
 
-from doi2dataset import MetadataProcessor
+from doi2dataset import Config, MetadataProcessor
 
 
 class FakeResponse:
@@ -23,6 +20,15 @@ class FakeResponse:
     def raise_for_status(self):
         pass
 
+@pytest.fixture(autouse=True)
+def load_config_test():
+    """
+    Automatically load the configuration from 'config_test.yaml'
+    located in the same directory as this test file.
+    """
+    config_path = os.path.join(os.path.dirname(__file__), "config_test.yaml")
+    Config.load_config(config_path=config_path)
+
 @pytest.fixture
 def fake_openalex_response():
     """
@@ -38,8 +44,8 @@ def test_fetch_doi_data_with_file(mocker, fake_openalex_response):
     """
     Test fetching DOI metadata by simulating the API call with a locally saved JSON response.
 
-    The APIClient.make_request method is patched to return a fake response based on
-    the contents of 'srep45389.json', so that no actual network request is performed.
+    The APIClient.make_request method is patched to return a fake response built from the contents
+    of 'srep45389.json', ensuring that the configuration is loaded from 'config_test.yaml'.
     """
     doi = "10.1038/srep45389"
     fake_response = FakeResponse(fake_openalex_response, 200)