Example #1
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))
Example #2
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))
Example #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))
Example #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))
Example #5
0
    def start_testcase(self, result_obj, user_name):
        result_id, result_version = get_resource_identity(result_obj)

        # start the test
        headers = get_form_headers(UserModel().get_auth_header(user_name))
        testresult = do_put("%s/results/%s/start" % (self.root_path, result_id),
                            {"originalVersionId": result_version}, headers)
        started_result = json_to_obj(testresult)[ns("testresult")][0]
        return started_result
Example #6
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
Example #7
0
    def start_testcase(self, result_obj, user_name):
        result_id, result_version = get_resource_identity(result_obj)

        # start the test
        headers = get_form_headers(UserModel().get_auth_header(user_name))
        testresult = do_put(
            "%s/results/%s/start" % (self.root_path, result_id),
            {"originalVersionId": result_version}, headers)
        started_result = json_to_obj(testresult)[ns("testresult")][0]
        return started_result
Example #8
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
Example #9
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))
Example #10
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))
Example #11
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))