<s> import os <EOL> import subprocess <EOL> import pytest <EOL> from mock import patch , MagicMock , Mock <EOL> from ceph_deploy . cli import _main as main <EOL> from ceph_deploy . hosts import remotes <EOL> from ceph_deploy . tests . directory import directory <EOL> def test_bad_no_conf ( tmpdir , cli ) : <EOL> with pytest . raises ( cli . Failed ) as err : <EOL> with cli ( <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stderr = subprocess . PIPE , <EOL> ) as p : <EOL> result = p . stderr . read ( ) <EOL> assert '<STR_LIT>' in result <EOL> assert err . value . status == <NUM_LIT:1> <EOL> def test_bad_no_key ( tmpdir , cli ) : <EOL> with tmpdir . join ( '<STR_LIT>' ) . open ( '<STR_LIT:w>' ) : <EOL> pass <EOL> with pytest . raises ( cli . Failed ) as err : <EOL> with cli ( <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stderr = subprocess . PIPE , <EOL> ) as p : <EOL> result = p . stderr . read ( ) <EOL> assert '<STR_LIT>' in result <EOL> assert err . value . status == <NUM_LIT:1> <EOL> def test_write_keyring ( tmpdir ) : <EOL> with tmpdir . join ( '<STR_LIT>' ) . open ( '<STR_LIT:w>' ) : <EOL> pass <EOL> with tmpdir . join ( '<STR_LIT>' ) . open ( '<STR_LIT:w>' ) : <EOL> pass <EOL> etc_ceph = os . path . join ( str ( tmpdir ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> os . makedirs ( etc_ceph ) <EOL> distro = MagicMock ( ) <EOL> distro . conn = MagicMock ( ) <EOL> remotes . write_file . func_defaults = ( <NUM_LIT:0> <NUM_LIT> , str ( tmpdir ) , - <NUM_LIT:1> , - <NUM_LIT:1> ) <EOL> distro . conn . remote_module = remotes <EOL> distro . conn . remote_module . write_conf = Mock ( ) <EOL> with patch ( '<STR_LIT>' ) : <EOL> with patch ( '<STR_LIT>' , MagicMock ( return_value = distro ) ) : <EOL> with directory ( str ( tmpdir ) ) : <EOL> main ( args = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> keyring_file = os . path . join ( etc_ceph , '<STR_LIT>' ) <EOL> assert os . path . exists ( keyring_file ) <EOL> file_mode = oct ( os . stat ( keyring_file ) . st_mode & <NUM_LIT:0> <NUM_LIT> ) <EOL> assert file_mode == oct ( <NUM_LIT:0> <NUM_LIT> ) </s>
