Esempio n. 1
0
def test_model_no_conflict_different_apps():
    app_a = morepath.App()

    class A(object):
        pass

    a = app_a.model(model=A, path='a')

    @a
    def get_a():
        return A()

    app_b = morepath.App()

    b = app_b.model(model=A, path='a')

    @b
    def get_a_again():
        return A()

    c = Config()
    c.configurable(app_a)
    c.configurable(app_b)
    c.action(a, get_a)
    c.action(b, get_a_again)
    c.commit()
Esempio n. 2
0
def test_function_conflict():
    app = morepath.App()

    def func(a):
        pass

    class A(object):
        pass

    a = app.function(func, A)

    @a
    def a_func(arequest, model):
        pass

    a1 = app.function(func, A)

    @a1
    def a1_func(request, model):
        pass

    c = Config()
    c.configurable(app)
    c.action(a, a_func)
    c.action(a1, a1_func)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 3
0
def test_function_no_conflict_different_apps():
    app_a = morepath.App()
    app_b = morepath.App()

    def func(a):
        pass

    class A(object):
        pass

    a = app_a.function(func, A)
    a1 = app_b.function(func, A)

    @a
    def a_func(a):
        pass

    @a1
    def a1_func(a):
        pass

    c = Config()
    c.configurable(app_a)
    c.configurable(app_b)
    c.action(a, a_func)
    c.action(a1, a1_func)
    c.commit()
Esempio n. 4
0
def test_model_conflict():
    app = morepath.App()

    class A(object):
        pass

    a = app.model(model=A, path='a')

    @a
    def get_a():
        return A()

    b = app.model(model=A, path='a')

    @b
    def get_a_again():
        return A()

    c = Config()
    c.configurable(app)
    c.action(a, get_a)
    c.action(b, get_a_again)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 5
0
def test_function_no_conflict_different_apps():
    app_a = morepath.App()
    app_b = morepath.App()

    def func(a):
        pass

    class A(object):
        pass

    a = app_a.function(func, A)
    a1 = app_b.function(func, A)

    @a
    def a_func(a):
        pass

    @a1
    def a1_func(a):
        pass

    c = Config()
    c.action(a, a_func)
    c.action(a1, a1_func)
    c.commit()
Esempio n. 6
0
def test_model_path_conflict():
    app = morepath.App()

    class A(object):
        pass

    class B(object):
        pass

    a = app.model(model=A, path='a')

    @a
    def get_a():
        return A()

    b = app.model(model=B, path='a')

    @b
    def get_a_again():
        return A()

    c = Config()
    c.action(a, get_a)
    c.action(b, get_a_again)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 7
0
def test_function_conflict():
    app = morepath.App()

    def func(a):
        pass

    class A(object):
        pass

    a = app.function(func, A)

    @a
    def a_func(arequest, model):
        pass

    a1 = app.function(func, A)

    @a1
    def a1_func(request, model):
        pass

    c = Config()
    c.action(a, a_func)
    c.action(a1, a1_func)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 8
0
def test_path_conflict_with_variable():
    app = morepath.App()

    class A(object):
        pass

    class B(object):
        pass

    a = app.model(model=A, path='a/{id}')

    @a
    def get_a(id):
        return A()

    b = app.model(model=B, path='a/{id2}')

    @b
    def get_b(id):
        return B()

    c = Config()
    c.configurable(app)
    c.action(a, get_a)
    c.action(b, get_b)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 9
0
def test_no_path_conflict_with_variable_different_converters():
    app = morepath.App()

    class A(object):
        pass

    class B(object):
        pass

    a = app.model(model=A, path='a/{id:int}')

    @a
    def get_a(id):
        return A()

    b = app.model(model=B, path='a/{id:str}')

    @b
    def get_b(id):
        return B()

    c = Config()
    c.configurable(app)
    c.action(a, get_a)
    c.action(b, get_b)

    c.commit()
Esempio n. 10
0
def test_view_no_conflict_different_predicates():
    app = morepath.App()

    class Model(object):
        pass

    a = app.view(model=Model, name='a', request_method='GET')
    b = app.view(model=Model, name='a', request_method='POST')

    @a
    def a_view(request, model):
        pass

    @b
    def b_view(request, model):
        pass

    c = Config()
    c.action(a, a_view)
    c.action(b, b_view)
    c.commit()
Esempio n. 11
0
def test_root_conflict():
    app = morepath.App()

    a = app.root()

    @a
    class Root(object):
        pass

    b = app.root()

    @b
    class Something(object):
        pass

    c = Config()
    c.configurable(app)
    c.action(a, Root)
    c.action(b, Something)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 12
0
def test_root_no_conflict_different_apps():
    app_a = morepath.App()
    app_b = morepath.App()

    a = app_a.root()

    @a
    class Root(object):
        pass

    b = app_b.root()

    @b
    class Something(object):
        pass

    c = Config()
    c.configurable(app_a)
    c.configurable(app_b)
    c.action(a, Root)
    c.action(b, Something)
    c.commit()
Esempio n. 13
0
def test_imperative():
    setup()

    class Foo(object):
        pass

    @reg.generic
    def target():
        pass

    app = App()

    c = Config()
    c.action(app, app)
    foo = Foo()
    c.action(app.function(target), foo)
    c.commit()

    assert target.component(lookup=app.lookup()) is foo
Esempio n. 14
0
def test_root_no_conflict_different_apps():
    app_a = morepath.App()
    app_b = morepath.App()

    a = app_a.root()

    @a
    class Root(object):
        pass

    b = app_b.root()

    @b
    class Something(object):
        pass

    c = Config()
    c.action(a, Root)
    c.action(b, Something)
    c.commit()
Esempio n. 15
0
def test_basic_json():
    setup()
    basic.app.clear()

    config = Config()
    config.scan(basic)
    config.commit()

    c = Client(basic.app, Response)

    response = c.get('/foo/json')

    assert response.data == '{"id": "foo"}'
Esempio n. 16
0
def test_view_no_conflict_different_apps():
    app_a = morepath.App()
    app_b = morepath.App()

    class Model(object):
        pass

    a = app_a.view(model=Model, name='a')
    a1 = app_b.view(model=Model, name='a')

    @a
    def a_view(request, model):
        pass

    @a1
    def a1_view(request, model):
        pass

    c = Config()
    c.configurable(app_a)
    c.configurable(app_b)
    c.action(a, a_view)
    c.action(a1, a1_view)
    c.commit()
Esempio n. 17
0
def test_view_conflict_with_html():
    app = morepath.App()

    class Model(object):
        pass

    a = app.view(model=Model, name='a')
    a1 = app.html(model=Model, name='a')

    @a
    def a_view(request, model):
        pass

    @a1
    def a1_view(request, model):
        pass

    c = Config()
    c.configurable(app)
    c.action(a, a_view)
    c.action(a1, a1_view)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 18
0
def test_root_conflict():
    app = morepath.App()

    a = app.root()

    @a
    class Root(object):
        pass

    b = app.root()

    @b
    class Something(object):
        pass

    c = Config()
    c.action(a, Root)
    c.action(b, Something)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 19
0
def test_view_no_conflict_different_apps():
    app_a = morepath.App()
    app_b = morepath.App()

    class Model(object):
        pass

    a = app_a.view(model=Model, name='a')
    a1 = app_b.view(model=Model, name='a')

    @a
    def a_view(request, model):
        pass

    @a1
    def a1_view(request, model):
        pass

    c = Config()
    c.action(a, a_view)
    c.action(a1, a1_view)
    c.commit()
Esempio n. 20
0
def test_view_conflict_with_html():
    app = morepath.App()

    class Model(object):
        pass

    a = app.view(model=Model, name='a')
    a1 = app.html(model=Model, name='a')

    @a
    def a_view(request, model):
        pass

    @a1
    def a1_view(request, model):
        pass

    c = Config()
    c.action(a, a_view)
    c.action(a1, a1_view)

    with pytest.raises(ConflictError):
        c.commit()
Esempio n. 21
0
def test_basic():
    setup()
    basic.app.clear()

    config = Config()
    config.scan(basic)
    config.commit()

    c = Client(basic.app, Response)

    response = c.get('/foo')

    assert response.data == 'The view for model: foo'

    response = c.get('/foo/link')
    assert response.data == 'foo'
Esempio n. 22
0
def test_basic_root():
    setup()
    basic.app.clear()

    config = Config()
    config.scan(basic)
    config.commit()

    c = Client(basic.app, Response)

    response = c.get('/')

    assert response.data == 'The root: ROOT'

    # @@ is to make sure we get the view, not the sub-model
    response = c.get('/@@link')
    assert response.data == ''
Esempio n. 23
0
def test_nested():
    setup()
    nested.outer_app.clear()
    nested.app.clear()

    config = Config()
    config.scan(nested)
    config.commit()

    c = Client(nested.outer_app, Response)

    response = c.get('/inner/foo')

    assert response.data == 'The view for model: foo'

    response = c.get('/inner/foo/link')
    assert response.data == 'inner/foo'
Esempio n. 24
0
def test_model_no_conflict_different_apps():
    app_a = morepath.App()

    class A(object):
        pass

    a = app_a.model(model=A, path='a')

    @a
    def get_a():
        return A()

    app_b = morepath.App()

    b = app_b.model(model=A, path='a')

    @b
    def get_a_again():
        return A()

    c = Config()
    c.action(a, get_a)
    c.action(b, get_a_again)
    c.commit()
