Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge branch 'postatum-93492110_improve_coverage' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoiko committed May 1, 2015
2 parents 6c78a2a + 1bb2b09 commit 4462c40
Show file tree
Hide file tree
Showing 30 changed files with 2,435 additions and 203 deletions.
4 changes: 1 addition & 3 deletions nefertari/acl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from pyramid.security import (
ALL_PERMISSIONS, Allow, Everyone, Deny,
Authenticated)
from pyramid.security import ALL_PERMISSIONS, Allow, Everyone, Authenticated


class BaseACL(object):
Expand Down
8 changes: 5 additions & 3 deletions nefertari/json_httpexceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from datetime import datetime
from pyramid import httpexceptions as http_exc

from nefertari.utils import dictset, json_dumps

logger = logging.getLogger(__name__)


Expand All @@ -25,6 +23,7 @@ def add_stack():

def create_json_response(obj, request=None, log_it=False, show_stack=False,
**extra):
from nefertari.utils import json_dumps
body = dict()
encoder = extra.pop('encoder', None)
for attr in BASE_ATTRS:
Expand Down Expand Up @@ -63,6 +62,7 @@ def exception_response(status_code, **kw):

class JBase(object):
def __init__(self, *arg, **kw):
from nefertari.utils import dictset
kw = dictset(kw)
self.__class__.__base__.__init__(
self, *arg,
Expand All @@ -75,7 +75,9 @@ def __init__(self, *arg, **kw):


http_exceptions = http_exc.status_map.values() + [
http_exc.HTTPBadRequest, http_exc.HTTPInternalServerError]
http_exc.HTTPBadRequest,
http_exc.HTTPInternalServerError,
]


for exc_cls in http_exceptions:
Expand Down
2 changes: 1 addition & 1 deletion nefertari/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class NefertariJsonRendererFactory(JsonRendererFactory):
def run_after_calls(self, value, system):
request = system.get('request')
if request and hasattr(request, 'action'):
after_calls = getattr(request, 'filters', [])
after_calls = getattr(request, 'filters', {})
for call in after_calls.get(request.action, []):
value = call(**dict(request=request, result=value))

Expand Down
2 changes: 1 addition & 1 deletion nefertari/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def add(self, member_name, collection_name='', parent=None, uid='',
kwargs['path_prefix'] = '/'.join(path_segs)

if prefix:
kwargs['path_prefix'] += '/'+prefix
kwargs['path_prefix'] += '/' + prefix

name_segs = [a.member_name for a in new_resource.ancestors]
name_segs.insert(1, prefix)
Expand Down
Empty file removed nefertari/tests/__init__.py
Empty file.
105 changes: 0 additions & 105 deletions nefertari/tests/test_view.py

This file was deleted.

45 changes: 0 additions & 45 deletions nefertari/tests/test_wrappers.py

This file was deleted.

11 changes: 6 additions & 5 deletions nefertari/tweens.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def timing(request):
try:
return handler(request)
finally:
delta = time.time()-start
delta = time.time() - start
msg = '%s (%s) request took %s seconds' % (
request.method, request.url, delta)
if delta > threshold:
Expand Down Expand Up @@ -103,9 +103,10 @@ def get_tunneling(request):
def cors(handler, registry):
log.info('cors_tunneling enabled')

allow_origins_setting = registry.settings.get('cors.allow_origins', '')

allow_origins = [
each.strip() for each in
registry.settings.get('cors.allow_origins', '').split(',')]
each.strip() for each in allow_origins_setting.split(',')]
allow_credentials = registry.settings.get('cors.allow_credentials', None)

def cors(request):
Expand All @@ -121,15 +122,15 @@ def cors(request):

return response

if not allow_origins:
if not allow_origins_setting:
log.warning('cors.allow_origins is not set')
else:
log.info('Allow Origins = %s ' % allow_origins)

if allow_credentials is None:
log.warning('cors.allow_credentials is not set')

elif asbool(allow_credentials) and allow_origins == '*':
elif asbool(allow_credentials) and allow_origins_setting == '*':
log.error('Not allowed Access-Control-Allow-Credentials '
'to set to TRUE if origin is *')
return
Expand Down
2 changes: 1 addition & 1 deletion nefertari/utility_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def create(self):

self.settings[key] = value

return JHTTPCreate()
return JHTTPCreated()

def delete(self, id):
if 'reset' in self._params:
Expand Down
2 changes: 1 addition & 1 deletion nefertari/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def to_dicts(collection, key=None, **kw):
if key:
each_dict = key(each_dict)
_dicts.append(each_dict)
except AttributeError, e:
except AttributeError:
_dicts.append(each)
except TypeError:
return collection
Expand Down
9 changes: 6 additions & 3 deletions nefertari/utils/dictset.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,22 @@ def asdict(self, name, _type=None, _set=False):
_dict = {}
for item in split_strip(dict_str):
key, _, val = item.partition(':')
val = _type(val)
if key in _dict:
if type(_dict[key]) is list:
if isinstance(_dict[key], list):
_dict[key].append(val)
else:
_dict[key] = [_dict[key], val]
else:
_dict[key] = _type(val)
_dict[key] = val

if _set:
self[name] = _dict

return _dict

def mget(self, prefix, defaults={}):
if prefix[-1] != '.':
if not prefix.endswith('.'):
prefix += '.'

_dict = dictset(defaults)
Expand Down Expand Up @@ -161,6 +162,7 @@ def process_float_param(self, name, default=None):

elif default is not None:
self[name] = default
return self.get(name, None)

def process_int_param(self, name, default=None):
if name in self:
Expand All @@ -171,6 +173,7 @@ def process_int_param(self, name, default=None):

elif default is not None:
self[name] = default
return self.get(name, None)

def process_dict_param(self, name, _type=None, pop=False):
return self.asdict(name, _type, _set=not pop)
Expand Down

0 comments on commit 4462c40

Please sign in to comment.