示例#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_single_item_from_endpoint(self,
                                      uri = None,
                                      tcm_type = None,
                                      params = {},
                                      headers = get_json_headers()):
        '''
            This hits an endpoint.  No searchResult or ArrayOfXXXX part here
        '''

        if uri == None:
            uri = self.root_path

        if tcm_type == None:
            tcm_type = self.singular

        response_txt = do_get(uri, params = params, headers = headers)
        tcm_obj = json_to_obj(response_txt)
        try:
            item = tcm_obj[ns(tcm_type)][0]

            # we only want to store this latest item, if it's an object of this type.  If this
            # model is doing a search for a different type of item (like percent complete object
            # of "CategoryValueInfo" then we don't want to store it as "latest item"
            if uri == self.root_path:
                self.store_latest(item)
            return item

        except KeyError:
            assert False, "%s\nDidn't find %s in %s" % (str(KeyError), ns(tcm_type), jstr(tcm_obj))
示例#3
0
    def get_single_item_from_endpoint(self,
                                      uri=None,
                                      tcm_type=None,
                                      params={},
                                      headers=get_json_headers()):
        '''
            This hits an endpoint.  No searchResult or ArrayOfXXXX part here
        '''

        if uri == None:
            uri = self.root_path

        if tcm_type == None:
            tcm_type = self.singular

        response_txt = do_get(uri, params=params, headers=headers)
        tcm_obj = json_to_obj(response_txt)
        try:
            item = tcm_obj[ns(tcm_type)][0]

            # we only want to store this latest item, if it's an object of this type.  If this
            # model is doing a search for a different type of item (like percent complete object
            # of "CategoryValueInfo" then we don't want to store it as "latest item"
            if uri == self.root_path:
                self.store_latest(item)
            return item

        except KeyError:
            assert False, "%s\nDidn't find %s in %s" % (
                str(KeyError), ns(tcm_type), jstr(tcm_obj))
示例#4
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))
示例#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))
示例#7
0
    def get_single_item_from_endpoint(self,
                                      uri = None,
                                      tcm_type = None,
                                      headers = get_json_headers()):
        '''
            This hits an endpoint.  No searchResult or ArrayOfXXXX part here
        '''

        if uri == None:
            uri = self.root_path

        if tcm_type == None:
            tcm_type = self.singular

        response_txt = do_get(uri, headers = headers)
        tcm_obj = json_to_obj(response_txt)
        try:
            item = tcm_obj[ns(tcm_type)][0]
            self.store_latest(item)
            return item

        except KeyError:
            assert False, "%s\nDidn't find %s in %s" % (str(KeyError), ns(tcm_type), jstr(tcm_obj))
示例#8
0
def user_not_logged_in(step):
    headers = {'cookie': world.auth_cookie, 'Content-Type': 'application/json'}

    do_get(UserModel().root_path + "/" + "current",
           headers=headers,
           exp_status=401)
示例#9
0
def user_not_logged_in(step):
    headers = {'cookie': world.auth_cookie,
               'Content-Type':'application/json' }

    do_get(UserModel().root_path + "/" + "current",
                  headers = headers, exp_status = 401)