Exemplo n.º 1
0
    def test_http_put_unexisting_object_resolves_in_a_create_permission(self):
        with mock.patch("kinto.core.utils.current_service") as current_service:
            # Patch current service.
            resource = mock.MagicMock()
            resource.object_id = 1
            resource.model.get_object.side_effect = storage_exceptions.ObjectNotFoundError
            current_service().resource.return_value = resource
            current_service().plural_path = "/school/{school_id}"
            # Do the actual call.
            request = DummyRequest(method="put")
            request.upath_info = "/school/abc/students/1"
            request.matchdict = {"school_id": "abc"}
            context = RouteFactory(request)

            self.assertEqual(context.required_permission, "create")
Exemplo n.º 2
0
    def test_http_put_unexisting_record_resolves_in_a_create_permission(self):
        with mock.patch("kinto.core.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.assertEqual(context.required_permission, "create")
Exemplo n.º 3
0
    def test_http_put_unexisting_record_resolves_in_a_create_permission(self):
        with mock.patch('kinto.core.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')
Exemplo n.º 4
0
    def test_route_factory_adds_allowed_principals_from_settings(self):
        with mock.patch('kinto.core.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'])
Exemplo n.º 5
0
    def test_route_factory_adds_allowed_principals_from_settings(self):
        with mock.patch('kinto.core.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'])