def test_dynamic_root_parent(self): raml_resource = Mock(path='/foobar/{id}') parent_resource = Mock(is_root=True) config = config_mock() with pytest.raises(Exception) as ex: generators.generate_resource( config, raml_resource, parent_resource) expected = ("Top-level resources can't be dynamic and must " "represent collections instead") assert str(ex.value) == expected
def test_full_run_singular( self, generate_view, view_attrs, generate_acl, get_model, attr_res, singular_res, mock_dyn): mock_dyn.return_value = 'fooid' model_cls = Mock() model_cls.pk_field.return_value = 'my_id' attr_res.return_value = False singular_res.return_value = True get_model.return_value = model_cls raml_resource = Mock(path='/stories') parent_resource = Mock(is_root=False, uid=1) parent_resource.view.Model.pk_field.return_value = 'other_id' config = config_mock() res = generators.generate_resource( config, raml_resource, parent_resource) get_model.assert_called_once_with('Story') generate_acl.assert_called_once_with( config, model_cls=parent_resource.view.Model, raml_resource=raml_resource) assert not mock_dyn.called view_attrs.assert_called_once_with(raml_resource, True) generate_view.assert_called_once_with( config, model_cls=parent_resource.view.Model, attrs=view_attrs(), attr_view=False, singular=True ) parent_resource.add.assert_called_once_with( 'story', factory=generate_acl(), view=generate_view() ) assert res == parent_resource.add()
def test_dynamic_not_root_parent(self): raml_resource = Mock(path='/foobar/{id}') parent_resource = Mock(is_root=False) config = config_mock() new_resource = generators.generate_resource( config, raml_resource, parent_resource) assert new_resource is None
def test_full_run_singular(self, generate_view, view_attrs, generate_acl, get_model, attr_res, singular_res, mock_dyn): mock_dyn.return_value = 'fooid' model_cls = Mock() model_cls.pk_field.return_value = 'my_id' attr_res.return_value = False singular_res.return_value = True get_model.return_value = model_cls raml_resource = Mock(path='/stories') parent_resource = Mock(is_root=False, uid=1) parent_resource.view.Model.pk_field.return_value = 'other_id' config = config_mock() res = generators.generate_resource(config, raml_resource, parent_resource) get_model.assert_called_once_with('Story') generate_acl.assert_called_once_with( config, model_cls=parent_resource.view.Model, raml_resource=raml_resource) assert not mock_dyn.called view_attrs.assert_called_once_with(raml_resource, True) generate_view.assert_called_once_with( config, model_cls=parent_resource.view.Model, attrs=view_attrs(), attr_view=False, singular=True) parent_resource.add.assert_called_once_with('story', factory=generate_acl(), view=generate_view()) assert res == parent_resource.add()
def test_full_run(self, generate_view, view_attrs, generate_acl, get_model, attr_res, singular_res, mock_dyn): mock_dyn.return_value = 'fooid' model_cls = Mock() model_cls.pk_field.return_value = 'my_id' attr_res.return_value = False singular_res.return_value = False get_model.return_value = model_cls raml_resource = Mock(path='/stories') parent_resource = Mock(is_root=False, uid=1) config = config_mock() res = generators.generate_resource(config, raml_resource, parent_resource) get_model.assert_called_once_with('Story') generate_acl.assert_called_once_with(config, model_cls=model_cls, raml_resource=raml_resource) mock_dyn.assert_called_once_with(raml_resource=raml_resource, clean_uri='stories', pk_field='my_id') view_attrs.assert_called_once_with(raml_resource, False) generate_view.assert_called_once_with(config, model_cls=model_cls, attrs=view_attrs(), attr_view=False, singular=False) parent_resource.add.assert_called_once_with('story', 'stories', id_name='fooid', factory=generate_acl(), view=generate_view()) assert res == parent_resource.add()
def test_dynamic_not_root_parent(self): raml_resource = Mock(path='/foobar/{id}') parent_resource = Mock(is_root=False) config = config_mock() new_resource = generators.generate_resource(config, raml_resource, parent_resource) assert new_resource is None
def test_full_run( self, generate_view, view_attrs, generate_acl, get_model, attr_res, singular_res, mock_dyn): mock_dyn.return_value = 'fooid' model_cls = Mock() model_cls.pk_field.return_value = 'my_id' attr_res.return_value = False singular_res.return_value = False get_model.return_value = model_cls raml_resource = Mock(path='/stories') parent_resource = Mock(is_root=False, uid=1) config = config_mock() res = generators.generate_resource( config, raml_resource, parent_resource) get_model.assert_called_once_with('Story') generate_acl.assert_called_once_with( config, model_cls=model_cls, raml_resource=raml_resource) mock_dyn.assert_called_once_with( raml_resource=raml_resource, route_name='stories', pk_field='my_id') view_attrs.assert_called_once_with(raml_resource, False) generate_view.assert_called_once_with( config, model_cls=model_cls, attrs=view_attrs(), attr_view=False, singular=False ) parent_resource.add.assert_called_once_with( 'story', 'stories', id_name='fooid', factory=generate_acl(), view=generate_view() ) assert res == parent_resource.add()