From 393698b365a5b8d77dac2578da3cdce45b0cf080 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Sun, 15 Oct 2017 17:37:37 +0200 Subject: [PATCH] some cleanup and documentation --- ordr2/__init__.py | 1 + ordr2/resources/__init__.py | 10 ++++------ ordr2/views/public.py | 6 +----- tests/resources/__init__.py | 8 ++++---- tests/test_ordr2.py | 22 ---------------------- 5 files changed, 10 insertions(+), 37 deletions(-) delete mode 100644 tests/test_ordr2.py diff --git a/ordr2/__init__.py b/ordr2/__init__.py index a9c7ca4..72d5dab 100644 --- a/ordr2/__init__.py +++ b/ordr2/__init__.py @@ -15,6 +15,7 @@ def main(global_config, **settings): config.include('pyramid_jinja2') config.include('.models') config.include('.resources') + config.include('.security') config.scan() diff --git a/ordr2/resources/__init__.py b/ordr2/resources/__init__.py index 0289a14..b1455e3 100644 --- a/ordr2/resources/__init__.py +++ b/ordr2/resources/__init__.py @@ -27,21 +27,19 @@ class BaseResource(object): ''' - # __name__ and __parent__ properties for location awareness + # __name__ and __parent__ properties for location aware resources __name__ = None __parent__ = None - # dict to match the next url path segment - # for example: to return an AccountResouce when the next path segment is - # 'account' use nodes = {'account': AccountResource} + #: dict to match the next url path segment nodes = {} def __init__(self, name, parent, model=None): ''' Create a base resource ''' self.__name__ = name self.__parent__ = parent - self.request = parent.request - self.model = model + self.request = parent.request #: the current request + self.model = model #: a related model instance def __acl__(self): ''' access controll list for the resource ''' diff --git a/ordr2/views/public.py b/ordr2/views/public.py index 00ce236..e86b79f 100644 --- a/ordr2/views/public.py +++ b/ordr2/views/public.py @@ -1,15 +1,11 @@ ''' pubic accessible views ''' -from pyramid.response import Response from pyramid.view import view_config -from sqlalchemy.exc import DBAPIError - -from ..models import MyModel - @view_config( context='ordr2:resources.RootResource', + permission='view', renderer='ordr2:templates/mytemplate.jinja2' ) def index(context, request): diff --git a/tests/resources/__init__.py b/tests/resources/__init__.py index e19fc99..1d5e0e8 100644 --- a/tests/resources/__init__.py +++ b/tests/resources/__init__.py @@ -6,8 +6,8 @@ import pytest def test_base_resource_init(): ''' test __init__ function of base resource ''' from ordr2.resources import BaseResource, RootResource - root = RootResource('request object') + root = RootResource('request object') resource = BaseResource('resource name', root, 'model instance') assert resource.__name__ == 'resource name' @@ -20,8 +20,8 @@ def test_base_resource_acl(): ''' test __acl__ function of base resource ''' from ordr2.resources import BaseResource, RootResource from pyramid.security import DENY_ALL - root = RootResource('request object') + root = RootResource('request object') resource = BaseResource('resource name', root, 'model instance') assert resource.__acl__() == [ DENY_ALL ] @@ -36,12 +36,12 @@ def test_base_resource_acl(): def test_base_resource_getitem(segment): ''' test the __getitem__ function of base resource ''' from ordr2.resources import BaseResource, RootResource + root = RootResource('request object') root.nodes = {'known': BaseResource} - resource = root[segment] - assert resource.__name__ == segment + assert resource.__name__ == 'known' assert resource.__parent__ == root assert resource.request == 'request object' diff --git a/tests/test_ordr2.py b/tests/test_ordr2.py deleted file mode 100644 index 96b2182..0000000 --- a/tests/test_ordr2.py +++ /dev/null @@ -1,22 +0,0 @@ -''' Tests for `ordr2` package. ''' - -import pytest - - -import ordr2 - - -@pytest.fixture -def response(): - ''' Sample pytest fixture. - - See more at: http://doc.pytest.org/en/latest/fixture.html - ''' - # import requests - # return requests.get('https://github.com/audreyr/cookiecutter-pypackage') - - -def test_content(response): - ''' Sample pytest test function with the pytest fixture as an argument. ''' - # from bs4 import BeautifulSoup - # assert 'GitHub' in BeautifulSoup(response.content).title.string