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.config import Configuration
15 class FakeError(BaseException):
17 def __init__(self, msg, status):
22 return f'{self.status} -- {self.msg}'
24 FakeResponse = namedtuple('FakeResponse', ['status', 'output', 'content_type'])
26 class FakeAdaptor(glue.ASGIAdaptor):
28 def __init__(self, params=None, headers=None, config=None):
29 self.params = params or {}
30 self.headers = headers or {}
31 self._config = config or Configuration(None)
34 def get(self, name, default=None):
35 return self.params.get(name, default)
38 def get_header(self, name, default=None):
39 return self.headers.get(name, default)
42 def error(self, msg, status=400):
43 return FakeError(msg, status)
46 def create_response(self, status, output, num_results):
47 return FakeResponse(status, output, self.content_type)
50 def base_uri(self) -> str: