def test_append_query_strings(self):
        url = "test-url"
        self.assertEqual(url, common.append_query_strings(url))

        self.assertEqual(url, common.append_query_strings(
            url, limit=None, marker=None))

        limit = "test-limit"
        marker = "test-marker"
        result = common.append_query_strings(url, limit=limit, marker=marker)
        self.assertTrue(result.startswith(url + '?'))
        self.assertIn("limit=%s" % limit, result)
        self.assertIn("marker=%s" % marker, result)
        self.assertEqual(result.count('&'), 1)

        opts = {}
        self.assertEqual(url, common.append_query_strings(
            url, limit=None, marker=None, **opts))

        opts = {'key1': 'value1', 'key2': None}
        result = common.append_query_strings(url, limit=None, marker=marker,
                                             **opts)
        self.assertTrue(result.startswith(url + '?'))
        self.assertEqual(result.count('&'), 1)
        self.assertNotIn("limit=%s" % limit, result)
        self.assertIn("marker=%s" % marker, result)
        self.assertIn("key1=%s" % opts['key1'], result)
        self.assertNotIn("key2=%s" % opts['key2'], result)
Exemple #2
0
    def test_append_query_strings(self):
        url = "test-url"
        self.assertEqual(url, common.append_query_strings(url))

        self.assertEqual(
            url, common.append_query_strings(url, limit=None, marker=None))

        limit = "test-limit"
        marker = "test-marker"
        result = common.append_query_strings(url, limit=limit, marker=marker)
        self.assertTrue(result.startswith(url + '?'))
        self.assertIn("limit=%s" % limit, result)
        self.assertIn("marker=%s" % marker, result)
        self.assertEqual(1, result.count('&'))

        opts = {}
        self.assertEqual(
            url,
            common.append_query_strings(url, limit=None, marker=None, **opts))

        opts = {'key1': 'value1', 'key2': None}
        result = common.append_query_strings(url,
                                             limit=None,
                                             marker=marker,
                                             **opts)
        self.assertTrue(result.startswith(url + '?'))
        self.assertEqual(1, result.count('&'))
        self.assertNotIn("limit=%s" % limit, result)
        self.assertIn("marker=%s" % marker, result)
        self.assertIn("key1=%s" % opts['key1'], result)
        self.assertNotIn("key2=%s" % opts['key2'], result)
Exemple #3
0
    def list(self, instance_id=None, project_id=None):
        query_strings = {}
        if instance_id:
            query_strings["instance_id"] = instance_id
        if project_id:
            query_strings["project_id"] = project_id

        url = common.append_query_strings('/backup_strategies',
                                          **query_strings)

        return self._list(url, "backup_strategies")
 def _modules_get(self, instance, from_guest=None, include_contents=None):
     url = "/instances/%s/modules" % base.getid(instance)
     query_strings = {}
     if from_guest is not None:
         query_strings["from_guest"] = from_guest
     if include_contents is not None:
         query_strings["include_contents"] = include_contents
     url = common.append_query_strings(url, **query_strings)
     resp, body = self.api.client.get(url)
     common.check_for_exceptions(resp, body, url)
     return [core_modules.Module(self, module, loaded=True)
             for module in body['modules']]
 def _modules_get(self, instance, from_guest=None, include_contents=None):
     url = "/instances/%s/modules" % base.getid(instance)
     query_strings = {}
     if from_guest is not None:
         query_strings["from_guest"] = from_guest
     if include_contents is not None:
         query_strings["include_contents"] = include_contents
     url = common.append_query_strings(url, **query_strings)
     resp, body = self.api.client.get(url)
     common.check_for_exceptions(resp, body, url)
     return [core_modules.Module(self, module, loaded=True)
             for module in body['modules']]
Exemple #6
0
    def delete(self, instance_id=None, project_id=None):
        url = "/backup_strategies"
        query_strings = {}
        if instance_id:
            query_strings["instance_id"] = instance_id
        if project_id:
            query_strings["project_id"] = project_id

        url = common.append_query_strings('/backup_strategies',
                                          **query_strings)

        resp, body = self._delete(url)
        common.check_for_exceptions(resp, body, url)
Exemple #7
0
 def _paginated(self, url, response_key, limit=None, marker=None,
                query_strings=None):
     query_strings = query_strings or {}
     url = common.append_query_strings(url, limit=limit, marker=marker,
                                       **query_strings)
     resp, body = self.api.client.get(url)
     if not body:
         raise Exception("Call to " + url + " did not return a body.")
     links = body.get('links', [])
     next_links = [link['href'] for link in links if link['rel'] == 'next']
     next_marker = None
     for link in next_links:
         # Extract the marker from the url.
         parsed_url = parse.urlparse(link)
         query_dict = dict(parse.parse_qsl(parsed_url.query))
         next_marker = query_dict.get('marker')
     data = [self.resource_class(self, res) for res in body[response_key]]
     return common.Paginated(data, next_marker=next_marker, links=links)
Exemple #8
0
 def _paginated(self, url, response_key, limit=None, marker=None,
                query_strings=None):
     query_strings = query_strings or {}
     url = common.append_query_strings(url, limit=limit, marker=marker,
                                       **query_strings)
     resp, body = self.api.client.get(url)
     if not body:
         raise Exception("Call to " + url + " did not return a body.")
     links = body.get('links', [])
     next_links = [link['href'] for link in links if link['rel'] == 'next']
     next_marker = None
     for link in next_links:
         # Extract the marker from the url.
         parsed_url = parse.urlparse(link)
         query_dict = dict(parse.parse_qsl(parsed_url.query))
         next_marker = query_dict.get('marker')
     data = [self.resource_class(self, res) for res in body[response_key]]
     return common.Paginated(data, next_marker=next_marker, links=links)