def test_profile_validate(self): self._setup_fakes() expected_resp = { 'created_at': None, 'domain': '', 'id': None, 'metadata': None, 'name': 'validated_profile', 'project': 'profile_test_project', 'type': 'TestProfile-1.0', 'updated_at': None, 'user': '******', 'spec': { 'type': 'TestProfile', 'version': '1.0', 'properties': { 'INT': 1, 'STR': 'str', 'LIST': ['v1', 'v2'], 'MAP': { 'KEY1': 1, 'KEY2': 'v2' }, } } } body = vorp.ProfileValidateRequestBody(spec=self.spec) request = vorp.ProfileValidateRequest(profile=body) resp = self.svc.profile_validate(self.ctx, request.obj_to_primitive()) self.assertEqual(expected_resp, resp)
def test_profile_validate_failed(self): self._setup_fakes() mock_do_validate = self.patchobject(fakes.TestProfile, 'do_validate') mock_do_validate.side_effect = exc.ESchema(message='BOOM') body = vorp.ProfileValidateRequestBody(spec=self.spec) request = vorp.ProfileValidateRequest(profile=body) ex = self.assertRaises(rpc.ExpectedException, self.svc.profile_validate, self.ctx, request.obj_to_primitive()) self.assertEqual(exc.InvalidSpec, ex.exc_info[0]) self.assertEqual('BOOM', six.text_type(ex.exc_info[1]))
def test_request_to_primitive(self): spec = copy.deepcopy(self.spec) body = profiles.ProfileValidateRequestBody(spec=spec) sot = profiles.ProfileValidateRequest(profile=body) res = sot.obj_to_primitive() self.assertIn('profile', res['senlin_object.changes']) self.assertEqual('ProfileValidateRequest', res['senlin_object.name']) self.assertEqual('senlin', res['senlin_object.namespace']) self.assertEqual('1.0', res['senlin_object.version']) profile_body = res['senlin_object.data']['profile'] self.assertIn('spec', profile_body['senlin_object.changes']) self.assertEqual( 'ProfileValidateRequestBody', profile_body['senlin_object.name']) self.assertEqual('senlin', profile_body['senlin_object.namespace']) self.assertEqual('1.0', profile_body['senlin_object.version']) data = jsonutils.loads(profile_body['senlin_object.data']['spec']) self.assertEqual(u'os.nova.server', data['type']) self.assertEqual(u'1.0', data['version'])
def test_validate_request(self): spec = copy.deepcopy(self.spec) body = profiles.ProfileValidateRequestBody(spec=spec) sot = profiles.ProfileValidateRequest(profile=body) self.assertIsInstance(sot.profile, profiles.ProfileValidateRequestBody)