def test_unregistered_renderer_error(self): with self.assertRaisesRegexp(ValueError, r'renderer.*not.*registered'): DefaultStreamViewBase.concrete_view_class( resource_id='some_resource_id', renderers=frozenset({'some_unregistered'}), data_spec=sen.data_spec, data_backend_api_method='some_method_name', adjust_exc=sen.adjust_exc)
def test_with_kwargs(self, *args): result = DefaultStreamViewBase.concrete_view_class( resource_id='some_resource_id', renderers=frozenset({'some'}), data_spec=sen.data_spec, data_backend_api_method='some_method_name', adjust_exc=sen.adjust_exc) self._basic_asserts(result)
def test_with_args(self, *args): result = DefaultStreamViewBase.concrete_view_class( 'some_resource_id', frozenset({'some'}), sen.data_spec, 'some_method_name', sen.adjust_exc) self._basic_asserts(result)
def setUp(self): self.data_spec = MagicMock() self.data_spec.clean_result_dict.side_effect = self.cleaned_list = [ sen.cleaned_result_dict_1, sen.cleaned_result_dict_2, sen.cleaned_result_dict_3, ] SomeAdjustedExc = self.SomeAdjustedExc patcher = patch( 'n6sdk.pyramid_commons._pyramid_commons.DefaultStreamViewBase.adjust_exc', side_effect=(lambda exc: SomeAdjustedExc(exc))) self.adjust_exc = patcher.start() self.addCleanup(patcher.stop) self.request = MagicMock() self.request.registry.data_backend_api.my_api_method = (sen.api_method) with patch( 'n6sdk.pyramid_commons._pyramid_commons.registered_stream_renderers', new={'some': MagicMock()}): self.cls = DefaultStreamViewBase.concrete_view_class( resource_id='/some/resource.id', config=sen.configurator, renderers=frozenset({'some'}), data_spec=self.data_spec, data_backend_api_method='my_api_method') self.cls._get_renderer_name = (lambda self: 'some') self.cls.call_api_method = MagicMock() self.cls.call_api_method.return_value = self.call_iter = iter([ sen.result_dict_1, sen.result_dict_2, sen.result_dict_3, ]) self.cls.get_clean_result_dict_kwargs = MagicMock( return_value={'kwarg': sen.kwarg}) self.obj = self.cls(sen.context, self.request) self.results = []
def setUp(self): self.data_spec = MagicMock() self.data_spec.clean_result_dict.side_effect = self.cleaned_list = [ sen.cleaned_result_dict_1, sen.cleaned_result_dict_2, sen.cleaned_result_dict_3, ] SomeAdjustedExc = self.SomeAdjustedExc self.adjust_exc = MagicMock( side_effect=(lambda exc: SomeAdjustedExc(exc))) self.request = MagicMock() self.request.registry.data_backend_api.my_api_method = ( sen.api_method) with patch('n6sdk.pyramid_commons.registered_stream_renderers', new={'some': MagicMock()}): self.cls = DefaultStreamViewBase.concrete_view_class( resource_id='some_resource_id', renderers=frozenset({'some'}), data_spec=self.data_spec, data_backend_api_method='my_api_method', adjust_exc=self.adjust_exc) self.cls._get_renderer_name = (lambda self: 'some') self.cls.call_api_method = MagicMock() self.cls.call_api_method.return_value = self.call_iter = iter([ sen.result_dict_1, sen.result_dict_2, sen.result_dict_3, ]) self.cls.get_clean_result_dict_kwargs = MagicMock( return_value={'kwarg': sen.kwarg}) self.obj = self.cls(sen.context, self.request) self.results = []
def test_with_renderers_as_str(self, *args): result = DefaultStreamViewBase.concrete_view_class( **dict(self._KWARGS_BASE, renderers='some')) self._basic_asserts(result)
def test_ok(self): url_pattern = self.prefix + '.{renderer}' none = DefaultStreamViewBase.validate_url_pattern(url_pattern) self.assertIsNone(none)
def _test_error(self, url_pattern): with self.assertRaises(HTTPServerError): DefaultStreamViewBase.validate_url_pattern(url_pattern)
def test_for_DefaultStreamViewBase(self): self.assertEqual(DefaultStreamViewBase.get_default_http_methods(), 'GET')
def test_unregistered_renderer_error(self): with self.assertRaisesRegexp(ValueError, r'renderer.*not.*registered'): DefaultStreamViewBase.concrete_view_class( **dict(self._KWARGS_BASE, renderers=['some_unregistered']))
def test_with_renderers_as_iterable_of_str(self, *args): result = DefaultStreamViewBase.concrete_view_class(**self._KWARGS_BASE) self._basic_asserts(result)