|
3 | 3 | from couchbase.exceptions import DocumentNotFoundException |
4 | 4 |
|
5 | 5 | from app.main import app |
6 | | -from app.routers.airport import _filter_complete_airports |
| 6 | +from app.routers.airport import get_airports_list |
7 | 7 |
|
8 | 8 | client = TestClient(app) |
9 | 9 |
|
10 | 10 |
|
11 | | -def test_filter_complete_airports_skips_incomplete_rows(): |
12 | | - complete_airport = { |
13 | | - "airportname": "Test Airport", |
14 | | - "city": "Test City", |
15 | | - "country": "Test Country", |
16 | | - "faa": "TAA", |
17 | | - } |
18 | | - incomplete_airport = { |
19 | | - "city": "Initial Test City", |
20 | | - "country": "Initial Test Country", |
21 | | - "faa": "TESTFAA", |
22 | | - } |
23 | | - |
24 | | - assert _filter_complete_airports([complete_airport, incomplete_airport]) == [ |
25 | | - complete_airport |
26 | | - ] |
| 11 | +class RecordingDB: |
| 12 | + def __init__(self, rows): |
| 13 | + self.rows = rows |
| 14 | + self.calls = [] |
| 15 | + |
| 16 | + def query(self, query, **params): |
| 17 | + self.calls.append((query, params)) |
| 18 | + return self.rows |
| 19 | + |
| 20 | + |
| 21 | +def test_list_airports_bakes_required_fields_into_the_query_before_pagination(): |
| 22 | + db = RecordingDB([]) |
| 23 | + |
| 24 | + assert get_airports_list(limit=3, offset=6, db=db) == [] |
| 25 | + |
| 26 | + query, params = db.calls[0] |
| 27 | + assert "airport.airportname IS NOT MISSING" in query |
| 28 | + assert "airport.airportname IS NOT NULL" in query |
| 29 | + assert "airport.city IS NOT MISSING" in query |
| 30 | + assert "airport.city IS NOT NULL" in query |
| 31 | + assert "airport.country IS NOT MISSING" in query |
| 32 | + assert "airport.country IS NOT NULL" in query |
| 33 | + assert "ORDER BY airport.airportname" in query |
| 34 | + assert "LIMIT $limit" in query |
| 35 | + assert "OFFSET $offset" in query |
| 36 | + assert params == {"country": None, "limit": 3, "offset": 6} |
| 37 | + |
| 38 | + |
| 39 | +def test_list_airports_bakes_country_filter_into_the_query_when_present(): |
| 40 | + db = RecordingDB([]) |
| 41 | + |
| 42 | + assert get_airports_list(country="France", limit=2, offset=4, db=db) == [] |
| 43 | + |
| 44 | + query, params = db.calls[0] |
| 45 | + assert "WHERE airport.country = $country" in query |
| 46 | + assert "airport.airportname IS NOT MISSING" in query |
| 47 | + assert params == {"country": "France", "limit": 2, "offset": 4} |
27 | 48 |
|
28 | 49 |
|
29 | 50 | class TestAirport: |
|
0 commit comments