-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flight_data_retriever.py
47 lines (36 loc) · 1.48 KB
/
test_flight_data_retriever.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
import unittest
from unittest.mock import MagicMock, patch
sys.path.insert(0, os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')
))
from src.flight_data_retriever import FlightDataRetriever
class TestFlightDataRetriever(unittest.TestCase):
def setUp(self):
self.api_endpoint = ("https://www.flightradar24.com/"
"flights/most-tracked")
self.headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/39.0.2171.95 Safari/537.36'
}
@patch('flight_data_retriever.requests.get')
def test_retrieve_flight_data(self, mock_get):
# Mock the response
mock_response = MagicMock()
mock_response.text = (
'{"data": [{"flight_id": "123", "callsign": "ABC"}]}'
)
mock_get.return_value = mock_response
# Create an instance of the FlightDataRetriever
flight_data_retriever = FlightDataRetriever(
self.api_endpoint, self.headers
)
# Call the method under test
flight_data = flight_data_retriever.retrieve_flight_data()
# Assert the expected behavior
self.assertEqual(flight_data.iloc[0]['flight_id'], '123')
self.assertEqual(flight_data.iloc[0]['callsign'], 'ABC')
if __name__ == '__main__':
unittest.main()