Browse Source

some cleanup and documentation

master
Holger Frey 7 years ago
parent
commit
393698b365
  1. 1
      ordr2/__init__.py
  2. 10
      ordr2/resources/__init__.py
  3. 6
      ordr2/views/public.py
  4. 8
      tests/resources/__init__.py
  5. 22
      tests/test_ordr2.py

1
ordr2/__init__.py

@ -15,6 +15,7 @@ def main(global_config, **settings): @@ -15,6 +15,7 @@ def main(global_config, **settings):
config.include('pyramid_jinja2')
config.include('.models')
config.include('.resources')
config.include('.security')
config.scan()

10
ordr2/resources/__init__.py

@ -27,21 +27,19 @@ class BaseResource(object): @@ -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 '''

6
ordr2/views/public.py

@ -1,15 +1,11 @@ @@ -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):

8
tests/resources/__init__.py

@ -6,8 +6,8 @@ import pytest @@ -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(): @@ -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(): @@ -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'

22
tests/test_ordr2.py

@ -1,22 +0,0 @@ @@ -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