Esempio n. 25
0
def test_view_no_conflict_different_names():
    app = morepath.App()

    class Model(object):
        pass

    a = app.view(model=Model, name='a')
    b = app.view(model=Model, name='b')

    @a
    def a_view(request, model):
        pass

    @b
    def b_view(request, model):
        pass

    c = Config()
    c.configurable(app)
    c.action(a, a_view)
    c.action(b, b_view)
    c.commit()
Esempio n. 26
0
def test_view_no_conflict_different_predicates():
    app = morepath.App()

    class Model(object):
        pass

    a = app.view(model=Model, name='a', request_method='GET')
    b = app.view(model=Model, name='a', request_method='POST')

    @a
    def a_view(request, model):
        pass

    @b
    def b_view(request, model):
        pass

    c = Config()
    c.action(a, a_view)
    c.action(b, b_view)
    c.commit()
Esempio n. 27
0
def test_redirect():
    setup()

    app = morepath.App()

    class Root(object):
        def __init__(self):
            pass

    def default(request, model):
        return morepath.redirect('/')

    c = Config()
    c.action(app, app)
    c.action(app.root(),
             Root)
    c.action(app.view(model=Root, render=render_html),
             default)
    c.commit()

    c = Client(app, Response)

    response = c.get('/')
    assert response.status == '302 FOUND'
Esempio n. 28
0
def test_json_directive():
    setup()

    app = morepath.App()

    class Model(object):
        def __init__(self, id):
            self.id = id

    def default(request, model):
        return "The view for model: %s" % model.id

    def json(request, model):
        return {'id': model.id}

    c = Config()
    c.action(app, app)
    c.action(app.model(path='{id}',
                       variables=lambda model: {'id': model.id}),
             Model)
    c.action(app.json(model=Model),
             json)
    c.commit()

    c = Client(app, Response)

    response = c.get('/foo')
    assert response.data == '{"id": "foo"}'
Esempio n. 29
0
def test_basic_imperative():
    setup()

    app = morepath.App()

    class Root(object):
        def __init__(self):
            self.value = 'ROOT'

    class Model(object):
        def __init__(self, id):
            self.id = id

    def get_model(id):
        return Model(id)

    def default(request, model):
        return "The view for model: %s" % model.id

    def link(request, model):
        return request.link(model)

    def json(request, model):
        return {'id': model.id}

    def root_default(request, model):
        return "The root: %s" % model.value

    def root_link(request, model):
        return request.link(model)

    c = Config()
    c.action(app, app)
    c.action(app.root(), Root)
    c.action(app.model(model=Model, path='{id}',
                       variables=lambda model: {'id': model.id}),
             get_model)
    c.action(app.view(model=Model),
             default)
    c.action(app.view(model=Model, name='link'),
             link)
    c.action(app.view(model=Model, name='json',
                          render=morepath.render_json),
             json)
    c.action(app.view(model=Root),
             root_default)
    c.action(app.view(model=Root, name='link'),
             root_link)
    c.commit()

    c = Client(app, Response)

    response = c.get('/foo')
    assert response.data == 'The view for model: foo'

    response = c.get('/foo/link')
    assert response.data == 'foo'

    response = c.get('/foo/json')
    assert response.data == '{"id": "foo"}'

    response = c.get('/')
    assert response.data == 'The root: ROOT'

    # @@ is to make sure we get the view, not the sub-model
    response = c.get('/@@link')
    assert response.data == ''
Esempio n. 30
0
def test_base():
    setup()

    class Root(object):
        pass

    class Container(object):
        def __init__(self, id):
            self.id = id
            self.items = {}

        def add_item(self, item_id):
            result = Item(item_id, self)
            self.items[item_id] = result
            return result

    class Item(object):
        def __init__(self, id, parent):
            self.id = id
            self.parent = parent

    alpha = Container('alpha')
    beta = Container('beta')
    alpha.add_item('a')
    alpha.add_item('b')
    c = alpha.add_item('c')
    beta.add_item('d')
    e = beta.add_item('e')

    app = App()

    c = Config()
    c.action(app, app)
    c.action(app.root(), Root)

    def get_container(container_id):
        if container_id == 'alpha':
            return alpha
        elif container_id == 'beta':
            return beta
        return None

    c.action(
        app.model(model=Container,
                  path="{container_id}",
                  variables=lambda container: {'container_id': container.id}),
        get_container)

    def get_item(base, item_id):
        return base.items.get(item_id)

    c.action(
        app.model(model=Item,
                  path="{item_id}",
                  variables=lambda item: {'item_id': item.id},
                  base=Container,
                  get_base=lambda item: item.parent), get_item)

    c.action(app.view(model=Container),
             lambda request, model: 'container: %s' % model.id)
    c.action(app.view(model=Container, name='link'),
             lambda request, model: request.link(model))
    c.action(app.view(model=Item),
             lambda request, model: 'item: %s' % model.id)
    c.action(app.view(model=Item, name='link'),
             lambda request, model: request.link(model))
    c.action(app.view(model=Item, name='otherlink'),
             lambda request, model: request.link(e))
    c.commit()

    c = Client(app, Response)

    response = c.get('/alpha')
    assert response.data == 'container: alpha'
    response = c.get('/beta')
    assert response.data == 'container: beta'
    response = c.get('/alpha/a')
    assert response.data == 'item: a'
    response = c.get('/beta/e')
    assert response.data == 'item: e'
    response = c.get('/alpha/e')
    assert response.status == '404 NOT FOUND'

    response = c.get('/alpha/@@link')
    assert response.data == 'alpha'
    response = c.get('/alpha/a/link')
    assert response.data == 'alpha/a'
    response = c.get('/alpha/a/otherlink')
    assert response.data == 'beta/e'
