Esempio n. 1
0
 def test_get_locale_with_no_systemd_redhat(self):
     '''
     Test getting current system locale with systemd and dbus available on RedHat.
     :return:
     '''
     localemod.get_locale()
     assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^LANG=" /etc/sysconfig/i18n'
Esempio n. 2
0
 def test_get_locale_with_systemd_and_dbus_sle12(self):
     '''
     Test getting current system locale with systemd and dbus available on SLE12.
     :return:
     '''
     localemod.get_locale()
     assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^RC_LANG" /etc/sysconfig/language'
Esempio n. 3
0
    def test_get_locale(self):
        '''
        Test for Get the current system locale
        '''
        with patch.dict(localemod.__context__, {'systemd.sd_booted': True}):
            localemod.HAS_DBUS = True
            with patch.object(localemod,
                              '_parse_dbus_locale',
                              return_value={'LANG': 'A'}):
                self.assertEqual('A', localemod.get_locale())
                localemod._parse_dbus_locale.assert_called_once_with()

            localemod.HAS_DBUS = False
            with patch.object(localemod,
                              '_parse_localectl',
                              return_value={'LANG': 'A'}):
                self.assertEqual('A', localemod.get_locale())
                localemod._parse_localectl.assert_called_once_with()

        with patch.dict(localemod.__context__, {'systemd.sd_booted': False}):
            with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}):
                with patch.dict(localemod.__salt__,
                                {'cmd.run': MagicMock(return_value='A')}):
                    self.assertEqual(localemod.get_locale(), 'A')

            with patch.dict(localemod.__grains__, {'os_family': ['RedHat']}):
                with patch.dict(localemod.__salt__,
                                {'cmd.run': MagicMock(return_value='A=B')}):
                    self.assertEqual(localemod.get_locale(), 'B')

            with patch.dict(localemod.__grains__, {'os_family': ['Unknown']}):
                self.assertRaises(CommandExecutionError, localemod.get_locale)
Esempio n. 4
0
 def test_get_locale_with_no_systemd_slowlaris(self):
     '''
     Test getting current system locale with systemd and dbus available on Solaris.
     :return:
     '''
     localemod.get_locale()
     assert localemod.__salt__['cmd.run'].call_args[0][0] == 'grep "^LANG=" /etc/default/init'
Esempio n. 5
0
 def test_get_locale_with_no_systemd_gentoo(self):
     '''
     Test getting current system locale with systemd and dbus available on Gentoo.
     :return:
     '''
     localemod.get_locale()
     assert localemod.__salt__['cmd.run'].call_args[0][0] == 'eselect --brief locale show'
Esempio n. 6
0
 def test_get_locale_with_no_systemd_gentoo(self):
     """
     Test getting current system locale with systemd and dbus available on Gentoo.
     :return:
     """
     localemod.get_locale()
     assert (localemod.__salt__["cmd.run"].call_args[0][0] ==
             "eselect --brief locale show")
Esempio n. 7
0
    def test_get_locale_debian(self):
        with patch.dict(localemod.__grains__, {'os_family': ['Debian']}):
            with patch.object(localemod, '_localectl_get', return_value=True):
                self.assertTrue(localemod.get_locale())

            with patch.dict(localemod.__salt__, {'cmd.run':
                                                 MagicMock(return_value='LC_ALL=C')}):
                self.assertEqual(localemod.get_locale(), 'C')
Esempio n. 8
0
 def test_get_locale_with_no_systemd_unknown(self):
     """
     Test getting current system locale with systemd and dbus available on Gentoo.
     :return:
     """
     with pytest.raises(CommandExecutionError) as exc_info:
         localemod.get_locale()
     assert '"DrunkDragon" is unsupported' in str(exc_info.value)
Esempio n. 9
0
 def test_get_locale_with_no_systemd_unknown(self):
     '''
     Test getting current system locale with systemd and dbus available on Gentoo.
     :return:
     '''
     with pytest.raises(CommandExecutionError) as err:
         localemod.get_locale()
     assert '"DrunkDragon" is unsupported' in six.text_type(err)
Esempio n. 10
0
 def test_get_locale_with_no_systemd_debian(self):
     """
     Test getting current system locale with systemd and dbus available on Debian.
     :return:
     """
     localemod.get_locale()
     assert (localemod.__salt__["cmd.run"].call_args[0][0] ==
             'grep "^LANG=" /etc/default/locale')
Esempio n. 11
0
    def test_get_locale(self):
        """
        Test for Get the current system locale
        """
        with patch.dict(localemod.__grains__, {"os_family": ["Arch"]}):
            with patch.object(localemod, "_localectl_get", return_value=True):
                self.assertTrue(localemod.get_locale())

        with patch.dict(localemod.__grains__, {"os_family": ["Gentoo"]}):
            with patch.dict(localemod.__salt__, {"cmd.run": MagicMock(return_value="A")}):
                self.assertEqual(localemod.get_locale(), "A")

        with patch.dict(localemod.__grains__, {"os_family": ["A"]}):
            with patch.dict(localemod.__salt__, {"cmd.run": MagicMock(return_value="A=B")}):
                self.assertEqual(localemod.get_locale(), "B")

        with patch.dict(localemod.__grains__, {"os_family": ["A"]}):
            with patch.dict(localemod.__salt__, {"cmd.run": MagicMock(return_value="A")}):
                self.assertEqual(localemod.get_locale(), "")
