/
test_amadeus.py
278 lines (204 loc) · 7.43 KB
/
test_amadeus.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import unittest
from datetime import datetime, timedelta
from amadeus.amadeus import (
Transport, Flights, Hotels, Cars, CO2Emissions, RailStations, Trains)
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock
API_URL = 'https://api.sandbox.amadeus.com/v1.2'
# Update the API KEY
API_KEY = 'xx5nE3UgOfRAwCFw9pw2WAwKiWojqMRR'
# mock if API Key is not available
if not API_KEY:
mock_return_value = ['flights', 'hotels', 'cars']
Transport.make_request = Mock(return_value=mock_return_value)
class AmadeusTestCase(unittest.TestCase):
def setUp(self):
self.api_key = API_KEY
datetime_format = '%Y-%m'
outbound_datetime = datetime.now() + timedelta(days=7)
inbound_datetime = outbound_datetime + timedelta(days=31)
self.outbound = outbound_datetime.strftime(datetime_format)
self.inbound = inbound_datetime.strftime(datetime_format)
datetime_format = '%Y-%m-%d'
inbound_datetime = outbound_datetime + timedelta(days=3)
self.departure_date = outbound_datetime.strftime(datetime_format)
self.return_date = inbound_datetime.strftime(datetime_format)
pass
def test_something(self):
pass
def tearDown(self):
pass
class TestTransport(AmadeusTestCase):
def test_get_location(self):
transport = Transport(self.api_key)
resp = transport.get_location('BKK')
self.assertTrue(len(resp) > 0)
class TestFlights(AmadeusTestCase):
def setUp(self):
super(TestFlights, self).setUp()
def test_inspiration_search(self):
flights = Flights(self.api_key)
origin = 'BKK'
departure_date = self.departure_date
return_date = self.return_date
max_price = 200
resp = flights.inspiration_search(
origin=origin,
departure_date="{departure_date}--{return_date}".format(
departure_date=departure_date, return_date=return_date),
max_price=max_price)
self.assertTrue(len(resp) > 0)
def test_extensive_search(self):
flights = Flights(self.api_key)
origin = 'NCE'
destination = 'LAS'
departure_date = self.departure_date
return_date = self.return_date
duration = '4--10'
resp = flights.extensive_search(
origin=origin,
destination=destination,
departure_date="{departure_date}--{return_date}".format(
departure_date=departure_date, return_date=return_date),
duration=duration)
print(resp)
self.assertTrue(len(resp) > 0)
def test_low_fare_search(self):
flights = Flights(self.api_key)
origin = 'NCE'
destination = 'LAS'
duration = '4--10'
resp = flights.low_fare_search(
origin=origin,
destination=destination,
departure_date=self.departure_date,
return_date=self.return_date,
duration=duration)
self.assertTrue(len(resp) > 0)
def test_auto_complete(self):
flights = Flights(self.api_key)
resp = flights.auto_complete(term='Ban')
self.assertTrue(len(resp) > 0)
class TestHotels(AmadeusTestCase):
def setUp(self):
super(TestHotels, self).setUp()
datetime_format = '%Y-%m-%d'
checkin_datetime = datetime.now()
checkout_datetime = checkin_datetime + timedelta(days=4)
self.check_in = checkin_datetime.strftime(datetime_format)
self.check_out = checkout_datetime.strftime(datetime_format)
def test_search_circle(self):
hotels = Hotels(self.api_key)
latitude = 16.44671
longitude = 102.833
currency = 'USD'
max_rate = 100
resp = hotels.search_circle(
check_in=self.check_in,
check_out=self.check_out,
latitude=latitude,
longitude=longitude,
currency=currency,
max_rate=max_rate,
radius=300)
self.assertTrue(len(resp) > 0)
def test_search_airport(self):
hotels = Hotels(self.api_key)
location = 'BKK'
currency = 'USD'
max_rate = 100
resp = hotels.search_airport(
check_in=self.check_in,
check_out=self.check_out,
location=location,
currency=currency,
max_rate=max_rate)
self.assertTrue(len(resp) > 0)
def test_search_property_code(self):
hotels = Hotels(self.api_key)
property_code = 'RTNCEPUL'
currency = 'USD'
max_rate = 100
resp = hotels.search_property_code(
check_in=self.check_in,
check_out=self.check_out,
property_code=property_code,
currency=currency,
max_rate=max_rate)
self.assertTrue(len(resp) > 0)
class TestCars(AmadeusTestCase):
def setUp(self):
super(TestCars, self).setUp()
datetime_format = '%Y-%m-%dT%H:%S'
pickup_datetime = datetime.now() + timedelta(days=10)
dropoff_datetime = pickup_datetime + timedelta(days=3)
self.pick_up = pickup_datetime.strftime(datetime_format)
self.drop_off = dropoff_datetime.strftime(datetime_format)
def test_search_airport(self):
cars = Cars(self.api_key)
currency = 'USD'
max_rate = 100
latitude = 16.44671
longitude = 102.833
location = 'BKK'
resp = cars.search_airport(
pick_up=self.pick_up,
drop_off=self.drop_off,
location=location,
currency=currency,
lang='EN')
self.assertTrue(len(resp) > 0)
def test_search_circle(self):
cars = Cars(self.api_key)
currency = 'USD'
max_rate = 100
latitude = 16.44671
longitude = 102.833
location = 'BKK'
resp = cars.search_circle(
pick_up=self.pick_up,
drop_off=self.drop_off,
latitude=latitude,
longitude=longitude,
radius=70,
currency=currency,
lang='EN')
self.assertTrue(len(resp) > 0)
class TestCO2Emissions(AmadeusTestCase):
def test_get_data(self):
co2 = CO2Emissions(self.api_key)
resp = co2.get_data(
origin='PAR',
destination='NYC')
self.assertTrue(len(resp) > 0)
class TestRailStations(AmadeusTestCase):
def test_auto_complete(self):
rails = RailStations(self.api_key)
resp = rails.auto_complete(term='VENT')
self.assertTrue(len(resp) > 0)
def test_nearest_relevant(self):
rails = RailStations(self.api_key)
resp = rails.nearest_relevant(latitude=41.89021, longitude=12.492231)
self.assertTrue(len(resp) > 0)
def test_get_info(self):
rails = RailStations(self.api_key)
resp = rails.get_info(id=8301700)
self.assertTrue(len(resp) > 0)
class TestTrains(AmadeusTestCase):
def test_extensive_search(self):
trains = Trains(self.api_key)
resp = trains.extensive_search(
origin=8399003,
destination=8308409,
departure_date=self.departure_date)
self.assertTrue(len(resp) > 0)
def test_schedule_search(self):
trains = Trains(self.api_key)
resp = trains.schedule_search(
origin=8302589,
departure_date=self.departure_date)
self.assertTrue(len(resp) > 0)
if __name__ == '__main__':
unittest.main()