def test_reset_reverts_count(self): url = 'mock://test/site/' matcher = adapter._Matcher('GET', url, [_MatcherResponse()], complete_qs=False, additional_matcher=None, request_headers={}, real_http=False, case_sensitive=False) request = adapter._RequestObjectProxy._create('GET', url) call_count = 3 for _ in range(call_count): matcher(request) self.assertEqual(matcher.call_count, call_count) matcher.reset() self.assertEqual(matcher.call_count, 0)
def register_uri(self, method, url, response_list=None, **kwargs): """Register a new URI match and fake response. :param str method: The HTTP method to match. :param str url: The URL to match. """ complete_qs = kwargs.pop('complete_qs', False) request_headers = kwargs.pop('request_headers', {}) if response_list and kwargs: raise RuntimeError('You should specify either a list of ' 'responses OR response kwargs. Not both.') elif not response_list: response_list = [kwargs] responses = [response._MatcherResponse(**k) for k in response_list] matcher = _Matcher(method, url, responses, complete_qs=complete_qs, request_headers=request_headers) self.add_matcher(matcher) return matcher
def register_uri(self, method, url, response_list=None, **kwargs): """Register a new URI match and fake response. :param str method: The HTTP method to match. :param str url: The URL to match. """ complete_qs = kwargs.pop('complete_qs', False) request_headers = kwargs.pop('request_headers', {}) if response_list and kwargs: raise RuntimeError('You should specify either a list of ' 'responses OR response kwargs. Not both.') elif not response_list: response_list = [kwargs] responses = [response._MatcherResponse(**k) for k in response_list] matcher = _Matcher(method, url, responses, complete_qs=complete_qs, request_headers=request_headers) self.add_matcher(matcher) return matcher
def register_uri(self, method, url, response_list=None, **kwargs): """Register a new URI match and fake response. :param str method: The HTTP method to match. :param str url: The URL to match. """ complete_qs = kwargs.pop('complete_qs', False) additional_matcher = kwargs.pop('additional_matcher', None) request_headers = kwargs.pop('request_headers', {}) real_http = kwargs.pop('_real_http', False) if response_list and kwargs: raise RuntimeError('You should specify either a list of ' 'responses OR response kwargs. Not both.') elif real_http and (response_list or kwargs): raise RuntimeError('You should specify either response data ' 'OR real_http. Not both.') elif not response_list: response_list = [] if real_http else [kwargs] # NOTE(jamielennox): case_sensitive is not present as a kwarg because i # think there would be an edge case where the adapter and register_uri # had different values. # Ideally case_sensitive would be a value passed to match() however # this would change the contract of matchers so we pass ito to the # proxy and the matcher seperately. responses = [_MatcherResponse(**k) for k in response_list] matcher = _Matcher(method, url, responses, case_sensitive=self._case_sensitive, complete_qs=complete_qs, additional_matcher=additional_matcher, request_headers=request_headers, real_http=real_http) self.add_matcher(matcher) return matcher
def register_uri(self, method, url, response_list=None, **kwargs): """Register a new URI match and fake response. :param str method: The HTTP method to match. :param str url: The URL to match. """ complete_qs = kwargs.pop('complete_qs', False) additional_matcher = kwargs.pop('additional_matcher', None) request_headers = kwargs.pop('request_headers', {}) real_http = kwargs.pop('_real_http', False) if response_list and kwargs: raise RuntimeError('You should specify either a list of ' 'responses OR response kwargs. Not both.') elif real_http and (response_list or kwargs): raise RuntimeError('You should specify either response data ' 'OR real_http. Not both.') elif not response_list: response_list = [] if real_http else [kwargs] # NOTE(jamielennox): case_sensitive is not present as a kwarg because i # think there would be an edge case where the adapter and register_uri # had different values. # Ideally case_sensitive would be a value passed to match() however # this would change the contract of matchers so we pass ito to the # proxy and the matcher separately. responses = [_MatcherResponse(**k) for k in response_list] matcher = _Matcher(method, url, responses, case_sensitive=self._case_sensitive, complete_qs=complete_qs, additional_matcher=additional_matcher, request_headers=request_headers, real_http=real_http) self.add_matcher(matcher) return matcher