Esempio n. 12
0
    def test_get_locale(self):
        '''
        Test for Get the current system locale
        '''
        with patch.dict(localemod.__grains__, {'os_family': ['Arch']}):
            with patch.object(localemod, '_locale_get', return_value=True):
                self.assertTrue(localemod.get_locale())

        with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}):
            with patch.dict(localemod.__salt__, {'cmd.run':
                                                 MagicMock(return_value='A')}):
                self.assertEqual(localemod.get_locale(), 'A')

        with patch.dict(localemod.__grains__, {'os_family': ['RedHat']}):
            with patch.dict(localemod.__salt__,
                            {'cmd.run': MagicMock(return_value='A=B')}):
                self.assertEqual(localemod.get_locale(), 'B')

        with patch.dict(localemod.__grains__, {'os_family': ['Unknown']}):
            self.assertRaises(CommandExecutionError, localemod.get_locale)
Esempio n. 13
0
    def test_get_locale(self):
        '''
        Test for Get the current system locale
        '''
        with patch.dict(localemod.__grains__, {'os_family': ['Arch']}):
            with patch.object(localemod, '_locale_get', return_value=True):
                self.assertTrue(localemod.get_locale())

        with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}):
            with patch.dict(localemod.__salt__,
                            {'cmd.run': MagicMock(return_value='A')}):
                self.assertEqual(localemod.get_locale(), 'A')

        with patch.dict(localemod.__grains__, {'os_family': ['RedHat']}):
            with patch.dict(localemod.__salt__,
                            {'cmd.run': MagicMock(return_value='A=B')}):
                self.assertEqual(localemod.get_locale(), 'B')

        with patch.dict(localemod.__grains__, {'os_family': ['Unknown']}):
            self.assertRaises(CommandExecutionError, localemod.get_locale)
Esempio n. 14
0
    def test_get_locale(self):
        '''
        Test for Get the current system locale
        '''
        with patch.dict(localemod.__grains__, {'os_family': ['Arch']}):
            with patch.object(localemod, '_localectl_get', return_value=True):
                self.assertTrue(localemod.get_locale())

        with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}):
            with patch.dict(localemod.__salt__, {'cmd.run':
                                                 MagicMock(return_value='A')}):
                self.assertEqual(localemod.get_locale(), 'A')

        with patch.dict(localemod.__grains__, {'os_family': ['A']}):
            with patch.dict(localemod.__salt__,
                            {'cmd.run': MagicMock(return_value='A=B')}):
                self.assertEqual(localemod.get_locale(), 'B')

        with patch.dict(localemod.__grains__, {'os_family': ['A']}):
            with patch.dict(localemod.__salt__, {'cmd.run':
                                                 MagicMock(return_value='A')}):
                self.assertEqual(localemod.get_locale(), '')
Esempio n. 15
0
    def test_get_locale(self):
        '''
        Test for Get the current system locale
        '''
        with patch.dict(localemod.__grains__, {'os_family': ['Arch']}):
            with patch.object(localemod, '_localectl_get', return_value=True):
                self.assertTrue(localemod.get_locale())

        with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}):
            with patch.dict(localemod.__salt__, {'cmd.run':
                                                 MagicMock(return_value='A')}):
                self.assertEqual(localemod.get_locale(), 'A')

        with patch.dict(localemod.__grains__, {'os_family': ['A']}):
            with patch.dict(localemod.__salt__,
                            {'cmd.run': MagicMock(return_value='A=B')}):
                self.assertEqual(localemod.get_locale(), 'B')

        with patch.dict(localemod.__grains__, {'os_family': ['A']}):
            with patch.dict(localemod.__salt__, {'cmd.run':
                                                 MagicMock(return_value='A')}):
                self.assertEqual(localemod.get_locale(), '')
Esempio n. 16
0
    def test_get_locale(self):
        '''
        Test for Get the current system locale
        '''
        with patch.dict(localemod.__context__, {'salt.utils.systemd.booted': True}):
            localemod.HAS_DBUS = True
            with patch.object(localemod,
                              '_parse_dbus_locale',
                              return_value={'LANG': 'A'}):
                self.assertEqual('A', localemod.get_locale())
                localemod._parse_dbus_locale.assert_called_once_with()

            localemod.HAS_DBUS = False
            with patch.object(localemod,
                              '_parse_localectl',
                              return_value={'LANG': 'A'}):
                self.assertEqual('A', localemod.get_locale())
                localemod._parse_localectl.assert_called_once_with()

        with patch.dict(localemod.__context__, {'salt.utils.systemd.booted': False}):
            with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}):
                with patch.dict(localemod.__salt__, {'cmd.run': MagicMock(return_value='A')}):
                    with patch.object(localemod,
                                      '_parse_localectl',
                                      return_value={'LANG': 'A'}):
                        self.assertEqual(localemod.get_locale(), 'A')

            with patch.dict(localemod.__grains__, {'os_family': ['RedHat']}):
                with patch.dict(localemod.__salt__, {'cmd.run': MagicMock(return_value='A=B')}):
                    with patch.object(localemod,
                                      '_parse_localectl',
                                      return_value={'LANG': 'B'}):
                        self.assertEqual(localemod.get_locale(), 'B')

            with patch.dict(localemod.__grains__, {'os_family': ['Unknown']}):
                with patch.dict(localemod.__salt__, {'cmd.run': MagicMock(return_value='A=B')}):
                    self.assertRaises(CommandExecutionError, localemod.get_locale)
Esempio n. 17
0
 def test_get_locale_with_systemd_and_dbus(self):
     '''
     Test getting current system locale with systemd and dbus available.
     :return:
     '''
     assert localemod.get_locale() == 'en_US.utf8'
Esempio n. 18
0
 def test_get_locale_with_systemd_nodbus(self):
     '''
     Test getting current system locale with systemd but no dbus available.
     :return:
     '''
     assert localemod.get_locale() == 'de_DE.utf8'