def transmute_from_with_child_mapping(self): data = '{"other": "sample", "child": {"test": "sample stuff"}}' result = JsonTransmuter.transmute_from(data, TestChildMapping) require(result.child).not_to.be_none() expect(result.child.test).to.equal('sample stuff')
def _post_target(self): resp = self.app.post_json( '/v1/tenant/targets', VALID_TARGETS['nova_target_with_rax_auth']['body']) require(resp.status_int).to.equal(201) require(resp.json).to.contain('target_id') return resp
def transmute_from_with_list_of_child_mappings(self): data = '{"children": [{"test": "sample1"}, {"test": "sample2"}]}' result = JsonTransmuter.transmute_from(data, TestListChildMapping) require(result.children).not_to.be_none() expect(len(result.children)).to.equal(2) expect(result.children[0].test).to.equal('sample1') expect(result.children[1].test).to.equal('sample2')
def can_encrypt_and_decrypt(self): enc_file = tempfile.NamedTemporaryFile() file_data = 'something' rekey.encrypt_file(file_data, enc_file.name, self.vault_key) require(len(open(enc_file.name, 'rb').read())).to.be_greater_than(0) pt = rekey.decrypt_file(enc_file.name, self.vault_key) require(pt).to.equal(file_data)
def should_404_on_bad_nova_ping(self, get_driver): post_resp = self._post_target() target_id = post_resp.json['target_id'] get_driver.side_effect = Exception('Provider is unavailable') resp = self.app.get('/v1/tenant/targets/{0}/ping'.format(target_id), expect_errors=True) require(resp.status_int).to.equal(404)
def can_encrypt_and_decrypt(self): enc_file = tempfile.NamedTemporaryFile() file_data = "something" rekey.encrypt_file(file_data, enc_file.name, self.vault_key) require(len(open(enc_file.name, "rb").read())).to.be_greater_than(0) pt = rekey.decrypt_file(enc_file.name, self.vault_key) require(pt).to.equal(file_data)
def can_get_job(self): post_resp = self._post_job() job_id = post_resp.json['job_id'] resp = self.app.get('/v1/tenant/jobs/{0}'.format(job_id)) require(resp.status_int).to.equal(200) expect(resp.json).to.contain('id') expect(resp.json).to.contain('actions') expect(resp.json).to.contain('name') expect(resp.json['id']).to.equal(job_id)
def can_get_schedule(self): resp = self.app.get(self.schedule_path) require(resp.status_int).to.equal(200) expect(resp.json).to.contain('id') expect(resp.json).to.contain('name') require(resp.json).to.contain('entries') expect(len(resp.json['entries'])).to.equal(1) expect(resp.json['entries'][0]).to.contain('job_id') expect(resp.json['entries'][0]).to.contain('delay')
def can_get_target(self): post_resp = self._post_target() target_id = post_resp.json['target_id'] resp = self.app.get('/v1/tenant/targets/{0}'.format(target_id)) require(resp.status_int).to.equal(200) expect(resp.json).to.contain('authentication') expect(resp.json).to.contain('address') expect(resp.json).to.contain('type') expect(resp.json).to.contain('id') expect(resp.json).to.contain('name') expect(resp.json['id']).to.equal(target_id)
def should_404_on_bad_ssh_ping(self, connect): post_resp = self.app.post_json( '/v1/tenant/targets', VALID_TARGETS['hostname_target_with_ssh_password_auth']['body']) expect(post_resp.status_int).to.equal(201) expect(post_resp.json).to.contain('target_id') target_id = post_resp.json['target_id'] connect.side_effect = SSHException resp = self.app.get('/v1/tenant/targets/{0}/ping'.format(target_id), expect_errors=True) require(resp.status_int).to.equal(404)
def can_ping_ssh_target(self, connect): post_resp = self.app.post_json( '/v1/tenant/targets', VALID_TARGETS['hostname_target_with_ssh_password_auth']['body']) expect(post_resp.status_int).to.equal(201) expect(post_resp.json).to.contain('target_id') target_id = post_resp.json['target_id'] connect.return_value = None resp = self.app.get('/v1/tenant/targets/{0}/ping'.format(target_id), expect_errors=True) require(resp.status_int).to.equal(200)
def can_run_schedule(self, body): schedule_body = json.loads(body) # post a schedule post_resp = self.app.post_json('/v1/user/schedules', schedule_body) require(post_resp.status_int).to.equal(201) require(post_resp.json).to.contain('schedule_id') schedule_id = post_resp.json['schedule_id'] schedule_path = '/v1/user/schedules/{0}'.format(schedule_id) # run the schedule with mock.patch('rift.api.resources.execute_job') as execute_job: resp = self.app.head(schedule_path) expect(resp.status_int).to.equal(200) n_entries = len(schedule_body['entries']) expect(len(execute_job.mock_calls)).to.equal(n_entries)
def can_list_jobs(self): resp = self.app.get('/v1/tenant/jobs') require(resp.status_int).to.equal(200) require(resp.json).to.contain('jobs') expect(resp.json['jobs']).to.equal([])
def can_post(self, body): body = json.loads(body) resp = self.app.post_json('/v1/tenant/jobs', body) require(resp.status_int).to.equal(201) expect(resp.json).to.contain('job_id')
def _post_job(self): body = json.loads(VALID_JOBS['job_with_empty_actions']['body']) post_resp = self.app.post_json('/v1/tenant/jobs', body) require(post_resp.status_int).to.equal(201) require(post_resp.json).to.contain('job_id') return post_resp
def can_get_version(self): resp = self.app.get('/') require(resp.json).to.contain('versions') require(resp.json['versions']).to.contain('v1') expect(resp.json['versions']['v1']).to.contain('status') expect(resp.json['versions']['v1']).to.contain('build')
def _post_schedule(self, body): resp = self.app.post_json('/v1/user/schedules', body) require(resp.status_int).to.equal(201) require(resp.json).to.contain('schedule_id') return resp
def can_ping_nova_target(self): post_resp = self._post_target() target_id = post_resp.json['target_id'] resp = self.app.get('/v1/tenant/targets/{0}/ping'.format(target_id)) require(resp.status_int).to.equal(200)
def can_delete_schedule(self): resp = self.app.delete(self.schedule_path) require(resp.status_int).to.equal(200) resp = self.app.get(self.schedule_path, expect_errors=True) expect(resp.status_int).to.equal(404)
def can_post_self(self, body): body = json.loads(body) resp = self.app.post_json('/v1/user/schedules', body) require(resp.status_int).to.equal(201) expect(resp.json).to.contain('schedule_id')
def can_post(self, body): resp = self.app.post_json('/v1/tenant/targets', body) require(resp.status_int).to.equal(201) expect(resp.json).to.contain('target_id')
def can_list_schedules(self): resp = self.app.get('/v1/user/schedules') require(resp.status_int).to.equal(200) require(resp.json).to.contain('schedules') expect(len(resp.json['schedules'])).to.equal(1)