Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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]))
Ejemplo n.º 3
0
    def test_request_body_to_primitive(self):
        spec = copy.deepcopy(self.spec)
        body = profiles.ProfileValidateRequestBody(spec=spec)
        res = body.obj_to_primitive()

        self.assertIn('spec', res['senlin_object.changes'])
        self.assertEqual(
            'ProfileValidateRequestBody', res['senlin_object.name'])
        self.assertEqual('senlin', res['senlin_object.namespace'])
        self.assertEqual('1.0', res['senlin_object.version'])

        data = jsonutils.loads(res['senlin_object.data']['spec'])
        self.assertEqual(u'os.nova.server', data['type'])
        self.assertEqual(u'1.0', data['version'])
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test_validate_request_body(self):
        spec = copy.deepcopy(self.spec)
        body = profiles.ProfileValidateRequestBody(spec=spec)

        self.assertEqual('os.nova.server', body.spec['type'])
        self.assertEqual('1.0', body.spec['version'])