def test_get_zone(self):
        zone = 'MST'

        with patch.object(salt.utils, 'which', return_value=True):
            mock_cmd = MagicMock(return_value={'stderr': 'error', 'retcode': 1})
            with patch.dict(timezone.__salt__, {'cmd.run_all': mock_cmd}):
                self.assertRaises(CommandExecutionError, timezone.get_zone)

            mock_cmd = MagicMock(return_value={'stdout': 'Timezone: {0}'.format(zone),
                                               'retcode': 0})
            with patch.dict(timezone.__salt__, {'cmd.run_all': mock_cmd}):
                self.assertEqual(timezone.get_zone(), zone)

            mock_cmd = MagicMock(return_value={'stdout': 'ZoneCTL: {0}'.format(zone),
                                               'retcode': 0})
            with patch.dict(timezone.__salt__, {'cmd.run_all': mock_cmd}):
                self.assertRaises(CommandExecutionError, timezone.get_zone)

        with patch.object(salt.utils, 'which', return_value=False):
            file_data = '\n'.join(['#', 'A'])
            with patch('salt.utils.fopen', mock_open(read_data=file_data),
                       create=True) as mfile:
                mfile.return_value.__iter__.return_value = file_data.splitlines()
                with patch.dict(timezone.__grains__, {'os_family': 'Debian',
                                                      'os': 'Debian'}):
                    self.assertEqual(timezone.get_zone(), '#\nA')

            with patch('salt.utils.fopen', mock_open(read_data=file_data),
                       create=True) as mfile:
                mfile.return_value.__iter__.return_value = file_data.splitlines()
                with patch.dict(timezone.__grains__, {'os_family': 'Gentoo',
                                                      'os': 'Gentoo'}):
                    self.assertEqual(timezone.get_zone(), '#\nA')

            with patch.dict(timezone.__grains__, {'os_family': 'FreeBSD',
                                                  'os': 'FreeBSD'}):
                zone = 'America/Denver'
                linkpath = '/usr/share/zoneinfo/' + zone
                with patch.object(os, 'readlink', return_value=linkpath):
                    self.assertEqual(timezone.get_zone(), zone)

            with patch.dict(timezone.__grains__, {'os_family': 'Solaris',
                                                  'os': 'Solaris'}):
                fl_data = 'TZ=Foo\n'
                with patch('salt.utils.fopen',
                           mock_open(read_data=fl_data)) as mfile:
                    mfile.return_value.__iter__.return_value = [fl_data]
                    self.assertEqual(timezone.get_zone(), 'Foo')
Endpoint: /tag/<id>/update.json
dataset/ETHPy150Open saltstack/salt/tests/unit/modules/timezone_test.py/TimezoneTestCase.test_get_zone--crossover with--dataset/ETHPy150Open photo/openphoto-python/trovebox/objects/tag.py/Tag.update