1 # SPDX-License-Identifier: GPL-3.0-or-later
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2024 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Provides dummy implementations of ASGIAdaptor for testing.
10 from collections import namedtuple
12 import nominatim_api.v1.server_glue as glue
13 from nominatim_api.v1.format import dispatch as formatting
14 from nominatim_api.config import Configuration
16 class FakeError(BaseException):
18 def __init__(self, msg, status):
23 return f'{self.status} -- {self.msg}'
25 FakeResponse = namedtuple('FakeResponse', ['status', 'output', 'content_type'])
27 class FakeAdaptor(glue.ASGIAdaptor):
29 def __init__(self, params=None, headers=None, config=None):
30 self.params = params or {}
31 self.headers = headers or {}
32 self._config = config or Configuration(None)
35 def get(self, name, default=None):
36 return self.params.get(name, default)
39 def get_header(self, name, default=None):
40 return self.headers.get(name, default)
43 def error(self, msg, status=400):
44 return FakeError(msg, status)
47 def create_response(self, status, output, num_results):
48 return FakeResponse(status, output, self.content_type)