Beispiel #1
0
    def test_present(self):
        '''
            Test to generate a locale if it is not present
        '''
        ret = [{'changes': {},
                'comment': 'Locale salt is already present', 'name': 'salt',
                'result': True},
               {'changes': {},
                'comment': 'Locale salt needs to be generated', 'name': 'salt',
                'result': None},
               {'changes': {'locale': 'salt'},
                'comment': 'Generated locale salt', 'name': 'salt',
                'result': True},
               {'changes': {}, 'comment': 'Failed to generate locale salt',
                'name': 'salt', 'result': False}]

        mock = MagicMock(side_effect=[True, False, False, False])
        with patch.dict(locale.__salt__, {"locale.avail": mock}):
            self.assertDictEqual(locale.present("salt"), ret[0])

            with patch.dict(locale.__opts__, {"test": True}):
                self.assertDictEqual(locale.present("salt"), ret[1])

            with patch.dict(locale.__opts__, {"test": False}):
                mock = MagicMock(side_effect=[True, False])
                with patch.dict(locale.__salt__, {"locale.gen_locale": mock}):
                    self.assertDictEqual(locale.present("salt"), ret[2])

                    self.assertDictEqual(locale.present("salt"), ret[3])
Beispiel #2
0
    def test_present(self):
        '''
            Test to generate a locale if it is not present
        '''
        ret = [{'changes': {},
                'comment': 'Locale salt is already present', 'name': 'salt',
                'result': True},
               {'changes': {},
                'comment': 'Locale salt needs to be generated', 'name': 'salt',
                'result': None},
               {'changes': {'locale': 'salt'},
                'comment': 'Generated locale salt', 'name': 'salt',
                'result': True},
               {'changes': {}, 'comment': 'Failed to generate locale salt',
                'name': 'salt', 'result': False}]

        mock = MagicMock(side_effect=[True, False, False, False])
        with patch.dict(locale.__salt__, {"locale.avail": mock}):
            self.assertDictEqual(locale.present("salt"), ret[0])

            with patch.dict(locale.__opts__, {"test": True}):
                self.assertDictEqual(locale.present("salt"), ret[1])

            with patch.dict(locale.__opts__, {"test": False}):
                mock = MagicMock(side_effect=[True, False])
                with patch.dict(locale.__salt__, {"locale.gen_locale": mock}):
                    self.assertDictEqual(locale.present("salt"), ret[2])

                    self.assertDictEqual(locale.present("salt"), ret[3])
Beispiel #3
0
def test_present():
    """
    Test to generate a locale if it is not present
    """
    ret = [
        {
            "changes": {},
            "comment": "Locale salt is already present",
            "name": "salt",
            "result": True,
        },
        {
            "changes": {},
            "comment": "Locale salt needs to be generated",
            "name": "salt",
            "result": None,
        },
        {
            "changes": {
                "locale": "salt"
            },
            "comment": "Generated locale salt",
            "name": "salt",
            "result": True,
        },
        {
            "changes": {},
            "comment": "Failed to generate locale salt",
            "name": "salt",
            "result": False,
        },
    ]

    mock = MagicMock(side_effect=[True, False, False, False])
    with patch.dict(locale.__salt__, {"locale.avail": mock}):
        assert locale.present("salt") == ret[0]

        with patch.dict(locale.__opts__, {"test": True}):
            assert locale.present("salt") == ret[1]

        with patch.dict(locale.__opts__, {"test": False}):
            mock = MagicMock(side_effect=[True, False])
            with patch.dict(locale.__salt__, {"locale.gen_locale": mock}):
                assert locale.present("salt") == ret[2]

                assert locale.present("salt") == ret[3]