예제 #1
0
 def setUp(self):
     self.authz = AuthorizationPolicy()
     self.authz.get_bound_permissions = mock.sentinel.get_bound_perms
     self.request = DummyRequest(method='GET')
     self.context = RouteFactory(self.request)
     self.context.on_collection = True
     self.context.check_permission = mock.Mock(return_value=False)
예제 #2
0
 def test_attributes_are_none_with_blank_requests(self):
     request = Request.blank(path='/')
     request.registry = mock.Mock(settings={})
     request.authn_type = 'fxa'
     request.prefixed_userid = property(authentication.prefixed_userid)
     context = RouteFactory(request)
     self.assertIsNone(context.required_permission)
     self.assertIsNone(context.current_record)
     self.assertIsNone(context.resource_name)
     self.assertIsNone(context.get_shared_ids)
예제 #3
0
 def test_http_put_sets_current_record_attribute(self):
     with mock.patch('cliquet.utils.current_service') as current_service:
         # Patch current service.
         resource = mock.MagicMock()
         resource.record_id = 1
         resource.model.get_record.return_value = mock.sentinel.record
         current_service().resource.return_value = resource
         # Do the actual call.
         request = DummyRequest(method='put')
         context = RouteFactory(request)
         self.assertEquals(context.current_record, mock.sentinel.record)
예제 #4
0
    def test_attributes_are_none_with_non_resource_requests(self):
        basic_service = object()
        request = Request.blank(path='/')
        request.prefixed_userid = property(authentication.prefixed_userid)
        request.matched_route = mock.Mock(pattern='foo')
        request.registry = mock.Mock(cornice_services={'foo': basic_service})
        request.registry.settings = {}

        context = RouteFactory(request)
        self.assertIsNone(context.current_record)
        self.assertIsNone(context.required_permission)
        self.assertIsNone(context.resource_name)
        self.assertIsNone(context.get_shared_ids)
예제 #5
0
    def test_http_put_unexisting_record_resolves_in_a_create_permission(self):
        with mock.patch('cliquet.utils.current_service') as current_service:
            # Patch current service.
            resource = mock.MagicMock()
            resource.record_id = 1
            resource.model.get_record.side_effect = \
                storage_exceptions.RecordNotFoundError
            current_service().resource.return_value = resource
            current_service().collection_path = '/buckets/{bucket_id}'
            # Do the actual call.
            request = DummyRequest(method='put')
            request.upath_info = '/buckets/abc/collections/1'
            request.matchdict = {'bucket_id': 'abc'}
            context = RouteFactory(request)

            self.assertEquals(context.required_permission, 'create')
예제 #6
0
    def test_route_factory_adds_allowed_principals_from_settings(self):
        with mock.patch('cliquet.utils.current_service') as current_service:
            # Patch current service.
            resource = mock.MagicMock()
            current_service().resource.return_value = resource
            current_service().collection_path = '/buckets'
            # Do the actual call.
            request = DummyRequest(method='post')
            request.current_resource_name = 'bucket'
            request.upath_info = '/buckets'
            request.matchdict = {}
            request.registry = mock.Mock()
            request.registry.settings = {
                'bucket_create_principals': 'fxa:user'
            }
            context = RouteFactory(request)

            self.assertEquals(context.allowed_principals, ['fxa:user'])
예제 #7
0
    def assert_request_resolves_to(self, method, permission, uri=None,
                                   record_not_found=False):
        if uri is None:
            uri = self.record_uri

        with mock.patch('cliquet.utils.current_service') as current_service:
            # Patch current service.
            resource = mock.MagicMock()
            resource.record_id = 1
            if record_not_found:
                resource.model.get_record.side_effect = \
                    storage_exceptions.RecordNotFoundError
            else:
                resource.model.get_record.return_value = 1
            current_service().resource.return_value = resource

            # Do the actual call.
            request = DummyRequest(method=method)
            request.upath_info = uri
            context = RouteFactory(request)

            self.assertEquals(context.required_permission, permission)
예제 #8
0
 def get_context(self):
     return RouteFactory(self.get_request())