Exemplo n.º 1
0
    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')
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    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')
Exemplo n.º 5
0
    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')
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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')
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
    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')
Exemplo n.º 14
0
    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')
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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)
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
    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)
Exemplo n.º 21
0
        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)
Exemplo n.º 22
0
        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)
Exemplo n.º 23
0
 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([])
Exemplo n.º 24
0
 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')
Exemplo n.º 25
0
 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
Exemplo n.º 26
0
 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([])
Exemplo n.º 27
0
 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')
Exemplo n.º 28
0
 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')
Exemplo n.º 29
0
 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
Exemplo n.º 30
0
    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)
Exemplo n.º 31
0
 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
Exemplo n.º 32
0
    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)
Exemplo n.º 33
0
 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')
Exemplo n.º 34
0
 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')
Exemplo n.º 35
0
 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
Exemplo n.º 36
0
 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')
Exemplo n.º 37
0
    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)
Exemplo n.º 38
0
 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')
Exemplo n.º 39
0
    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)
Exemplo n.º 40
0
 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)
Exemplo n.º 41
0
 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')
Exemplo n.º 42
0
 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)