<s> import os <EOL> from nose . tools import istest <EOL> from mock import call <EOL> from jinja2 import FileSystemLoader <EOL> from provy . more . debian import SSHRole <EOL> from tests . unit . tools . helpers import ProvyTestCase , PROJECT_ROOT <EOL> class SSHRoleTest ( ProvyTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( SSHRoleTest , self ) . setUp ( ) <EOL> self . role = SSHRole ( None , { } ) <EOL> template_dir = os . path . join ( PROJECT_ROOT , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . role . context [ '<STR_LIT>' ] = FileSystemLoader ( template_dir ) <EOL> self . test_pub_key = open ( os . path . join ( template_dir , '<STR_LIT>' ) ) . read ( ) <EOL> self . test_private_key = self . role . render ( '<STR_LIT>' ) <EOL> @ istest <EOL> def ensures_ssh_key ( self ) : <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' ) as ( mock_write , ensure_dir ) : <EOL> self . role . ensure_ssh_key ( '<STR_LIT:user>' , '<STR_LIT>' ) <EOL> ensure_dir . assert_called_with ( <EOL> '<STR_LIT>' , owner = '<STR_LIT:user>' , sudo = True , <EOL> ) <EOL> mock_write . assert_called_with ( <EOL> '<STR_LIT:user>' , self . test_private_key , self . test_pub_key , <EOL> ) <EOL> @ istest <EOL> def writes_keys ( self ) : <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) as ( execute_python , write_to_temp_file , update_file ) : <EOL> self . role . _SSHRole__write_keys ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <EOL> execute_python . call_args , <EOL> call ( '<STR_LIT>' , stdout = False ) <EOL> ) <EOL> write_to_temp_file . assert_has_calls ( [ <EOL> call ( '<STR_LIT>' + str ( execute_python . return_value ) ) , <EOL> call ( '<STR_LIT>' ) , <EOL> ] ) <EOL> update_file . assert_has_calls ( [ <EOL> call ( <EOL> write_to_temp_file . return_value , <EOL> '<STR_LIT>' , sudo = True , owner = '<STR_LIT:user>' , <EOL> ) , <EOL> call ( <EOL> write_to_temp_file . return_value , <EOL> '<STR_LIT>' , sudo = True , owner = '<STR_LIT:user>' , <EOL> ) , <EOL> ] ) <EOL> @ istest <EOL> def doesnt_log_if_updating_keys_files_fails ( self ) : <EOL> with self . mock_role_methods ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) as ( execute_python , write_to_temp_file , update_file , log ) : <EOL> update_file . return_value = False <EOL> self . role . _SSHRole__write_keys ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertFalse ( log . called ) </s>
