How to use the freezer.apiclient.exceptions function in freezer

To help you get started, we’ve selected a few freezer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / freezer / tests / unit / apiclient / test_apiclient_sessions.py View on Github external
def test_update_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
        self.mock_response.json.return_value = {
            "patch": {"status": "bamboozled"},
            "version": 12,
            "session_id": "d454beec-1f3c-4d11-aa1a-404116a40502"
        }
        self.mock_response.status_code = 404
        self.mock_response.text = '{"title": "Not Found","description":"No document found with ID d454beec-1f3c-4d11-aa1a-404116a40502x"}'
        mock_requests.patch.return_value = self.mock_response
        self.assertRaises(exceptions.ApiClientException, self.session_manager.update,
                          'd454beec-1f3c-4d11-aa1a-404116a40502', {'status': 'bamboozled'})
github openstack / freezer / tests / unit / apiclient / test_apiclient_actions.py View on Github external
def test_create_fail_when_api_return_error_code(self, mock_requests):
        self.mock_response.status_code = 500
        mock_requests.post.return_value = self.mock_response
        self.assertRaises(exceptions.ApiClientException, self.action_manager.create, {'action': 'metadata'})
github openstack / freezer / tests / unit / apiclient / test_apiclient_sessions.py View on Github external
def test_create_raise_ApiClientException_when_api_return_error_code(self, mock_requests):
        self.mock_response.status_code = 500
        mock_requests.post.return_value = self.mock_response
        self.assertRaises(exceptions.ApiClientException, self.session_manager.create, {'session': 'metadata'})
github openstack / freezer / tests / unit / apiclient / test_apiclient_registration.py View on Github external
def test_delete_fail(self, mock_requests):
        mock_response = Mock()
        mock_response.status_code = 500
        mock_requests.delete.return_value = mock_response
        self.assertRaises(exceptions.ApiClientException, self.r.delete, 'test_client_id')
github openstack / freezer / tests / unit / apiclient / test_apiclient_backup.py View on Github external
def test_create_fail_when_api_return_error_code(self, mock_requests):
        mock_response = Mock()
        mock_response.status_code = 500
        mock_requests.post.return_value = mock_response
        self.assertRaises(exceptions.ApiClientException, self.b.create, {'backup': 'metadata'})
github openstack / freezer / freezer / apiclient / registration.py View on Github external
def create(self, client_info):
        r = requests.post(self.endpoint,
                          data=json.dumps(client_info),
                          headers=self.headers,
                          verify=self.verify)
        if r.status_code != 201:
            raise exceptions.ApiClientException(r)
        client_id = r.json()['client_id']
        return client_id
github openstack / freezer / freezer / apiclient / registration.py View on Github external
def get(self, client_id):
        endpoint = self.endpoint + client_id
        r = requests.get(endpoint, headers=self.headers, verify=self.verify)
        if r.status_code == 200:
            return r.json()
        if r.status_code == 404:
            return None
        raise exceptions.ApiClientException(r)
github openstack / freezer / freezer / apiclient / jobs.py View on Github external
:param job_id: the id of the job to start
        :return: the response obj:
                 {
                    result: string 'success' or 'already stopped'
                 }
        """
        # endpoint /v1/jobs/{job_id}/event
        endpoint = '{0}{1}/event'.format(self.endpoint, job_id)
        doc = {"abort": None}
        r = requests.post(endpoint,
                          headers=self.headers,
                          data=json.dumps(doc),
                          verify=self.verify)
        if r.status_code != 202:
            raise exceptions.ApiClientException(r)
        return r.json()
github openstack / freezer / freezer / apiclient / backups.py View on Github external
:param limit: number of result to return (optional, default 10)
        :param offset: order of first document (optional, default 0)
        :param search: structured query (optional)
                       can contain:
                       * "time_before": timestamp
                       * "time_after": timestamp
                       Example:
                       { "time_before": 1428529956 }
        """
        data = json.dumps(search) if search else None
        query = {'limit': int(limit), 'offset': int(offset)}
        r = requests.get(self.endpoint, headers=self.headers,
                         params=query, data=data, verify=self.verify)
        if r.status_code != 200:
            raise exceptions.ApiClientException(r)

        return r.json()['backups']
github openstack / freezer / freezer / apiclient / jobs.py View on Github external
def create(self, doc, job_id=''):
        job_id = job_id or doc.get('job_id', '')
        endpoint = self.endpoint + job_id
        doc['client_id'] = doc.get('client_id', '') or self.client.client_id
        r = requests.post(endpoint,
                          data=json.dumps(doc),
                          headers=self.headers,
                          verify=self.verify)
        if r.status_code != 201:
            raise exceptions.ApiClientException(r)
        job_id = r.json()['job_id']
        return job_id