Skip to content
Snippets Groups Projects
Commit 0bdaf9b4 authored by Carsten Hinz's avatar Carsten Hinz
Browse files

added test function created by github copilot... see it as an experiment

parent 849fc4df
No related branches found
No related tags found
3 merge requests!11Creation of first beta release version,!10change in metadata of notebook,!9change in metadata of notebook
"""! 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment