Example #1
0
def child_link_obj(*path_elements):
    """
    Create a link object that appends the given elements to the path of the
    current request.
    Example: current request path = '/foo/bar/baz/'
             path elements = ['fee', 'fie']
             returned path = '/foo/bar/baz/fee/fie/'
    @param path_elements: path elements to append
    @type  path_elements: *str
    @return: link object
    @rtype:  dict
    """
    suffix = '/'.join(path_elements)
    link = copy.copy(_LINK_OBJ_SKEL)
    link['_href'] = http.extend_uri_path(suffix)
    return link
Example #2
0
def child_link_obj(*path_elements):
    """
    Create a link object that appends the given elements to the path of the
    current request.
    Example: current request path = '/foo/bar/baz/'
             path elements = ['fee', 'fie']
             returned path = '/foo/bar/baz/fee/fie/'
    @param path_elements: path elements to append
    @type  path_elements: *str
    @return: link object
    @rtype:  dict
    """
    suffix = '/'.join(path_elements)
    link = copy.copy(_LINK_OBJ_SKEL)
    link['_href'] = http.extend_uri_path(suffix)
    return link
Example #3
0
def child_link_obj(*path_elements):
    """
    Create a link object that appends the given elements to the path of the
    current request.
    Example: current request path = '/foo/bar/baz/'
             path_elements = ('fee', 'fie')
             returned_path = '/foo/bar/baz/fee/fie/'

    :param path_elements: captured positional arguments treated as path elements to append
    :type path_elements: Variable length tuple of strings
    :return: link object
    :rtype: dict
    """

    suffix = os.path.join(*path_elements)
    link = link_dict()
    link['_href'] = http.extend_uri_path(suffix)
    return link
Example #4
0
def search_safe_link_obj(resource_id):
    """
    Like child_link_obj, except this can be used with search results. If the
    current request URL ends with 'search/', that gets stripped off before
    creating the object link.  If it does not end with 'search/', this acts just
    like child_link_obj.

    @param resource_id: id of the resource to which you need a link
    @type  resource_id: basestring

    @return:    dict with '_href' key and corresponding value
    @rtype:     dict
    """
    search_suffix = 'search/'
    uri_path = http.uri_path()
    if uri_path.endswith(search_suffix):
        uri_path = uri_path[:-len(search_suffix)]
    link = copy.copy(_LINK_OBJ_SKEL)
    link['_href'] = http.extend_uri_path(resource_id, uri_path)
    return link
Example #5
0
def search_safe_link_obj(resource_id):
    """
    Like child_link_obj, except this can be used with search results. If the
    current request URL ends with 'search/', that gets stripped off before
    creating the object link.  If it does not end with 'search/', this acts just
    like child_link_obj.

    @param resource_id: id of the resource to which you need a link
    @type  resource_id: basestring

    @return:    dict with '_href' key and corresponding value
    @rtype:     dict
    """
    search_suffix = 'search/'
    uri_path = http.uri_path()
    if uri_path.endswith(search_suffix):
        uri_path = uri_path[:-len(search_suffix)]
    link = copy.copy(_LINK_OBJ_SKEL)
    link['_href'] = http.extend_uri_path(resource_id, uri_path)
    return link
Example #6
0
 def test_extend_uri_path_with_prefix(self, mock_path):
     ret = http.extend_uri_path('repo1', '/base/uri/')
     # verify
     self.assertEqual(mock_path.call_count, 0)
     self.assertEqual(ret, '/base/uri/repo1/')
Example #7
0
 def test_extend_uri_path_no_trailing_slash(self, mock_path):
     ret = http.extend_uri_path('repo1')
     # verify
     mock_path.assert_called_once_with()
     self.assertEqual(ret, '/base/uri/repo1/')
 def test_extend_uri_path_with_prefix(self, mock_path):
     ret = http.extend_uri_path('repo1', '/base/uri/')
     # verify
     self.assertEqual(mock_path.call_count, 0)
     self.assertEqual(ret, '/base/uri/repo1/')
 def test_extend_uri_path_no_trailing_slash(self, mock_path):
     ret = http.extend_uri_path('repo1')
     # verify
     mock_path.assert_called_once_with()
     self.assertEqual(ret, '/base/uri/repo1/')