示例#1
0
    def test_full_run_singular(
            self, generate_view, view_attrs, generate_acl, get_model,
            attr_res, singular_res):
        attr_res.return_value = False
        singular_res.return_value = True
        config = Mock()
        resource = Mock(resources={})
        parent_resource = Mock(uid=1)
        parent_resource.view.Model.pk_field.return_value = 'other_id'

        generators.configure_resources(
            config, raml_resources={'/stories': resource},
            parsed_raml='foo', parent_resource=parent_resource)

        singular_res.assert_called_once_with(resource, 'stories')
        attr_res.assert_called_once_with(resource, 'stories')
        get_model.assert_called_once_with('Story')
        generate_acl.assert_called_once_with(
            context_cls=parent_resource.view.Model,
            raml_resource=resource,
            parsed_raml='foo'
        )
        view_attrs.assert_called_once_with(resource, True)
        generate_view.assert_called_once_with(
            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 generate_view()._singular_model == get_model()
示例#2
0
 def test_dynamic_resource(self, mock_singular):
     resource = Mock(resources={})
     parent_resource = Mock(uid=1)
     generators.configure_resources(
         None, raml_resources={'/{id}': resource},
         parsed_raml='', parent_resource=parent_resource)
     assert not mock_singular.called
示例#3
0
 def test_no_raml_resources(self, mock_rest):
     config = Mock()
     generators.configure_resources(
         config, raml_resources={}, parsed_raml='',
         parent_resource=None)
     assert not config.get_root_resource.called
     assert not mock_rest.called
示例#4
0
 def test_root_dynamic_resource(self, mock_singular):
     config = Mock()
     resource = Mock(resource={})
     with pytest.raises(Exception) as ex:
         generators.configure_resources(
             config, raml_resources={'/{id}': resource},
             parsed_raml='', parent_resource=None)
     assert "Top-level resources can't be dynamic" in str(ex.value)
     assert not mock_singular.called
示例#5
0
 def test_no_parent_not_restful_uri(self):
     config = Mock()
     with pytest.raises(ValueError) as ex:
         generators.configure_resources(
             config, raml_resources={'/foo/bar': ''},
             parsed_raml='', parent_resource=None)
     expected = 'Resource URI `/foo/bar` is not RESTful'
     assert str(ex.value) == expected
     config.get_root_resource.assert_called_once_with()
示例#6
0
    def test_full_run(
            self, generate_view, view_attrs, generate_acl, get_model,
            attr_res, singular_res):
        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
        config = Mock()
        resource = Mock(resources={})
        parent_resource = Mock(uid=1)

        generators.configure_resources(
            config, raml_resources={'/stories': resource},
            parsed_raml='foo', parent_resource=parent_resource)

        singular_res.assert_called_once_with(resource, 'stories')
        attr_res.assert_called_once_with(resource, 'stories')
        get_model.assert_called_once_with('Story')
        generate_acl.assert_called_once_with(
            context_cls=model_cls,
            raml_resource=resource,
            parsed_raml='foo'
        )
        view_attrs.assert_called_once_with(resource, False)
        generate_view.assert_called_once_with(
            model_cls=model_cls,
            attrs=view_attrs(),
            attr_view=False,
            singular=False
        )
        parent_resource.add.assert_called_once_with(
            'story', 'stories',
            id_name='stories_my_id',
            factory=generate_acl(),
            view=generate_view()
        )