def test_only_provided_attrs_are_available(self, run_init, mock_eng): view_cls = views.generate_rest_view( model_cls='foo', attrs=['show', 'foobar'], es_based=True, attr_view=False, singular=False) assert issubclass(view_cls, views.ESCollectionView) request = Mock(**ViewTestBase.request_kwargs) view = view_cls(request=request, **ViewTestBase.view_kwargs) assert not hasattr(view_cls, 'foobar') try: view.show() except JHTTPMethodNotAllowed: raise Exception('Unexpected error') except Exception: pass with pytest.raises(JHTTPMethodNotAllowed): view.delete_many() with pytest.raises(JHTTPMethodNotAllowed): view.create() with pytest.raises(JHTTPMethodNotAllowed): view.delete() with pytest.raises(JHTTPMethodNotAllowed): view.update_many() with pytest.raises(JHTTPMethodNotAllowed): view.index()
def test_default_values(self, mock_eng): view_cls = views.generate_rest_view( model_cls='foo', attrs=['show']) assert issubclass(view_cls, views.ESCollectionView) assert issubclass(view_cls, views.CollectionView) assert view_cls._model_class == 'foo' assert view_cls._json_encoder == mock_eng.JSONEncoder
def test_only_provided_attrs_are_available(self, run_init): config = config_mock() view_cls = views.generate_rest_view(config, model_cls='foo', attrs=['show', 'foobar'], es_based=True, attr_view=False, singular=False) view_cls._json_encoder = 'foo' assert issubclass(view_cls, views.ESCollectionView) request = Mock(**ViewTestBase.request_kwargs) view = view_cls(request=request, **ViewTestBase.view_kwargs) assert not hasattr(view_cls, 'foobar') try: view.show() except JHTTPMethodNotAllowed: raise Exception('Unexpected error') except Exception: pass with pytest.raises(JHTTPMethodNotAllowed): view.delete_many() with pytest.raises(JHTTPMethodNotAllowed): view.create() with pytest.raises(JHTTPMethodNotAllowed): view.delete() with pytest.raises(JHTTPMethodNotAllowed): view.update_many() with pytest.raises(JHTTPMethodNotAllowed): view.index()
def test_attribute_view(self): config = config_mock() view_cls = views.generate_rest_view( config, model_cls='foo', attrs=['show'], es_based=True, attr_view=True, singular=False) view_cls._json_encoder = 'foo' assert issubclass(view_cls, views.ItemAttributeView)
def test_default_values(self): config = config_mock() view_cls = views.generate_rest_view( config, model_cls='foo', attrs=['show']) view_cls._json_encoder = 'foo' assert issubclass(view_cls, views.ESCollectionView) assert issubclass(view_cls, views.CollectionView) assert view_cls.Model == 'foo'
def test_dbcollection_view(self): config = config_mock() view_cls = views.generate_rest_view( config, model_cls='foo', attrs=['show'], es_based=False, attr_view=False, singular=False) view_cls._json_encoder = 'foo' assert not issubclass(view_cls, views.ESCollectionView) assert issubclass(view_cls, views.CollectionView)
def test_database_acls_option(self): from nefertari_guards.view import ACLFilterViewMixin config = config_mock() config.registry.database_acls = False view_cls = views.generate_rest_view( config, model_cls='foo', attrs=['show'], es_based=False, attr_view=False, singular=False) assert not issubclass( view_cls, ACLFilterViewMixin) assert not issubclass( view_cls, views.SetObjectACLMixin) config.registry.database_acls = True view_cls = views.generate_rest_view( config, model_cls='foo', attrs=['show'], es_based=False, attr_view=False, singular=False) assert issubclass(view_cls, views.SetObjectACLMixin) assert issubclass(view_cls, ACLFilterViewMixin)
def test_dbcollection_view(self, mock_eng): view_cls = views.generate_rest_view( model_cls='foo', attrs=['show'], es_based=False, attr_view=False, singular=False) assert not issubclass(view_cls, views.ESCollectionView) assert issubclass(view_cls, views.CollectionView)
def test_attribute_view(self, mock_eng): view_cls = views.generate_rest_view( model_cls='foo', attrs=['show'], es_based=True, attr_view=True, singular=False) assert issubclass(view_cls, views.ItemAttributeView)