def test_release_good_response(self):
     with open(self.keyfile, 'w') as f:
         f.write(self.key_content)
     service_url = 'http://test_url'
     self.ctx.instance.runtime_properties['host_id'] = \
         self.good_response_acquire_key['host_id']
     self.ctx.instance.runtime_properties['key'] = self.keyfile
     with requests_mock.mock() as m:
         m.delete('{0}/hosts/{1}'.format(service_url, self.host_id),
                  content=json.dumps(self.good_response_acquire_key),
                  status_code=requests.codes.OK)
         tasks.release(service_url, ctx=self.ctx)
     self.assertFalse(os.path.exists(self.keyfile))
Exemplo n.º 2
0
 def test_release_good_response(self):
     with open(self.keyfile, 'w') as f:
         f.write(self.key_content)
     service_url = 'http://test_url'
     self.ctx.instance.runtime_properties['host_id'] = \
         self.good_response_acquire_key['host_id']
     self.ctx.instance.runtime_properties['key'] = self.keyfile
     with requests_mock.mock() as m:
         m.delete('{0}/hosts/{1}'.format(service_url, self.host_id),
                  content=json.dumps(self.good_response_acquire_key),
                  status_code=requests.codes.OK)
         tasks.release(service_url, ctx=self.ctx)
     self.assertFalse(os.path.exists(self.keyfile))
    def test_success(self, mock):
        '''DELETE /host/<host_id>/deallocate with success response'''
        with open(self.opts.keyfile, 'w') as f_key:
            f_key.write(self.opts.keyfile_content)
        self.ctx.instance.runtime_properties['host_id'] = self.opts.host_id
        self.ctx.instance.runtime_properties['key'] = self.opts.keyfile

        mock.register_uri(
            'DELETE',
            '{0}/host/{1}/deallocate'.format(
                self.endpoint, self.opts.host_id),
            json={},
            status_code=httplib.NO_CONTENT
        )

        tasks.release(self.endpoint, ctx=self.ctx)
        self.assertFalse(os.path.exists(self.opts.keyfile))