Beispiel #1
0
 def _get_object_data(self, obj):
     if obj:       
         serviced_obj = IService(obj)
         data = serviced_obj.get_object()
         type_ = serviced_obj.get_type()
         misc = serviced_obj.get_misc()
         return self.builder.get_path(obj, ''), (data, type_, misc,)
     else:
         return ()
Beispiel #2
0
 def __call__(self, context, path=''):
     builder = getUtility(IContextBuilder)
     obj = builder(context, path)
     if IContainer.providedBy(obj):
         return IServiceContainer(obj)
     else:
         return IService(obj)
Beispiel #3
0
 def get_object(self, paths=['',]):
     """
     @param paths - list of strings to the path of the wanted objects
                  - [path, ...]
     =returns { path: [{ attr: value, ...}, type_name, {misc}], ...}
     """
     objs = {}
     for path in paths:
         obj = self.builder(self.context, path)
         serviced_obj = IService(obj)
         data = serviced_obj.get_object()
         type_ = serviced_obj.get_type()
         misc = serviced_obj.get_misc()
         objs[self.builder.get_path(self.context, path)] = (data, type_, misc,)
         self.logger.info("- get_object - Gathering data for %s." % repr(obj))
     return objs
Beispiel #4
0
    def post_object(self, params):
        """
        @param params - dictionary of path with a list value where list item zero are
                        attribute names and their respective values; and list item one
                        is the type name.
                      - { path: [{ attr: value, ...}, type_name], ...}
        =returns [path, ...]
        """
        assert type(params) == dict, "The first agument must be a dictionary."

        results = []
        for path in params:
            try:
                properties, type_name = params[path][0:2]
            except ValueError:
                raise ValueError(
                    "The parameters given must be in the following format: { path: [{ attr: value, ...}, type_name], ...}\nThe application had problems unpacking the path's required list values."
                )
            # create the child object
            split_path = path.split('/')
            id_ = split_path[-1]
            parent_path = '/'.join(split_path[:-1])
            properties['id'] = id_
            assert id_ is not None, "Problem finding the id of the to-be-created object."
            assert type_name is not None, "Could not find the type-name."
            # start by getting the parent object
            obj = self.builder(self.context, parent_path)
            serviced_obj = IServiceContainer(obj)

            created_obj_id = serviced_obj.create_object(type_name, id_)
            self.logger.info(
                "- post_object - Creating object at %s of %s type." %
                (repr(obj), type_name))
            results.append(
                self.builder.get_path(serviced_obj.context, created_obj_id))

            # set the additional values
            created_obj = self.builder(obj, created_obj_id)
            serviced_created_obj = IService(created_obj)
            serviced_created_obj.set_properties(properties)
            self.logger.info("- post_object - Set properties for %s." %
                             repr(created_obj))
        return results
Beispiel #5
0
    def put_object(self, params):
        """
        @param params - dictionary of path with a list value where list item zero are
                        attribute names and their respective values; and list item one
                        is the type name.
                      - { path: [{ attr: value, ...}], ...}
        =returns [path, ...]
        """
        assert type(params) == dict, "The first argument must be a dictionary."

        results = []
        for path in params:
            properties = params[path][0]
            obj = self.builder(self.context, path)
            serviced_obj = IService(obj)
            self.logger.info("- put_object - Set properties for %s." % repr(obj))
            serviced_obj.set_properties(properties)
            results.append(self.builder.get_path(self.context, path))
            # TODO pumazi: notifiers and possibly reindex
        return results
 def setUp(self):
     sm = getSiteManager()
     # Register the base service adapter.
     from wsapi4plone.core.interfaces import IService
     from wsapi4plone.core.service import Service
     sm.registerAdapter(Service,
                        required=(Interface,),
                        provided=IService)
     # Adapter a dummy object to play with in the tests.
     dummy = Dummy()
     self.serviced_object = IService(dummy)
Beispiel #7
0
    def get_schema(self, type_name, path=''):
        """
        @param type_name - the formal system name (aka id) of the content-type
        @param path - string to the path of the container
                    - sometimes necessary if content-type contraints are defined
        =returns { attr: {required: True | False, type: type_string, ...}, ...}
        """
        # TODO pumazi: may want to eventually cache the schema types so that
        # objects don't need created on every types enabled call
        context = self.builder(self.context, path)
        uid = 'tmp_' + type_name + '_' + str(random.randint(1, 1000000))
        parent_serviced_obj = IServiceContainer(context)

        id_ = parent_serviced_obj.create_object(type_name, uid)
        self.logger.info("- get_schema - Getting schema for %s type with temporary name %s on %s." % (type_name, id_, context))

        obj = self.builder(context[id_], '')
        serviced_obj = IService(obj)
        skeleton = serviced_obj.get_skeleton()
        parent_serviced_obj.delete_object(id_)
        return skeleton
Beispiel #8
0
    def put_object(self, params):
        """
        @param params - dictionary of path with a list value where list item zero are
                        attribute names and their respective values; and list item one
                        is the type name.
                      - { path: [{ attr: value, ...}], ...}
        =returns [path, ...]
        """
        assert type(params) == dict, "The first argument must be a dictionary."

        results = []
        for path in params:
            properties = params[path][0]
            obj = self.builder(self.context, path)
            serviced_obj = IService(obj)
            self.logger.info("- put_object - Set properties for %s." %
                             repr(obj))
            serviced_obj.set_properties(properties)
            results.append(self.builder.get_path(self.context, path))
            # TODO pumazi: notifiers and possibly reindex
        return results
