"""Test helper for mocking owsrequest requests.""" from owsrequest import request from owsrequest import test_utils import pytest METHODS = ['get', 'post', 'head', 'put', 'delete'] class OwsRequestMockBuilder: """Utility to build mocking setup for owsrequest.""" def __init__(self, mocker): """Initializer.""" self.specs = {method: [] for method in METHODS} self.mocker = mocker def add(self, spec_with_method): """Add a spec to the list of available methods.""" method = spec_with_method.pop('method') self.specs[method].append(spec_with_method) return self def apply(self): """Set up actual mock with added specs.""" for method in METHODS: specs = self.specs[method] requests = test_utils.mock_ows_requests(specs) self.mocker.patch.object(request, method, requests) @pytest.fixture def ows_request_mocker(mocker): """Fixture for mocking requests.""" return OwsRequestMockBuilder(mocker)