<s> import os <EOL> import unittest <EOL> try : <EOL> import unittest . mock as mock <EOL> except ImportError : <EOL> import mock <EOL> from oslo_config import cfg <EOL> from cloudbaseinit . plugins . common . userdataplugins import heat <EOL> CONF = cfg . CONF <EOL> class HeatUserDataHandlerTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . _heat = heat . HeatPlugin ( ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_check_heat_config_dir ( self , mock_dirname , mock_makedirs , <EOL> mock_exists ) : <EOL> mock_exists . return_value = False <EOL> fake_path = mock . sentinel . fake_path <EOL> fake_dir = mock . sentinel . fake_dir <EOL> mock_dirname . return_value = fake_dir <EOL> self . _heat . _check_dir ( file_name = fake_path ) <EOL> mock_dirname . assert_called_once_with ( fake_path ) <EOL> mock_exists . assert_called_once_with ( fake_dir ) <EOL> mock_makedirs . assert_called_once_with ( fake_dir ) <EOL> @ mock . patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def _test_process ( self , mock_write_file , mock_check_dir , <EOL> mock_execute_user_data_script , filename ) : <EOL> mock_part = mock . MagicMock ( ) <EOL> mock_part . get_filename . return_value = filename <EOL> response = self . _heat . process ( mock_part ) <EOL> path = os . path . join ( CONF . heat_config_dir , filename ) <EOL> mock_check_dir . assert_called_once_with ( path ) <EOL> mock_part . get_filename . assert_called_with ( ) <EOL> mock_write_file . assert_called_once_with ( <EOL> path , mock_part . get_payload . return_value ) <EOL> if filename == self . _heat . _heat_user_data_filename : <EOL> mock_execute_user_data_script . assert_called_with ( <EOL> mock_part . get_payload ( ) ) <EOL> self . assertEqual ( mock_execute_user_data_script . return_value , <EOL> response ) <EOL> else : <EOL> self . assertTrue ( response is None ) <EOL> def test_process ( self ) : <EOL> self . _test_process ( filename = self . _heat . _heat_user_data_filename ) <EOL> def test_process_content_other_data ( self ) : <EOL> self . _test_process ( filename = '<STR_LIT>' ) </s>
