From 0bdaf9b49bb5343808593e9f6c9b040049253b04 Mon Sep 17 00:00:00 2001
From: Carsten Hinz <c.hinz@fz-juelich.de>
Date: Mon, 17 Jun 2024 14:23:31 +0200
Subject: [PATCH] added test function created by github copilot... see it as an
 experiment

---
 tests/test_setupFunctions.py | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 tests/test_setupFunctions.py

diff --git a/tests/test_setupFunctions.py b/tests/test_setupFunctions.py
new file mode 100644
index 0000000..3201f53
--- /dev/null
+++ b/tests/test_setupFunctions.py
@@ -0,0 +1,35 @@
+
+"""! the following test was created with the github copilot.
+"""
+
+from unittest import mock
+import pytest
+import json
+from toargridding.setupFunctions import updateTOARVariables
+
+@mock.patch("toargridding.setupFunctions.requests.get")
+@mock.patch("toargridding.setupFunctions.json.dump")
+def test_updateTOARVariables(mock_json_dump, mock_requests_get):
+    # Arrange
+    mock_response = mock.Mock()
+    mock_response.json.return_value = {"test": "data"}
+    mock_requests_get.return_value = mock_response
+
+    # Act
+    updateTOARVariables()
+
+    # Assert
+    mock_requests_get.assert_called_once_with("https://toar-data.fz-juelich.de/api/v2/variables/?limit=None")
+    mock_json_dump.assert_called_once_with({"test": "data"}, mock.ANY, indent=2)
+
+@mock.patch("toargridding.setupFunctions.requests.get")
+def test_updateTOARVariables_api_failure(mock_requests_get):
+    # Arrange
+    mock_response = mock.Mock()
+    mock_response.raise_for_status.side_effect = Exception("API request failed")
+    mock_requests_get.return_value = mock_response
+
+    # Act & Assert
+    with pytest.raises(Exception) as e:
+        updateTOARVariables()
+    assert str(e.value) == "API request failed"
\ No newline at end of file
-- 
GitLab