1 # SPDX-License-Identifier: GPL-3.0-or-later
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2025 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
 
  17 class FakeError(BaseException):
 
  19     def __init__(self, msg, status):
 
  24         return f'{self.status} -- {self.msg}'
 
  27 FakeResponse = namedtuple('FakeResponse', ['status', 'output', 'content_type'])
 
  30 class FakeAdaptor(glue.ASGIAdaptor):
 
  32     def __init__(self, params=None, headers=None, config=None):
 
  33         self.params = params or {}
 
  34         self.headers = headers or {}
 
  35         self._config = config or Configuration(None)
 
  37     def get(self, name, default=None):
 
  38         return self.params.get(name, default)
 
  40     def get_header(self, name, default=None):
 
  41         return self.headers.get(name, default)
 
  43     def error(self, msg, status=400):
 
  44         return FakeError(msg, status)
 
  46     def create_response(self, status, output, num_results):
 
  47         return FakeResponse(status, output, self.content_type)
 
  58     def query_stats(self):