forked from UCL-COMP0233-24-25/time-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Using mock testing to test the new API calling function.
- Loading branch information
am1520x
committed
Oct 30, 2024
1 parent
4cce632
commit 8ee35d1
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |