From 8ee35d1d813aa8e1ca54a58e33f626fa530ea4d5 Mon Sep 17 00:00:00 2001 From: am1520x Date: Wed, 30 Oct 2024 22:03:22 +0000 Subject: [PATCH] Answers UCL-COMP0233-24-25/RSE-Classwork#18 Using mock testing to test the new API calling function. --- test_iss.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test_iss.py diff --git a/test_iss.py b/test_iss.py new file mode 100644 index 0000000..80331cc --- /dev/null +++ b/test_iss.py @@ -0,0 +1,29 @@ +import pytest +import requests +from unittest.mock import patch +from times import iss_passes + +# Sample mock response data +mock_response_data = { + "passes": [ + {"startUTC": 1609459200, "endUTC": 1609459800}, + {"startUTC": 1609462800, "endUTC": 1609463400} + ] +} + +@patch('times.requests.get') +def test_iss_passes(mock_get): + # Configure the mock to return a response with our mock data + mock_get.return_value.json.return_value = mock_response_data + + api_key = "test_api_key" + lat = 56 + lon = 0 + result = iss_passes(api_key, lat, lon) + + expected = [ + ("2021-01-01 00:00:00", "2021-01-01 00:10:00"), + ("2021-01-01 01:00:00", "2021-01-01 01:10:00") + ] + + assert result == expected