Exemplo n.º 1
0
def test_get_test_value():
    """
    Test _get_test_value when opts contains different values
    """
    test_arg = "test"
    with patch.dict(state.__opts__, {test_arg: True}):
        assert state._get_test_value(
            test=None
        ), "Failure when {} is True in __opts__".format(test_arg)

    with patch.dict(config.__pillar__, {test_arg: "blah"}):
        assert not state._get_test_value(
            test=None
        ), "Failure when {} is blah in __opts__".format(test_arg)

    with patch.dict(config.__pillar__, {test_arg: "true"}):
        assert not state._get_test_value(
            test=None
        ), "Failure when {} is true in __opts__".format(test_arg)

    with patch.dict(config.__opts__, {test_arg: False}):
        assert not state._get_test_value(
            test=None
        ), "Failure when {} is False in __opts__".format(test_arg)

    with patch.dict(config.__opts__, {}):
        assert not state._get_test_value(
            test=None
        ), "Failure when {} does not exist in __opts__".format(test_arg)

    with patch.dict(config.__pillar__, {test_arg: None}):
        assert (
            state._get_test_value(test=None) is None
        ), "Failure when {} is None in __opts__".format(test_arg)

    with patch.dict(config.__pillar__, {test_arg: True}):
        assert state._get_test_value(
            test=None
        ), "Failure when {} is True in __pillar__".format(test_arg)

    with patch.dict(config.__pillar__, {"master": {test_arg: True}}):
        assert state._get_test_value(
            test=None
        ), "Failure when {} is True in master __pillar__".format(test_arg)

    with patch.dict(config.__pillar__, {"master": {test_arg: False}}):
        with patch.dict(config.__pillar__, {test_arg: True}):
            assert state._get_test_value(
                test=None
            ), "Failure when {} is False in master __pillar__ and True in pillar".format(
                test_arg
            )

    with patch.dict(config.__pillar__, {"master": {test_arg: True}}):
        with patch.dict(config.__pillar__, {test_arg: False}):
            assert not state._get_test_value(
                test=None
            ), "Failure when {} is True in master __pillar__ and False in pillar".format(
                test_arg
            )

    with patch.dict(state.__opts__, {"test": False}):
        assert not state._get_test_value(
            test=None
        ), "Failure when {} is False in __opts__".format(test_arg)

    with patch.dict(state.__opts__, {"test": False}):
        with patch.dict(config.__pillar__, {"master": {test_arg: True}}):
            assert state._get_test_value(
                test=None
            ), "Failure when {} is False in __opts__".format(test_arg)

    with patch.dict(state.__opts__, {}):
        assert state._get_test_value(test=True), "Failure when test is True as arg"
Exemplo n.º 2
0
    def test_get_test_value(self):
        '''
        Test _get_test_value when opts contains different values
        '''
        test_arg = 'test'
        with patch.dict(state.__opts__, {test_arg: True}):
            self.assertTrue(
                state._get_test_value(test=None),
                msg='Failure when {0} is True in __opts__'.format(test_arg))

        with patch.dict(config.__pillar__, {test_arg: 'blah'}):
            self.assertFalse(
                state._get_test_value(test=None),
                msg='Failure when {0} is blah in __opts__'.format(test_arg))

        with patch.dict(config.__pillar__, {test_arg: 'true'}):
            self.assertFalse(
                state._get_test_value(test=None),
                msg='Failure when {0} is true in __opts__'.format(test_arg))

        with patch.dict(config.__opts__, {test_arg: False}):
            self.assertFalse(
                state._get_test_value(test=None),
                msg='Failure when {0} is False in __opts__'.format(test_arg))

        with patch.dict(config.__opts__, {}):
            self.assertFalse(
                state._get_test_value(test=None),
                msg='Failure when {0} does not exist in __opts__'.format(
                    test_arg))

        with patch.dict(config.__pillar__, {test_arg: None}):
            self.assertEqual(
                state._get_test_value(test=None),
                None,
                msg='Failure when {0} is None in __opts__'.format(test_arg))

        with patch.dict(config.__pillar__, {test_arg: True}):
            self.assertTrue(
                state._get_test_value(test=None),
                msg='Failure when {0} is True in __pillar__'.format(test_arg))

        with patch.dict(config.__pillar__, {'master': {test_arg: True}}):
            self.assertTrue(
                state._get_test_value(test=None),
                msg='Failure when {0} is True in master __pillar__'.format(
                    test_arg))

        with patch.dict(config.__pillar__, {'master': {test_arg: False}}):
            with patch.dict(config.__pillar__, {test_arg: True}):
                self.assertTrue(
                    state._get_test_value(test=None),
                    msg=
                    'Failure when {0} is False in master __pillar__ and True in pillar'
                    .format(test_arg))

        with patch.dict(config.__pillar__, {'master': {test_arg: True}}):
            with patch.dict(config.__pillar__, {test_arg: False}):
                self.assertFalse(
                    state._get_test_value(test=None),
                    msg=
                    'Failure when {0} is True in master __pillar__ and False in pillar'
                    .format(test_arg))

        with patch.dict(state.__opts__, {'test': False}):
            self.assertFalse(
                state._get_test_value(test=None),
                msg='Failure when {0} is False in __opts__'.format(test_arg))

        with patch.dict(state.__opts__, {'test': False}):
            with patch.dict(config.__pillar__, {'master': {test_arg: True}}):
                self.assertTrue(
                    state._get_test_value(test=None),
                    msg='Failure when {0} is False in __opts__'.format(
                        test_arg))

        with patch.dict(state.__opts__, {}):
            self.assertTrue(state._get_test_value(test=True),
                            msg='Failure when test is True as arg')