def test_set_locale(self): ''' Test for Sets the current system locale ''' with patch.dict(localemod.__context__, {'salt.utils.systemd.booted': True}): with patch.object(localemod, '_localectl_set', return_value=True): self.assertTrue(localemod.set_locale('l')) with patch.dict(localemod.__context__, {'salt.utils.systemd.booted': False}): with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}): with patch.dict(localemod.__salt__, {'cmd.retcode': MagicMock(return_value='A')}): with patch.object(localemod, '_parse_localectl', return_value={'LANG': 'B'}): self.assertFalse(localemod.set_locale('l')) with patch.dict(localemod.__grains__, {'os_family': ['A']}): with patch.dict(localemod.__salt__, {'cmd.retcode': MagicMock(return_value=0)}): with patch('salt.utils.systemd.booted', return_value=False): self.assertRaises(CommandExecutionError, localemod.set_locale, 'A')
def test_set_locale_with_systemd_and_dbus(self): ''' Test setting current system locale with systemd and dbus available. :return: ''' loc = 'de_DE.utf8' localemod.set_locale(loc) assert localemod._localectl_set.call_args[0][0] == 'de_DE.utf8'
def test_set_locale_with_no_systemd_unknown(self): """ Test setting current system locale without systemd on unknown system. :return: """ with pytest.raises(CommandExecutionError) as exc_info: localemod.set_locale("de_DE.utf8") assert "Unsupported platform" in str(exc_info.value)
def test_set_locale_with_systemd_nodbus(self): """ Test setting current system locale with systemd but no dbus available. :return: """ loc = "de_DE.utf8" localemod.set_locale(loc) assert localemod._localectl_set.call_args[0][0] == "de_DE.utf8"
def test_set_locale_with_no_systemd_unknown(self): ''' Test setting current system locale without systemd on unknown system. :return: ''' with pytest.raises(CommandExecutionError) as err: localemod.set_locale('de_DE.utf8') assert 'Unsupported platform' in six.text_type(err)
def test_set_locale_with_no_systemd_gentoo(self): ''' Test setting current system locale with systemd and dbus available on Gentoo. :return: ''' loc = 'de_DE.utf8' localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__['cmd.retcode'].call_args[0][0] == 'eselect --brief locale set de_DE.utf8'
def test_set_locale_with_no_systemd_gentoo(self): """ Test setting current system locale with systemd and dbus available on Gentoo. :return: """ loc = "de_DE.utf8" localemod.set_locale(loc) assert not localemod._localectl_set.called assert (localemod.__salt__["cmd.retcode"].call_args[0][0] == "eselect --brief locale set de_DE.utf8")
def test_set_locale_with_no_systemd_debian_no_update_locale(self): ''' Test setting current system locale with systemd and dbus available on Debian but update-locale is not installed. :return: ''' loc = 'de_DE.utf8' with pytest.raises(CommandExecutionError) as err: localemod.set_locale(loc) assert not localemod._localectl_set.called assert 'Cannot set locale: "update-locale" was not found.' in six.text_type(err)
def test_set_locale_with_no_systemd_debian_no_update_locale(self): """ Test setting current system locale with systemd and dbus available on Debian but update-locale is not installed. :return: """ loc = "de_DE.utf8" with pytest.raises(CommandExecutionError) as exc_info: localemod.set_locale(loc) assert not localemod._localectl_set.called assert 'Cannot set locale: "update-locale" was not found.' in str( exc_info.value)
def test_set_locale_with_no_systemd_debian(self): ''' Test setting current system locale with systemd and dbus available on Debian. :return: ''' loc = 'de_DE.utf8' localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__['file.replace'].called assert localemod.__salt__['file.replace'].call_args[0][0] == '/etc/default/locale' assert localemod.__salt__['file.replace'].call_args[0][1] == '^LANG=.*' assert localemod.__salt__['file.replace'].call_args[0][2] == 'LANG="{}"'.format(loc)
def test_set_locale_with_systemd_and_dbus_sle12(self): ''' Test setting current system locale with systemd and dbus available on SLE12. :return: ''' loc = 'de_DE.utf8' localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__['file.replace'].called assert localemod.__salt__['file.replace'].call_args[0][0] == '/etc/sysconfig/language' assert localemod.__salt__['file.replace'].call_args[0][1] == '^RC_LANG=.*' assert localemod.__salt__['file.replace'].call_args[0][2] == 'RC_LANG="{}"'.format(loc)
def test_set_locale_with_no_systemd_slowlaris_with_list_avail(self): ''' Test setting current system locale with systemd and dbus available on Slowlaris. The list_avail returns the proper locale. :return: ''' loc = 'de_DE.utf8' localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__['file.replace'].called assert localemod.__salt__['file.replace'].call_args[0][0] == '/etc/default/init' assert localemod.__salt__['file.replace'].call_args[0][1] == '^LANG=.*' assert localemod.__salt__['file.replace'].call_args[0][2] == 'LANG="{}"'.format(loc)
def test_set_locale(self): """ Test for Sets the current system locale """ with patch.dict(localemod.__grains__, {"os_family": ["Arch"]}): with patch.object(localemod, "_localectl_set", return_value=True): self.assertTrue(localemod.set_locale("l")) with patch.dict(localemod.__grains__, {"os_family": ["Gentoo"]}): with patch.dict(localemod.__salt__, {"cmd.retcode": MagicMock(return_value="A")}): self.assertFalse(localemod.set_locale("l")) with patch.dict(localemod.__grains__, {"os_family": ["A"]}): self.assertTrue(localemod.set_locale("locale"))
def test_set_locale_with_no_systemd_debian(self): """ Test setting current system locale with systemd and dbus available on Debian. :return: """ loc = "de_DE.utf8" localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__["file.replace"].called assert (localemod.__salt__["file.replace"].call_args[0][0] == "/etc/default/locale") assert localemod.__salt__["file.replace"].call_args[0][1] == "^LANG=.*" assert localemod.__salt__["file.replace"].call_args[0][ 2] == 'LANG="{}"'.format(loc)
def test_set_locale_with_systemd_and_dbus_sle12(self): """ Test setting current system locale with systemd and dbus available on SLE12. :return: """ loc = "de_DE.utf8" localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__["file.replace"].called assert (localemod.__salt__["file.replace"].call_args[0][0] == "/etc/sysconfig/language") assert localemod.__salt__["file.replace"].call_args[0][ 1] == "^RC_LANG=.*" assert localemod.__salt__["file.replace"].call_args[0][ 2] == 'RC_LANG="{}"'.format(loc)
def test_set_locale_with_no_systemd_solaris_with_list_avail(self): """ Test setting current system locale with systemd and dbus available on Solaris. The list_avail returns the proper locale. :return: """ loc = "de_DE.utf8" localemod.set_locale(loc) assert not localemod._localectl_set.called assert localemod.__salt__["file.replace"].called assert localemod.__salt__["file.replace"].call_args[0][ 0] == "/etc/default/init" assert localemod.__salt__["file.replace"].call_args[0][1] == "^LANG=.*" assert localemod.__salt__["file.replace"].call_args[0][ 2] == 'LANG="{}"'.format(loc)
def test_set_locale(self): ''' Test for Sets the current system locale ''' with patch.dict(localemod.__grains__, {'os_family': ['Arch']}): with patch.object(localemod, '_localectl_set', return_value=True): self.assertTrue(localemod.set_locale('l')) with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}): with patch.dict(localemod.__salt__, {'cmd.retcode': MagicMock(return_value='A')}): self.assertFalse(localemod.set_locale('l')) with patch.dict(localemod.__grains__, {'os_family': ['A']}): self.assertTrue(localemod.set_locale('locale'))
def test_set_locale(self): ''' Test for Sets the current system locale ''' with patch.dict(localemod.__grains__, {'os_family': ['Arch']}): with patch.object(localemod, '_localectl_set', return_value=True): self.assertTrue(localemod.set_locale('l')) with patch.dict(localemod.__grains__, {'os_family': ['Gentoo']}): with patch.dict(localemod.__salt__, {'cmd.retcode': MagicMock(return_value='A')}): self.assertFalse(localemod.set_locale('l')) with patch.dict(localemod.__grains__, {'os_family': ['A']}): self.assertRaises(CommandExecutionError, localemod.set_locale, 'A')
def test_set_locale_debian_no_localectl(self): with patch.dict(localemod.__grains__, {'os_family': ['Debian']}): with patch.dict( localemod.__salt__, { 'cmd.run': MagicMock(return_value=''), 'file.replace': MagicMock(return_value='') }): self.assertTrue(localemod.set_locale('C'))
def test_set_locale_with_no_systemd_solaris_without_list_avail(self): ''' Test setting current system locale with systemd and dbus is not available on Solaris. The list_avail does not return the proper locale. :return: ''' loc = 'de_DE.utf8' assert not localemod.set_locale(loc) assert not localemod._localectl_set.called assert not localemod.__salt__['file.replace'].called
def test_set_locale_debian_localectl(self): with patch.dict(localemod.__grains__, {'os_family': ['Debian']}): with patch.object(localemod, '_localectl_set', return_value=True): self.assertTrue(localemod.set_locale('C'))
def test_set_locale_debian_no_localectl(self): with patch.dict(localemod.__grains__, {'os_family': ['Debian']}): with patch.dict(localemod.__salt__, {'cmd.run': MagicMock(return_value=''), 'file.replace': MagicMock(return_value='')}): self.assertTrue(localemod.set_locale('C'))