Пример #1
0
    def get_list_from_endpoint(self,
                               uri,
                               tcm_type = None,
                               headers = get_json_headers()):
        '''
            This hits an endpoint.  It goes into the ArrayOfXXX tcm_type of response
        '''
        if tcm_type == None:
            tcm_type = self.singular

        response_txt = do_get(uri, headers = headers)

        try:
            array_of_type = json_to_obj(response_txt)[ns(as_arrayof(tcm_type))][0]
            if (len(array_of_type) > 1):
                items = array_of_type[ns(tcm_type)]
                if (not isinstance(items, list)):
                    items = [items]
            else:
                items = []

            return items
        except (KeyError, TypeError) as err:
            assert False, \
                "%s\nDidn't find [%s][0][%s] in\n%s" % \
                (str(err),
                 ns(as_arrayof(tcm_type)),
                 ns(tcm_type),
                 json_pretty(response_txt))
Пример #2
0
    def get_list_from_endpoint(self,
                               uri,
                               tcm_type=None,
                               params={},
                               headers=get_json_headers()):
        '''
            This hits an endpoint.  It goes into the ArrayOfXXX tcm_type of response
        '''
        if tcm_type == None:
            tcm_type = self.singular

        response_txt = do_get(uri, params=params, headers=headers)

        try:
            array_of_type = json_to_obj(response_txt)[ns(
                as_arrayof(tcm_type))][0]
            if (len(array_of_type) > 1):
                items = array_of_type[ns(tcm_type)]
                if (not isinstance(items, list)):
                    items = [items]
            else:
                items = []

            return items
        except (KeyError, TypeError) as err:
            assert False, \
                "%s\nDidn't find [%s][0][%s] in\n%s" % \
                (str(err),
                 ns(as_arrayof(tcm_type)),
                 ns(tcm_type),
                 json_pretty(response_txt))
Пример #3
0
    def create(self, params, headers = get_form_headers()):
        data = do_post(self.root_path, params, headers = headers)
        try:
            created_obj = json_to_obj(data)[ns(self.creation_key)][0]
        except KeyError:
            assert False, "looking for %s in:\n%s" % (self.creation_key, json_pretty(data))

        self.store_latest(created_obj)
        return created_obj
Пример #4
0
    def create(self, params, headers=get_form_headers()):
        data = do_post(self.root_path, params, headers=headers)
        try:
            created_obj = json_to_obj(data)[ns(self.creation_key)][0]
        except KeyError:
            assert False, "looking for %s in:\n%s" % (self.creation_key,
                                                      json_pretty(data))

        self.store_latest(created_obj)
        return created_obj
Пример #5
0
    def get_list_from_search(self,
                             uri,
                             tcm_type = None,
                             plural_tcm_type = None,
                             params = {},
                             headers = get_json_headers()):
        '''
            This will always return an array.  May have many, one or no items in it
            it goes into the "searchResult" tcm_type of response
        '''
        if tcm_type == None:
            tcm_type = self.singular
            plural_tcm_type = self.plural

        if plural_tcm_type == None:
            plural_tcm_type = plural(tcm_type)

        response_txt = do_get(uri, params, headers)

        sr_field = ns("searchResult")
        tcm_type = ns(tcm_type)
        pl_type = ns(plural_tcm_type)

        try:
            sr = json_to_obj(response_txt)[sr_field][0]
            if (sr[ns("totalResults")] > 0):
                items = sr[pl_type][tcm_type]
                if (not isinstance(items, list)):
                    items = [items]
            else:
                items = []

            return items
        except (KeyError, TypeError) as err:
            assert False, \
                "%s\nDidn't find [%s][0][%s][%s] in\n%s" % \
                (str(err),
                 sr_field,
                 pl_type,
                 ns(tcm_type),
                 json_pretty(response_txt))
Пример #6
0
    def get_list_from_search(self,
                             uri,
                             tcm_type=None,
                             plural_tcm_type=None,
                             params={},
                             headers=get_json_headers()):
        '''
            This will always return an array.  May have many, one or no items in it
            it goes into the "searchResult" tcm_type of response
        '''
        if tcm_type == None:
            tcm_type = self.singular
            plural_tcm_type = self.plural

        if plural_tcm_type == None:
            plural_tcm_type = plural(tcm_type)

        response_txt = do_get(uri, params, headers)

        sr_field = ns("searchResult")
        tcm_type = ns(tcm_type)
        pl_type = ns(plural_tcm_type)

        try:
            sr = json_to_obj(response_txt)[sr_field][0]
            if (sr[ns("totalResults")] > 0):
                items = sr[pl_type][tcm_type]
                if (not isinstance(items, list)):
                    items = [items]
            else:
                items = []

            return items
        except (KeyError, TypeError) as err:
            assert False, \
                "%s\nDidn't find [%s][0][%s][%s] in\n%s" % \
                (str(err),
                 sr_field,
                 pl_type,
                 ns(tcm_type),
                 json_pretty(response_txt))