# Copyright (c) 2014 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import six

from murano.dsl import dsl
from murano.dsl import exceptions
from murano.tests.unit.dsl.foundation import object_model as om
from murano.tests.unit.dsl.foundation import test_case


class TestContracts(test_case.DslTestCase):
    def setUp(self):
        super(TestContracts, self).setUp()
        self._runner = self.new_runner(
            om.Object(
                'ContractExamples',
                ordinaryProperty='PROPERTY',
                sampleClass=om.Object(
                    'SampleClass1',
                    stringProperty='string1',
                    classProperty=om.Object(
                        'SampleClass2',
                        class2Property='string2'))))

    def test_string_contract(self):
        result = self._runner.testStringContract('qwerty')
        self.assertIsInstance(result, six.string_types)
        self.assertEqual('qwerty', result)

    def test_string_from_number_contract(self):
        result = self._runner.testStringContract(123)
        self.assertIsInstance(result, six.string_types)
        self.assertEqual('123', result)

    def test_string_null_contract(self):
        self.assertIsNone(self._runner.testStringContract(None))

    def test_int_contract(self):
        result = self._runner.testIntContract(123)