def test_get_collection_links_handles_invalid_limits(self):
        self.setUpGetCollectionLinks()
        self.request.params = {'limit': 'foo'}
        links = views_common.get_collection_links(self.request, self.items)
        self.assertEqual([], links)

        self.request.params = {'limit': None}
        links = views_common.get_collection_links(self.request, self.items)
        self.assertEqual([], links)
Example #2
0
    def test_get_collection_links_handles_invalid_limits(self):
        self.setUpGetCollectionLinks()
        self.request.params = {'limit': 'foo'}
        links = views_common.get_collection_links(self.request, self.items)
        self.assertEqual([], links)

        self.request.params = {'limit': None}
        links = views_common.get_collection_links(self.request, self.items)
        self.assertEqual([], links)
Example #3
0
    def test_get_collection_links_overwrites_url_marker(self):
        self.setUpGetCollectionLinks()
        self.request.params = {'limit': '2', 'marker': 'some_marker'}
        links = views_common.get_collection_links(self.request, self.items)

        expected = 'http://example.com/fake/path?marker=id2&limit=2'
        next_link = filter(lambda link: link['rel'] == 'next', links).pop()
        self.assertEqual(expected, next_link['href'])
Example #4
0
    def test_get_collection_links_creates_next(self):
        self.setUpGetCollectionLinks()
        links = views_common.get_collection_links(self.request, self.items)

        expected = 'http://example.com/fake/path?marker=id2&limit=2'
        next_link = filter(lambda link: link['rel'] == 'next', links).pop()
        self.assertEqual('next', next_link['rel'])
        self.assertEqual(expected, next_link['href'])
Example #5
0
def collection(req, stacks):
    formatted_stacks = [format_stack(req, s, basic_keys) for s in stacks]

    result = {'stacks': formatted_stacks}
    links = views_common.get_collection_links(req, formatted_stacks)
    if links:
        result['links'] = links

    return result
Example #6
0
    def test_get_collection_links_creates_next(self):
        self.setUpGetCollectionLinks()
        links = views_common.get_collection_links(self.request, self.items)

        expected_params = {'marker': ['id2'], 'limit': ['2']}
        next_link = filter(lambda link: link['rel'] == 'next', links).pop()
        self.assertEqual('next', next_link['rel'])
        url_path, url_params = next_link['href'].split('?', 1)
        self.assertEqual(url_path, self.request.path_url)
        self.assertEqual(expected_params, urlparse.parse_qs(url_params))
Example #7
0
def collection(req, stacks, count=None):
    formatted_stacks = [format_stack(req, s, basic_keys) for s in stacks]

    result = {'stacks': formatted_stacks}
    links = views_common.get_collection_links(req, formatted_stacks)
    if links:
        result['links'] = links
    if count is not None:
        result['count'] = count

    return result
    def test_get_collection_links_does_not_overwrite_other_params(self):
        self.setUpGetCollectionLinks()
        self.request.params = {'limit': '2', 'foo': 'bar'}
        links = views_common.get_collection_links(self.request, self.items)

        next_link = filter(lambda link: link['rel'] == 'next', links).pop()
        url = next_link['href']
        query_string = urlparse.urlparse(url).query
        params = urlparse.parse_qs(query_string)
        self.assertEqual('2', params['limit'][0])
        self.assertEqual('bar', params['foo'][0])
Example #9
0
def collection(req, stacks, count=None):
    formatted_stacks = [format_stack(req, s, basic_keys) for s in stacks]

    result = {'stacks': formatted_stacks}
    links = views_common.get_collection_links(req, formatted_stacks)
    if links:
        result['links'] = links
    if count is not None:
        result['count'] = count

    return result
Example #10
0
    def test_get_collection_links_does_not_overwrite_other_params(self):
        self.setUpGetCollectionLinks()
        self.request.params = {'limit': '2', 'foo': 'bar'}
        links = views_common.get_collection_links(self.request, self.items)

        next_link = filter(lambda link: link['rel'] == 'next', links).pop()
        url = next_link['href']
        query_string = urlparse.urlparse(url).query
        params = {}
        params.update(urlparse.parse_qsl(query_string))
        self.assertEqual('2', params['limit'])
        self.assertEqual('bar', params['foo'])
Example #11
0
def collection(req, stacks, count=None, include_project=False):
    keys = basic_keys
    formatted_stacks = [format_stack(req, s, keys, include_project)
                        for s in stacks]

    result = {'stacks': formatted_stacks}
    links = views_common.get_collection_links(req, formatted_stacks)
    if links:
        result['links'] = links
    if count is not None:
        result['count'] = count

    return result
Example #12
0
    def test_get_collection_links_doesnt_create_next_if_page_not_full(self):
        self.setUpGetCollectionLinks()
        self.request.params['limit'] = '10'
        links = views_common.get_collection_links(self.request, self.items)

        self.assertEqual([], links)
Example #13
0
    def test_get_collection_links_doesnt_create_next_if_page_not_full(self):
        self.setUpGetCollectionLinks()
        self.request.params['limit'] = '10'
        links = views_common.get_collection_links(self.request, self.items)

        self.assertEqual([], links)