Esempio n. 31
0
def test_view_predicates():
    setup()

    app = App()

    class Root(object):
        pass

    def get(request, model):
        return 'GET'

    def post(request, model):
        return 'POST'

    c = Config()
    c.action(app, app)
    c.action(app.root(), Root)
    c.action(app.view(model=Root, name='foo', request_method='GET'), get)
    c.action(app.view(model=Root, name='foo', request_method='POST'), post)

    c.commit()

    c = Client(app, Response)

    response = c.get('/foo')
    assert response.data == 'GET'
    response = c.post('/foo')
    assert response.data == 'POST'
Esempio n. 32
0
def test_view_predicates():
    setup()

    app = App()

    class Root(object):
        pass

    def get(request, model):
        return 'GET'

    def post(request, model):
        return 'POST'

    c = Config()
    c.action(app, app)
    c.action(app.root(), Root)
    c.action(app.view(model=Root, name='foo', request_method='GET'),
             get)
    c.action(app.view(model=Root, name='foo', request_method='POST'),
             post)

    c.commit()

    c = Client(app, Response)

    response = c.get('/foo')
    assert response.data == 'GET'
    response = c.post('/foo')
    assert response.data == 'POST'
Esempio n. 33
0
def test_base():
    setup()

    class Root(object):
        pass

    class Container(object):
        def __init__(self, id):
            self.id = id
            self.items = {}

        def add_item(self, item_id):
            result = Item(item_id, self)
            self.items[item_id] = result
            return result

    class Item(object):
        def __init__(self, id, parent):
            self.id = id
            self.parent = parent

    alpha = Container('alpha')
    beta = Container('beta')
    alpha.add_item('a')
    alpha.add_item('b')
    c = alpha.add_item('c')
    beta.add_item('d')
    e = beta.add_item('e')

    app = App()

    c = Config()
    c.action(app, app)
    c.action(app.root(), Root)

    def get_container(container_id):
        if container_id == 'alpha':
            return alpha
        elif container_id == 'beta':
            return beta
        return None

    c.action(
        app.model(
            model=Container,
            path="{container_id}",
            variables=lambda container: {'container_id': container.id}),
        get_container)

    def get_item(base, item_id):
        return base.items.get(item_id)

    c.action(
        app.model(model=Item,
                  path="{item_id}",
                  variables=lambda item: {'item_id': item.id},
                  base=Container,
                  get_base=lambda item: item.parent),
        get_item)

    c.action(
        app.view(model=Container),
        lambda request, model: 'container: %s' % model.id)
    c.action(
        app.view(model=Container, name='link'),
        lambda request, model: request.link(model))
    c.action(
        app.view(model=Item),
        lambda request, model: 'item: %s' % model.id)
    c.action(
        app.view(model=Item, name='link'),
        lambda request, model: request.link(model))
    c.action(
        app.view(model=Item, name='otherlink'),
        lambda request, model: request.link(e))
    c.commit()

    c = Client(app, Response)

    response = c.get('/alpha')
    assert response.data == 'container: alpha'
    response = c.get('/beta')
    assert response.data == 'container: beta'
    response = c.get('/alpha/a')
    assert response.data == 'item: a'
    response = c.get('/beta/e')
    assert response.data == 'item: e'
    response = c.get('/alpha/e')
    assert response.status == '404 NOT FOUND'

    response = c.get('/alpha/@@link')
    assert response.data == 'alpha'
    response = c.get('/alpha/a/link')
    assert response.data == 'alpha/a'
    response = c.get('/alpha/a/otherlink')
    assert response.data == 'beta/e'