<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import logging <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . helpers import ensure_in_syspath <EOL> from salttesting . mock import ( <EOL> MagicMock , <EOL> patch , <EOL> mock_open , <EOL> call , <EOL> NO_MOCK , <EOL> NO_MOCK_REASON <EOL> ) <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . modules import dnsutil <EOL> log = logging . getLogger ( __name__ ) <EOL> mock_hosts_file = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> mock_hosts_file_rtn = { '<STR_LIT>' : [ '<STR_LIT:localhost>' ] , '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:127.0.0.1>' : [ '<STR_LIT:localhost>' ] , '<STR_LIT>' : [ '<STR_LIT:localhost>' ] } <EOL> mock_soa_zone = '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' '<STR_LIT>' <EOL> if NO_MOCK is False : <EOL> mock_calls_list = [ call . read ( ) , call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT:\n>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT:\n>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT:\n>' ) , <EOL> call . write ( '<STR_LIT>' ) , <EOL> call . write ( '<STR_LIT:\n>' ) , <EOL> call . close ( ) ] <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class DNSUtilTestCase ( TestCase ) : <EOL> def test_parse_hosts ( self ) : <EOL> with patch ( '<STR_LIT>' , mock_open ( read_data = mock_hosts_file ) ) : <EOL> self . assertEqual ( dnsutil . parse_hosts ( ) , { '<STR_LIT>' : [ '<STR_LIT:localhost>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:127.0.0.1>' : [ '<STR_LIT:localhost>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:localhost>' ] } ) <EOL> @ patch ( '<STR_LIT>' , MagicMock ( return_value = mock_hosts_file_rtn ) ) <EOL> def test_hosts_append ( self ) : <EOL> with patch ( '<STR_LIT>' , mock_open ( read_data = mock_hosts_file ) ) as m_open : <EOL> dnsutil . hosts_append ( '<STR_LIT>' , '<STR_LIT:127.0.0.1>' , '<STR_LIT>' ) <EOL> helper_open = m_open ( ) <EOL> helper_open . write . assert_called_once_with ( '<STR_LIT>' ) <EOL> def test_hosts_remove ( self ) : <EOL> to_remove = '<STR_LIT>' <EOL> new_mock_file = mock_hosts_file + '<STR_LIT>' + to_remove + '<STR_LIT:\n>' <EOL> with patch ( '<STR_LIT>' , mock_open ( read_data = new_mock_file ) ) as m_open : <EOL> dnsutil . hosts_remove ( '<STR_LIT>' , to_remove ) <EOL> helper_open = m_open ( ) <EOL> calls_list = helper_open . method_calls <EOL> self . assertEqual ( calls_list , mock_calls_list ) <EOL> @ skipIf ( True , '<STR_LIT>' ) <EOL> def test_parse_zone ( self ) : <EOL> with patch ( '<STR_LIT>' , mock_open ( read_data = mock_soa_zone ) ) : <EOL> log . debug ( mock_soa_zone ) <EOL> log . debug ( dnsutil . parse_zone ( '<STR_LIT>' ) ) <EOL> def test_to_seconds_hour ( self ) : <EOL> self . assertEqual ( dnsutil . _to_seconds ( '<STR_LIT>' ) , <NUM_LIT> , <EOL> msg = '<STR_LIT>' ) <EOL> def test_to_seconds_day ( self ) : <EOL> self . assertEqual ( dnsutil . _to_seconds ( '<STR_LIT>' ) , <NUM_LIT> , <EOL> msg = '<STR_LIT>' ) <EOL> def test_to_seconds_week ( self ) : <EOL> self . assertEqual ( dnsutil . _to_seconds ( '<STR_LIT>' ) , <NUM_LIT> , <EOL> msg = '<STR_LIT>' ) <EOL> def test_to_seconds_empty ( self ) : <EOL> self . assertEqual ( dnsutil . _to_seconds ( '<STR_LIT>' ) , <NUM_LIT> , <EOL> msg = '<STR_LIT>' ) <EOL> def test_to_seconds_large ( self ) : <EOL> self . assertEqual ( dnsutil . _to_seconds ( '<STR_LIT>' ) , <NUM_LIT> , <EOL> msg = '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( DNSUtilTestCase , needs_daemon = False ) </s>
