Пример #1
0
 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)
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
 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)
Пример #6
0
    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 = []
Пример #7
0
    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 = []
Пример #8
0
 def test_with_renderers_as_str(self, *args):
     result = DefaultStreamViewBase.concrete_view_class(
         **dict(self._KWARGS_BASE, renderers='some'))
     self._basic_asserts(result)
Пример #9
0
 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']))
Пример #10
0
 def test_with_renderers_as_iterable_of_str(self, *args):
     result = DefaultStreamViewBase.concrete_view_class(**self._KWARGS_BASE)
     self._basic_asserts(result)
Пример #11
0
 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)