|
3 | 3 | from couchbase.exceptions import DocumentNotFoundException |
4 | 4 |
|
5 | 5 | from app.main import app |
6 | | -from app.routers.airport import get_airports_list |
7 | 6 |
|
8 | 7 | client = TestClient(app) |
9 | 8 |
|
10 | 9 |
|
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} |
48 | | - |
49 | | - |
50 | 10 | class TestAirport: |
51 | 11 | def test_add_airport( |
52 | 12 | self, couchbase_client, airport_api, airport_collection, helpers |
|
0 commit comments