예제 #1
0
파일: fakes.py 프로젝트: andrew-plunk/heat
    def _cs_request(self, url, method, **kwargs):
        # Check that certain things are called correctly
        if method in ['GET', 'DELETE']:
            assert 'body' not in kwargs
        elif method == 'PUT':
            assert 'body' in kwargs

        # Call the method
        args = urlutils.parse_qsl(urlutils.urlparse(url)[4])
        kwargs.update(args)
        munged_url = url.rsplit('?', 1)[0]
        munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
        munged_url = munged_url.replace('-', '_')

        callback = "%s_%s" % (method.lower(), munged_url)

        if not hasattr(self, callback):
            raise AssertionError('Called unknown API method: %s %s, '
                                 'expected fakes method name: %s' %
                                 (method, url, callback))

        # Note the call
        self.callstack.append((method, url, kwargs.get('body', None)))

        status, body = getattr(self, callback)(**kwargs)
        if hasattr(status, 'items'):
            return httplib2.Response(status), body
        else:
            return httplib2.Response({"status": status}), body
예제 #2
0
    def _cs_request(self, url, method, **kwargs):
        # Check that certain things are called correctly
        if method in ['GET', 'DELETE']:
            assert 'body' not in kwargs
        elif method == 'PUT':
            assert 'body' in kwargs

        # Call the method
        args = urlutils.parse_qsl(urlutils.urlparse(url)[4])
        kwargs.update(args)
        munged_url = url.rsplit('?', 1)[0]
        munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
        munged_url = munged_url.replace('-', '_')

        callback = "%s_%s" % (method.lower(), munged_url)

        if not hasattr(self, callback):
            raise AssertionError('Called unknown API method: %s %s, '
                                 'expected fakes method name: %s' %
                                 (method, url, callback))

        # Note the call
        self.callstack.append((method, url, kwargs.get('body', None)))

        status, body = getattr(self, callback)(**kwargs)
        if hasattr(status, 'items'):
            return httplib2.Response(status), body
        else:
            return httplib2.Response({"status": status}), body
    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 = urlutils.urlparse(url).query
        params = {}
        params.update(urlutils.parse_qsl(query_string))
        self.assertEqual('2', params['limit'])
        self.assertEqual('bar', params['foo'])
    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 = urlutils.urlparse(url).query
        params = {}
        params.update(urlutils.parse_qsl(query_string))
        self.assertEqual('2', params['limit'])
        self.assertEqual('bar', params['foo'])