Example #1
0
 def test_non_empty_user_table(self, unit):
     add_fixtures(unit.dbsession)
     context = ListResource(User)
     context.renderer = 'json'
     response = Read(context, unit.request).list_view()
     assert response.json['paginator'] == [
         {'name': 'admin'},
         {'name': 'moderator'},
         {'name': 'user1'},
         {'name': 'user2'}
     ]
Example #2
0
def includeme(config):
    """
    Initialize the model for a Pyramid app.

    Activate this setup using ``config.include('Cosmetics.models')``.

    """
    settings = config.get_settings()

    # use pyramid_tm to hook the transaction lifecycle to the request
    config.include('pyramid_tm')

    session_factory = get_session_factory(get_engine(settings))
    config.registry['dbsession_factory'] = session_factory

    # make request.dbsession available for use in Pyramid
    config.add_request_method(
        # r.tm is the transaction manager used by pyramid_tm
        lambda r: get_tm_session(session_factory, r.tm),
        'dbsession',
        reify=True)

    from pyramid.security import Everyone, Allow
    from pyramid_sacrud import PYRAMID_SACRUD_HOME, PYRAMID_SACRUD_VIEW
    acl = [
        (Allow, Everyone, PYRAMID_SACRUD_HOME),
        (Allow, Everyone, PYRAMID_SACRUD_VIEW),
        (Allow, Everyone, 'test'),
    ]

    from ps_alchemy.resources import ListResource

    my_ps_group = ListResource(Group)
    my_ps_group.__acl__ = acl

    models = (('Test', [my_ps_group, User]), ('Test1', [Category, Unit]))

    config.include('ps_alchemy')
    config.include('pyramid_sacrud', route_prefix='admin')
    config.registry.settings['pyramid_sacrud.models'] = models
Example #3
0
 def test_verify_list_resource(self):
     verifyClass(ISacrudResource, ListResource)
     verifyObject(ISacrudResource, ListResource(TestModel))
Example #4
0
 def test_empty_user_table(self, unit):
     context = ListResource(User)
     context.renderer = 'json'
     response = Read(context, unit.request).list_view()
     assert response.json['paginator'] == []
Example #5
0
 def test_empty_user_table(self, unit):
     context = ListResource(User)
     context.renderer = 'json'
     response = Read(context, unit.request).list_view()
     assert response.json['paginator'] == []