Beispiel #9
0
    def post_object(self, params):
        """
        @param params - dictionary of path with a list value where list item zero are
                        attribute names and their respective values; and list item one
                        is the type name.
                      - { path: [{ attr: value, ...}, type_name], ...}
        =returns [path, ...]
        """
        assert type(params) == dict, "The first agument must be a dictionary."
        alsoProvides(self.context.REQUEST, IDisableCSRFProtection)
        results = []
        for path in params:
            try:
                properties, type_name = params[path][0:2]
            except ValueError:
                raise ValueError("The parameters given must be in the following format: { path: [{ attr: value, ...}, type_name], ...}\nThe application had problems unpacking the path's required list values.")
            # create the child object
            split_path = path.split('/')
            id_ = split_path[-1]
            parent_path = '/'.join(split_path[:-1])
            properties['id'] = id_
            assert id_ is not None, "Problem finding the id of the to-be-created object."
            assert type_name is not None, "Could not find the type-name."
            # start by getting the parent object
            obj = self.builder(self.context, parent_path)
            serviced_obj = IServiceContainer(obj)


            created_obj_id = serviced_obj.create_object(type_name, id_)
            self.logger.info("- post_object - Creating object at %s of %s type." % (repr(obj), type_name))
            results.append(self.builder.get_path(serviced_obj.context, created_obj_id))

            # set the additional values
            created_obj = self.builder(obj, created_obj_id)
            
            serviced_created_obj = IService(created_obj)
            serviced_created_obj.set_properties(properties)
            self.logger.info("- post_object - Set properties for %s." % repr(created_obj))
        return results
Beispiel #10
0
 def get_object(self, paths=[
     '',
 ]):
     """
     @param paths - list of strings to the path of the wanted objects
                  - [path, ...]
     =returns { path: [{ attr: value, ...}, type_name, {misc}], ...}
     """
     objs = {}
     for path in paths:
         obj = self.builder(self.context, path)
         serviced_obj = IService(obj)
         data = serviced_obj.get_object()
         type_ = serviced_obj.get_type()
         misc = serviced_obj.get_misc()
         objs[self.builder.get_path(self.context, path)] = (
             data,
             type_,
             misc,
         )
         self.logger.info("- get_object - Gathering data for %s." %
                          repr(obj))
     return objs
Beispiel #11
0
    def get_schema(self, type_name, path=''):
        """
        @param type_name - the formal system name (aka id) of the content-type
        @param path - string to the path of the container
                    - sometimes necessary if content-type contraints are defined
        =returns { attr: {required: True | False, type: type_string, ...}, ...}
        """
        # TODO pumazi: may want to eventually cache the schema types so that
        # objects don't need created on every types enabled call
        context = self.builder(self.context, path)
        uid = 'tmp_' + type_name + '_' + str(random.randint(1, 1000000))
        parent_serviced_obj = IServiceContainer(context)

        id_ = parent_serviced_obj.create_object(type_name, uid)
        self.logger.info(
            "- get_schema - Getting schema for %s type with temporary name %s on %s."
            % (type_name, id_, context))

        obj = self.builder(context[id_], '')
        serviced_obj = IService(obj)
        skeleton = serviced_obj.get_skeleton()
        parent_serviced_obj.delete_object(id_)
        return skeleton
Beispiel #12
0
    def test_get_object(self):
        # We need to login to get the values of some of the attributes
        # (e.g. locallyAllowedTypes).
        self.login('test_user_1_')
        from wsapi4plone.core.interfaces import IService
        portal = IService(self.portal).get_object()
        self.logout()
        actual = portal
        expected = PORTAL_VALUES
        actual_keys = actual.keys()
        expected_keys = expected.keys()

        def diff(a, b):
            c = set(a).difference(set(b))
            return list(c)

        # Check the keys for any differences before moving on.
        self.failUnlessEqual(set(actual_keys), set(expected_keys),
                             "Difference attributes were discovered. The \
                             differening attribute(s) are %s." % \
                             diff(actual_keys, expected_keys))
        # Check each attribute's value individually since list order and
        # DateTime values will not be the same.
        for attr in actual:
            if isinstance(expected[attr], DateTime):
                # It is good enough that they are the same type?
                # The expected results do not have the most current
                # date and time.
                continue
            elif isinstance(expected[attr], list):
                # We need to take a closer look at lists. There is no
                # guaranty that the results will be in the same order.
                expected_value = expected[attr]
                resulting_value = actual[attr]
                self.failUnlessEqual(set(resulting_value),
                                     set(expected_value),
                                     "Difference attributes were discovered. \
                                     The differening attribute(s) are %s." % \
                                     diff(resulting_value, expected_value))
                continue
            # If it gets this far, it must be a base type or it will fail.
            self.failUnlessEqual(expected[attr], actual[attr])
Beispiel #13
0
 def test_get_skeleton(self):
     from wsapi4plone.core.interfaces import IService
     skel = IService(self.portal).get_skeleton()
     self.failUnlessEqual(skel, PORTAL_SKELETON)