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

Commit

Permalink
Merge pull request #73 from postatum/98290626O_auth_setting
Browse files Browse the repository at this point in the history
Set root resource .auth in package init
  • Loading branch information
jstoiko committed Jul 16, 2015
2 parents 3f65321 + 1f305ee commit 42680d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions nefertari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def includeme(config):
from nefertari.resource import get_root_resource, get_resource_map
from nefertari.renderers import (
JsonRendererFactory, NefertariJsonRendererFactory)
from nefertari.utils import dictset

log.info("%s %s" % (APP_NAME, __version__))
config.add_directive('get_root_resource', get_root_resource)
Expand All @@ -28,3 +29,7 @@ def includeme(config):
config.add_request_method(get_resource_map, 'resource_map', reify=True)

config.add_tween('nefertari.tweens.cache_control')

Settings = dictset(config.registry.settings)
root = config.get_root_resource()
root.auth = Settings.asbool('auth')
5 changes: 2 additions & 3 deletions nefertari/polymorphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
* add_url_polymorphic: Wrapper class that is used instead of default
`nefertari.wrappers.add_object_url`.
To use this module, simply include it in your `main()` AFTER root
resource's `auth` variable and after Pyramid ACLAuthorizationPolicy
is set up.
To use this module, simply include it in your `main()` after
Pyramid ACLAuthorizationPolicy is set up and nefertari is included.
By default this module is included by 'nefertari.elasticsearch' when
`elasticsearch.enable_polymorphic_query` setting is True.
Expand Down
4 changes: 3 additions & 1 deletion tests/test_pyramid_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ def test_includeme(self):
from nefertari import includeme

config = mock.Mock()
config.registry.settings = {'auth': True}
includeme(config)

self.assertEqual(1, config.add_directive.call_count)
self.assertEqual(2, config.add_renderer.call_count)
# config.add_renderer.assert_called_with('json', JsonRendererFactory)
root = config.get_root_resource()
assert root.auth

0 comments on commit 42680d5

Please sign in to comment.