<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import argparse <EOL> import functools <EOL> import itertools <EOL> import os <EOL> import shutil <EOL> import traceback <EOL> import tempfile <EOL> import unittest <EOL> import mock <EOL> import six <EOL> from six . moves import reload_module <EOL> from acme import jose <EOL> from certbot import account <EOL> from certbot import cli <EOL> from certbot import configuration <EOL> from certbot import constants <EOL> from certbot import crypto_util <EOL> from certbot import errors <EOL> from certbot import le_util <EOL> from certbot import main <EOL> from certbot import renewal <EOL> from certbot import storage <EOL> from certbot . plugins import disco <EOL> from certbot . plugins import manual <EOL> from certbot . tests import storage_test <EOL> from certbot . tests import test_util <EOL> CERT = test_util . vector_path ( '<STR_LIT>' ) <EOL> CSR = test_util . vector_path ( '<STR_LIT>' ) <EOL> KEY = test_util . vector_path ( '<STR_LIT>' ) <EOL> class CLITest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . tmp_dir = tempfile . mkdtemp ( ) <EOL> self . config_dir = os . path . join ( self . tmp_dir , '<STR_LIT>' ) <EOL> self . work_dir = os . path . join ( self . tmp_dir , '<STR_LIT>' ) <EOL> self . logs_dir = os . path . join ( self . tmp_dir , '<STR_LIT>' ) <EOL> self . standard_args = [ '<STR_LIT>' , self . config_dir , <EOL> '<STR_LIT>' , self . work_dir , <EOL> '<STR_LIT>' , self . logs_dir , '<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tmp_dir ) <EOL> cli . _parser = cli . set_by_cli . detector = None <EOL> def _call ( self , args , stdout = None ) : <EOL> "<STR_LIT>" <EOL> with mock . patch ( '<STR_LIT>' ) as client : <EOL> ret , stdout , stderr = self . _call_no_clientmock ( args , stdout ) <EOL> return ret , stdout , stderr , client <EOL> def _call_no_clientmock ( self , args , stdout = None ) : <EOL> "<STR_LIT>" <EOL> args = self . standard_args + args <EOL> toy_stdout = stdout if stdout else six . StringIO ( ) <EOL> with mock . patch ( '<STR_LIT>' , new = toy_stdout ) : <EOL> with mock . patch ( '<STR_LIT>' ) as stderr : <EOL> ret = main . main ( args [ : ] ) <EOL> return ret , toy_stdout , stderr <EOL> def test_no_flags ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_run : <EOL> self . _call ( [ ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , mock_run . call_count ) <EOL> def _help_output ( self , args ) : <EOL> "<STR_LIT>" <EOL> output = six . StringIO ( ) <EOL> self . assertRaises ( SystemExit , self . _call , args , output ) <EOL> out = output . getvalue ( ) <EOL> return out <EOL> def test_help ( self ) : <EOL> self . assertRaises ( SystemExit , self . _call , [ '<STR_LIT>' ] ) <EOL> self . assertRaises ( SystemExit , self . _call , [ '<STR_LIT>' , '<STR_LIT:all>' ] ) <EOL> plugins = disco . PluginsRegistry . find_all ( ) <EOL> out = self . _help_output ( [ '<STR_LIT>' , '<STR_LIT:all>' ] ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if "<STR_LIT>" in plugins : <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> self . assertTrue ( "<STR_LIT>" not in out ) <EOL> self . assertTrue ( "<STR_LIT>" not in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( "<STR_LIT>" not in out ) <EOL> if "<STR_LIT>" in plugins : <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> else : <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( "<STR_LIT>" not in out ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( "<STR_LIT>" not in out ) <EOL> self . assertTrue ( "<STR_LIT>" not in out ) <EOL> out = self . _help_output ( [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( cli . usage_strings ( plugins ) [ <NUM_LIT:0> ] in out ) <EOL> def _cli_missing_flag ( self , args , message ) : <EOL> "<STR_LIT>" <EOL> exc = None <EOL> try : <EOL> with mock . patch ( '<STR_LIT>' ) : <EOL> main . main ( self . standard_args + args [ : ] ) <EOL> except errors . MissingCommandlineFlag as exc : <EOL> self . assertTrue ( message in str ( exc ) ) <EOL> self . assertTrue ( exc is not None ) <EOL> def test_noninteractive ( self ) : <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . _cli_missing_flag ( args , "<STR_LIT>" ) <EOL> args . extend ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . _cli_missing_flag ( args , "<STR_LIT>" ) <EOL> with mock . patch ( '<STR_LIT>' ) : <EOL> with mock . patch ( '<STR_LIT>' ) : <EOL> args . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . _cli_missing_flag ( args , "<STR_LIT>" ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_user_agent ( self , afd , _obt , det , _client ) : <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' ] + self . standard_args <EOL> det . return_value = mock . MagicMock ( ) , None <EOL> afd . return_value = mock . MagicMock ( ) , "<STR_LIT>" <EOL> with mock . patch ( '<STR_LIT>' ) as acme_net : <EOL> self . _call_no_clientmock ( args ) <EOL> os_ver = "<STR_LIT:U+0020>" . join ( le_util . get_os_info ( ) ) <EOL> ua = acme_net . call_args [ <NUM_LIT:1> ] [ "<STR_LIT>" ] <EOL> self . assertTrue ( os_ver in ua ) <EOL> import platform <EOL> plat = platform . platform ( ) <EOL> if "<STR_LIT>" in plat . lower ( ) : <EOL> self . assertTrue ( platform . linux_distribution ( ) [ <NUM_LIT:0> ] in ua ) <EOL> with mock . patch ( '<STR_LIT>' ) as acme_net : <EOL> ua = "<STR_LIT>" <EOL> args += [ "<STR_LIT>" , ua ] <EOL> self . _call_no_clientmock ( args ) <EOL> acme_net . assert_called_once_with ( mock . ANY , verify_ssl = True , user_agent = ua ) <EOL> def test_install_abspath ( self ) : <EOL> cert = '<STR_LIT>' <EOL> key = '<STR_LIT:key>' <EOL> chain = '<STR_LIT>' <EOL> fullchain = '<STR_LIT>' <EOL> with mock . patch ( '<STR_LIT>' ) as mock_install : <EOL> self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , cert , '<STR_LIT>' , '<STR_LIT:key>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> args = mock_install . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( args . cert_path , os . path . abspath ( cert ) ) <EOL> self . assertEqual ( args . key_path , os . path . abspath ( key ) ) <EOL> self . assertEqual ( args . chain_path , os . path . abspath ( chain ) ) <EOL> self . assertEqual ( args . fullchain_path , os . path . abspath ( fullchain ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_installer_selection ( self , mock_pick_installer , _rec ) : <EOL> self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:key>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( mock_pick_installer . call_count , <NUM_LIT:1> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_configurator_selection ( self , mock_exe_exists ) : <EOL> mock_exe_exists . return_value = True <EOL> real_plugins = disco . PluginsRegistry . find_all ( ) <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> if "<STR_LIT>" in real_plugins : <EOL> ret , _ , _ , _ = self . _call ( args ) <EOL> self . assertTrue ( "<STR_LIT>" in ret ) <EOL> self . assertTrue ( "<STR_LIT>" in ret ) <EOL> self . _cli_missing_flag ( [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> with mock . patch ( "<STR_LIT>" ) as mock_init : <EOL> with mock . patch ( "<STR_LIT>" ) as mock_afd : <EOL> mock_afd . return_value = ( mock . MagicMock ( ) , mock . MagicMock ( ) ) <EOL> self . _call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> unused_config , auth , unused_installer = mock_init . call_args [ <NUM_LIT:0> ] <EOL> self . assertTrue ( isinstance ( auth , manual . Authenticator ) ) <EOL> with mock . patch ( '<STR_LIT>' ) as mock_certonly : <EOL> self . _call ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , mock_certonly . call_count ) <EOL> def test_rollback ( self ) : <EOL> _ , _ , _ , client = self . _call ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , client . rollback . call_count ) <EOL> _ , _ , _ , client = self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> client . rollback . assert_called_once_with ( <EOL> mock . ANY , <NUM_LIT> , mock . ANY , mock . ANY ) <EOL> def test_config_changes ( self ) : <EOL> _ , _ , _ , client = self . _call ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , client . view_config_changes . call_count ) <EOL> def test_plugins ( self ) : <EOL> flags = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for args in itertools . chain ( <EOL> * ( itertools . combinations ( flags , r ) <EOL> for r in xrange ( len ( flags ) ) ) ) : <EOL> self . _call ( [ '<STR_LIT>' ] + list ( args ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_plugins_no_args ( self , _det , mock_disco ) : <EOL> ifaces = [ ] <EOL> plugins = mock_disco . PluginsRegistry . find_all ( ) <EOL> _ , stdout , _ , _ = self . _call ( [ '<STR_LIT>' ] ) <EOL> plugins . visible . assert_called_once_with ( ) <EOL> plugins . visible ( ) . ifaces . assert_called_once_with ( ifaces ) <EOL> filtered = plugins . visible ( ) . ifaces ( ) <EOL> self . assertEqual ( stdout . getvalue ( ) . strip ( ) , str ( filtered ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_plugins_init ( self , _det , mock_disco ) : <EOL> ifaces = [ ] <EOL> plugins = mock_disco . PluginsRegistry . find_all ( ) <EOL> _ , stdout , _ , _ = self . _call ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> plugins . visible . assert_called_once_with ( ) <EOL> plugins . visible ( ) . ifaces . assert_called_once_with ( ifaces ) <EOL> filtered = plugins . visible ( ) . ifaces ( ) <EOL> self . assertEqual ( filtered . init . call_count , <NUM_LIT:1> ) <EOL> filtered . verify . assert_called_once_with ( ifaces ) <EOL> verified = filtered . verify ( ) <EOL> self . assertEqual ( stdout . getvalue ( ) . strip ( ) , str ( verified ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_plugins_prepare ( self , _det , mock_disco ) : <EOL> ifaces = [ ] <EOL> plugins = mock_disco . PluginsRegistry . find_all ( ) <EOL> _ , stdout , _ , _ = self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> plugins . visible . assert_called_once_with ( ) <EOL> plugins . visible ( ) . ifaces . assert_called_once_with ( ifaces ) <EOL> filtered = plugins . visible ( ) . ifaces ( ) <EOL> self . assertEqual ( filtered . init . call_count , <NUM_LIT:1> ) <EOL> filtered . verify . assert_called_once_with ( ifaces ) <EOL> verified = filtered . verify ( ) <EOL> verified . prepare . assert_called_once_with ( ) <EOL> verified . available . assert_called_once_with ( ) <EOL> available = verified . available ( ) <EOL> self . assertEqual ( stdout . getvalue ( ) . strip ( ) , str ( available ) ) <EOL> def test_certonly_abspath ( self ) : <EOL> cert = '<STR_LIT>' <EOL> key = '<STR_LIT:key>' <EOL> chain = '<STR_LIT>' <EOL> fullchain = '<STR_LIT>' <EOL> with mock . patch ( '<STR_LIT>' ) as mock_obtaincert : <EOL> self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , cert , '<STR_LIT>' , '<STR_LIT:key>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> config , unused_plugins = mock_obtaincert . call_args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( config . cert_path , os . path . abspath ( cert ) ) <EOL> self . assertEqual ( config . key_path , os . path . abspath ( key ) ) <EOL> self . assertEqual ( config . chain_path , os . path . abspath ( chain ) ) <EOL> self . assertEqual ( config . fullchain_path , os . path . abspath ( fullchain ) ) <EOL> def test_certonly_bad_args ( self ) : <EOL> try : <EOL> self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> assert False , "<STR_LIT>" <EOL> except errors . PluginSelectionError as e : <EOL> self . assertTrue ( '<STR_LIT>' in e . message ) <EOL> def test_check_config_sanity_domain ( self ) : <EOL> self . assertRaises ( errors . ConfigurationError , <EOL> self . _call , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertRaises ( errors . ConfigurationError , <EOL> self . _call , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertRaises ( errors . ConfigurationError , <EOL> self . _call , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertRaises ( errors . ConfigurationError , <EOL> self . _call , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertRaises ( errors . ConfigurationError , <EOL> self . _call , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_csr_with_besteffort ( self ) : <EOL> args = [ "<STR_LIT>" , CSR , "<STR_LIT>" ] <EOL> self . assertRaises ( errors . Error , self . _call , args ) <EOL> def test_run_with_csr ( self ) : <EOL> try : <EOL> self . _call ( [ '<STR_LIT>' , CSR ] ) <EOL> except errors . Error as e : <EOL> assert "<STR_LIT>" in repr ( e ) <EOL> return <EOL> assert False , "<STR_LIT>" <EOL> def _get_argument_parser ( self ) : <EOL> plugins = disco . PluginsRegistry . find_all ( ) <EOL> return functools . partial ( cli . prepare_and_parse_args , plugins ) <EOL> def test_parse_domains ( self ) : <EOL> parse = self . _get_argument_parser ( ) <EOL> short_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> namespace = parse ( short_args ) <EOL> self . assertEqual ( namespace . domains , [ '<STR_LIT>' ] ) <EOL> short_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> namespace = parse ( short_args ) <EOL> self . assertEqual ( namespace . domains , [ '<STR_LIT>' ] ) <EOL> short_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> namespace = parse ( short_args ) <EOL> self . assertEqual ( namespace . domains , [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> long_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> namespace = parse ( long_args ) <EOL> self . assertEqual ( namespace . domains , [ '<STR_LIT>' ] ) <EOL> long_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> namespace = parse ( long_args ) <EOL> self . assertEqual ( namespace . domains , [ '<STR_LIT>' ] ) <EOL> long_args = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> namespace = parse ( long_args ) <EOL> self . assertEqual ( namespace . domains , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_server_flag ( self ) : <EOL> parse = self . _get_argument_parser ( ) <EOL> namespace = parse ( '<STR_LIT>' . split ( ) ) <EOL> self . assertEqual ( namespace . server , '<STR_LIT>' ) <EOL> def _check_server_conflict_message ( self , parser_args , conflicting_args ) : <EOL> parse = self . _get_argument_parser ( ) <EOL> try : <EOL> parse ( parser_args ) <EOL> self . fail ( <EOL> "<STR_LIT>" <EOL> '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . join ( conflicting_args ) ) ) <EOL> except errors . Error as error : <EOL> self . assertTrue ( '<STR_LIT>' in error . message ) <EOL> for arg in conflicting_args : <EOL> self . assertTrue ( arg in error . message ) <EOL> def test_staging_flag ( self ) : <EOL> parse = self . _get_argument_parser ( ) <EOL> short_args = [ '<STR_LIT>' ] <EOL> namespace = parse ( short_args ) <EOL> self . assertTrue ( namespace . staging ) <EOL> self . assertEqual ( namespace . server , constants . STAGING_URI ) <EOL> short_args += '<STR_LIT>' . split ( ) <EOL> self . _check_server_conflict_message ( short_args , '<STR_LIT>' ) <EOL> def _assert_dry_run_flag_worked ( self , namespace , existing_account ) : <EOL> self . assertTrue ( namespace . dry_run ) <EOL> self . assertTrue ( namespace . break_my_certs ) <EOL> self . assertTrue ( namespace . staging ) <EOL> self . assertEqual ( namespace . server , constants . STAGING_URI ) <EOL> if existing_account : <EOL> self . assertTrue ( namespace . tos ) <EOL> self . assertTrue ( namespace . register_unsafely_without_email ) <EOL> else : <EOL> self . assertFalse ( namespace . tos ) <EOL> self . assertFalse ( namespace . register_unsafely_without_email ) <EOL> def test_dry_run_flag ( self ) : <EOL> parse = self . _get_argument_parser ( ) <EOL> config_dir = tempfile . mkdtemp ( ) <EOL> short_args = '<STR_LIT>' . format ( config_dir ) . split ( ) <EOL> self . assertRaises ( errors . Error , parse , short_args ) <EOL> self . _assert_dry_run_flag_worked ( <EOL> parse ( short_args + [ '<STR_LIT>' ] ) , False ) <EOL> self . _assert_dry_run_flag_worked ( <EOL> parse ( short_args + [ '<STR_LIT>' ] ) , False ) <EOL> self . _assert_dry_run_flag_worked ( <EOL> parse ( short_args + [ '<STR_LIT>' ] ) , False ) <EOL> account_dir = os . path . join ( config_dir , constants . ACCOUNTS_DIR ) <EOL> os . mkdir ( account_dir ) <EOL> os . mkdir ( os . path . join ( account_dir , '<STR_LIT>' ) ) <EOL> self . _assert_dry_run_flag_worked ( parse ( short_args + [ '<STR_LIT>' ] ) , True ) <EOL> self . _assert_dry_run_flag_worked ( parse ( short_args + [ '<STR_LIT>' ] ) , True ) <EOL> short_args += [ '<STR_LIT>' ] <EOL> self . _assert_dry_run_flag_worked ( parse ( short_args ) , True ) <EOL> short_args += '<STR_LIT>' . split ( ) <EOL> conflicts = [ '<STR_LIT>' ] <EOL> self . _check_server_conflict_message ( short_args , '<STR_LIT>' ) <EOL> short_args += [ '<STR_LIT>' ] <EOL> conflicts += [ '<STR_LIT>' ] <EOL> self . _check_server_conflict_message ( short_args , conflicts ) <EOL> def _certonly_new_request_common ( self , mock_client , args = None ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_renewal : <EOL> mock_renewal . return_value = ( "<STR_LIT>" , None ) <EOL> with mock . patch ( '<STR_LIT>' ) as mock_init : <EOL> mock_init . return_value = mock_client <EOL> if args is None : <EOL> args = [ ] <EOL> args += '<STR_LIT>' . split ( ) <EOL> self . _call ( args ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_certonly_dry_run_new_request_success ( self , mock_get_utility ) : <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client . obtain_and_enroll_certificate . return_value = None <EOL> self . _certonly_new_request_common ( mock_client , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <EOL> mock_client . obtain_and_enroll_certificate . call_count , <NUM_LIT:1> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in mock_get_utility ( ) . add_message . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( mock_get_utility ( ) . add_message . call_count , <NUM_LIT:1> ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_certonly_new_request_success ( self , mock_get_utility , mock_notAfter ) : <EOL> cert_path = '<STR_LIT>' <EOL> date = '<STR_LIT>' <EOL> mock_notAfter ( ) . date . return_value = date <EOL> mock_lineage = mock . MagicMock ( cert = cert_path , fullchain = cert_path ) <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client . obtain_and_enroll_certificate . return_value = mock_lineage <EOL> self . _certonly_new_request_common ( mock_client ) <EOL> self . assertEqual ( <EOL> mock_client . obtain_and_enroll_certificate . call_count , <NUM_LIT:1> ) <EOL> cert_msg = mock_get_utility ( ) . add_message . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( cert_path in cert_msg ) <EOL> self . assertTrue ( date in cert_msg ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in mock_get_utility ( ) . add_message . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> def test_certonly_new_request_failure ( self ) : <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client . obtain_and_enroll_certificate . return_value = False <EOL> self . assertRaises ( errors . Error , <EOL> self . _certonly_new_request_common , mock_client ) <EOL> def _test_renewal_common ( self , due_for_renewal , extra_args , log_out = None , <EOL> args = None , should_renew = True , error_expected = False ) : <EOL> cert_path = '<STR_LIT>' <EOL> chain_path = '<STR_LIT>' <EOL> mock_lineage = mock . MagicMock ( cert = cert_path , fullchain = chain_path ) <EOL> mock_lineage . should_autorenew . return_value = due_for_renewal <EOL> mock_certr = mock . MagicMock ( ) <EOL> mock_key = mock . MagicMock ( pem = '<STR_LIT>' ) <EOL> mock_client = mock . MagicMock ( ) <EOL> stdout = None <EOL> mock_client . obtain_certificate . return_value = ( mock_certr , '<STR_LIT>' , <EOL> mock_key , '<STR_LIT>' ) <EOL> try : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_fdc : <EOL> mock_fdc . return_value = ( mock_lineage , None ) <EOL> with mock . patch ( '<STR_LIT>' ) as mock_init : <EOL> mock_init . return_value = mock_client <EOL> get_utility_path = '<STR_LIT>' <EOL> with mock . patch ( get_utility_path ) as mock_get_utility : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_ssl : <EOL> mock_latest = mock . MagicMock ( ) <EOL> mock_latest . get_issuer . return_value = "<STR_LIT>" <EOL> mock_ssl . crypto . load_certificate . return_value = mock_latest <EOL> with mock . patch ( '<STR_LIT>' ) : <EOL> if not args : <EOL> args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if extra_args : <EOL> args += extra_args <EOL> try : <EOL> ret , stdout , _ , _ = self . _call ( args ) <EOL> if ret : <EOL> print ( "<STR_LIT>" , ret ) <EOL> raise AssertionError ( ret ) <EOL> assert not error_expected , "<STR_LIT>" <EOL> except : <EOL> if not error_expected : <EOL> raise AssertionError ( <EOL> "<STR_LIT>" + <EOL> traceback . format_exc ( ) ) <EOL> if should_renew : <EOL> mock_client . obtain_certificate . assert_called_once_with ( [ '<STR_LIT>' ] ) <EOL> else : <EOL> self . assertEqual ( mock_client . obtain_certificate . call_count , <NUM_LIT:0> ) <EOL> except : <EOL> self . _dump_log ( ) <EOL> raise <EOL> finally : <EOL> if log_out : <EOL> with open ( os . path . join ( self . logs_dir , "<STR_LIT>" ) ) as lf : <EOL> self . assertTrue ( log_out in lf . read ( ) ) <EOL> return mock_lineage , mock_get_utility , stdout <EOL> def test_certonly_renewal ( self ) : <EOL> lineage , get_utility , _ = self . _test_renewal_common ( True , [ ] ) <EOL> self . assertEqual ( lineage . save_successor . call_count , <NUM_LIT:1> ) <EOL> lineage . update_all_links_to . assert_called_once_with ( <EOL> lineage . latest_common_version ( ) ) <EOL> cert_msg = get_utility ( ) . add_message . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in cert_msg ) <EOL> self . assertTrue ( '<STR_LIT>' in get_utility ( ) . add_message . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> def test_certonly_renewal_triggers ( self ) : <EOL> _ , get_utility , _ = self . _test_renewal_common ( False , [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> log_out = "<STR_LIT>" ) <EOL> self . assertEqual ( get_utility ( ) . add_message . call_count , <NUM_LIT:1> ) <EOL> self . assertTrue ( '<STR_LIT>' in get_utility ( ) . add_message . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> self . _test_renewal_common ( False , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> log_out = "<STR_LIT>" ) <EOL> self . assertEqual ( get_utility ( ) . add_message . call_count , <NUM_LIT:1> ) <EOL> self . _test_renewal_common ( False , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> log_out = "<STR_LIT>" , should_renew = False ) <EOL> def _dump_log ( self ) : <EOL> with open ( os . path . join ( self . logs_dir , "<STR_LIT>" ) ) as lf : <EOL> print ( "<STR_LIT>" ) <EOL> print ( lf . read ( ) ) <EOL> def _make_test_renewal_conf ( self , testfile ) : <EOL> with open ( test_util . vector_path ( testfile ) ) as src : <EOL> renewal_conf = src . read ( ) . replace ( "<STR_LIT>" , test_util . vector_path ( ) ) <EOL> rd = os . path . join ( self . config_dir , "<STR_LIT>" ) <EOL> if not os . path . exists ( rd ) : <EOL> os . makedirs ( rd ) <EOL> rc = os . path . join ( rd , "<STR_LIT>" ) <EOL> with open ( rc , "<STR_LIT:w>" ) as dest : <EOL> dest . write ( renewal_conf ) <EOL> return rc <EOL> def test_renew_verb ( self ) : <EOL> self . _make_test_renewal_conf ( '<STR_LIT>' ) <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . _test_renewal_common ( True , [ ] , args = args , should_renew = True ) <EOL> def test_quiet_renew ( self ) : <EOL> self . _make_test_renewal_conf ( '<STR_LIT>' ) <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> _ , _ , stdout = self . _test_renewal_common ( True , [ ] , args = args , should_renew = True ) <EOL> out = stdout . getvalue ( ) <EOL> self . assertTrue ( "<STR_LIT>" in out ) <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> _ , _ , stdout = self . _test_renewal_common ( True , [ ] , args = args , should_renew = True ) <EOL> out = stdout . getvalue ( ) <EOL> self . assertEqual ( "<STR_LIT>" , out ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_ancient_webroot_renewal_conf ( self , mock_set_by_cli ) : <EOL> mock_set_by_cli . return_value = False <EOL> rc_path = self . _make_test_renewal_conf ( '<STR_LIT>' ) <EOL> args = mock . MagicMock ( account = None , email = None , webroot_path = None ) <EOL> config = configuration . NamespaceConfig ( args ) <EOL> lineage = storage . RenewableCert ( rc_path , <EOL> configuration . RenewerConfiguration ( config ) ) <EOL> renewalparams = lineage . configuration [ "<STR_LIT>" ] <EOL> renewal . _restore_webroot_config ( config , renewalparams ) <EOL> self . assertEqual ( config . webroot_path , [ "<STR_LIT>" ] ) <EOL> def test_renew_verb_empty_config ( self ) : <EOL> rd = os . path . join ( self . config_dir , '<STR_LIT>' ) <EOL> if not os . path . exists ( rd ) : <EOL> os . makedirs ( rd ) <EOL> with open ( os . path . join ( rd , '<STR_LIT>' ) , '<STR_LIT:w>' ) : <EOL> pass <EOL> args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . _test_renewal_common ( False , [ ] , args = args , should_renew = False , error_expected = True ) <EOL> def _make_dummy_renewal_config ( self ) : <EOL> renewer_configs_dir = os . path . join ( self . config_dir , '<STR_LIT>' ) <EOL> os . makedirs ( renewer_configs_dir ) <EOL> with open ( os . path . join ( renewer_configs_dir , '<STR_LIT>' ) , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> def _test_renew_common ( self , renewalparams = None , names = None , <EOL> assert_oc_called = None , ** kwargs ) : <EOL> self . _make_dummy_renewal_config ( ) <EOL> with mock . patch ( '<STR_LIT>' ) as mock_rc : <EOL> mock_lineage = mock . MagicMock ( ) <EOL> mock_lineage . fullchain = "<STR_LIT>" <EOL> if renewalparams is not None : <EOL> mock_lineage . configuration = { '<STR_LIT>' : renewalparams } <EOL> if names is not None : <EOL> mock_lineage . names . return_value = names <EOL> mock_rc . return_value = mock_lineage <EOL> with mock . patch ( '<STR_LIT>' ) as mock_obtain_cert : <EOL> kwargs . setdefault ( '<STR_LIT:args>' , [ '<STR_LIT>' ] ) <EOL> self . _test_renewal_common ( True , None , should_renew = False , ** kwargs ) <EOL> if assert_oc_called is not None : <EOL> if assert_oc_called : <EOL> self . assertTrue ( mock_obtain_cert . called ) <EOL> else : <EOL> self . assertFalse ( mock_obtain_cert . called ) <EOL> def test_renew_no_renewalparams ( self ) : <EOL> self . _test_renew_common ( assert_oc_called = False , error_expected = True ) <EOL> def test_renew_no_authenticator ( self ) : <EOL> self . _test_renew_common ( renewalparams = { } , assert_oc_called = False , <EOL> error_expected = True ) <EOL> def test_renew_with_bad_int ( self ) : <EOL> renewalparams = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _test_renew_common ( renewalparams = renewalparams , error_expected = True , <EOL> assert_oc_called = False ) <EOL> def test_renew_with_nonetype_http01 ( self ) : <EOL> renewalparams = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:None>' } <EOL> self . _test_renew_common ( renewalparams = renewalparams , <EOL> assert_oc_called = True ) <EOL> def test_renew_with_bad_domain ( self ) : <EOL> renewalparams = { '<STR_LIT>' : '<STR_LIT>' } <EOL> names = [ '<STR_LIT>' ] <EOL> self . _test_renew_common ( renewalparams = renewalparams , error_expected = True , <EOL> names = names , assert_oc_called = False ) <EOL> def test_renew_with_configurator ( self ) : <EOL> renewalparams = { '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _test_renew_common ( <EOL> renewalparams = renewalparams , assert_oc_called = True , <EOL> args = '<STR_LIT>' . split ( ) ) <EOL> def test_renew_plugin_config_restoration ( self ) : <EOL> renewalparams = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:None>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> self . _test_renew_common ( renewalparams = renewalparams , <EOL> assert_oc_called = True ) <EOL> def test_renew_reconstitute_error ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_reconstitute : <EOL> mock_reconstitute . side_effect = Exception <EOL> self . _test_renew_common ( assert_oc_called = False , error_expected = True ) <EOL> def test_renew_obtain_cert_error ( self ) : <EOL> self . _make_dummy_renewal_config ( ) <EOL> with mock . patch ( '<STR_LIT>' ) as mock_rc : <EOL> mock_lineage = mock . MagicMock ( ) <EOL> mock_lineage . fullchain = "<STR_LIT>" <EOL> mock_rc . return_value = mock_lineage <EOL> mock_lineage . configuration = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> with mock . patch ( '<STR_LIT>' ) as mock_obtain_cert : <EOL> mock_obtain_cert . side_effect = Exception <EOL> self . _test_renewal_common ( True , None , error_expected = True , <EOL> args = [ '<STR_LIT>' ] , should_renew = False ) <EOL> def test_renew_with_bad_cli_args ( self ) : <EOL> self . _test_renewal_common ( True , None , args = '<STR_LIT>' . split ( ) , <EOL> should_renew = False , error_expected = True ) <EOL> self . _test_renewal_common ( True , None , args = '<STR_LIT>' . format ( CSR ) . split ( ) , <EOL> should_renew = False , error_expected = True ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_certonly_reinstall ( self , mock_init , mock_renewal , mock_get_utility ) : <EOL> mock_renewal . return_value = ( '<STR_LIT>' , mock . MagicMock ( ) ) <EOL> mock_init . return_value = mock_client = mock . MagicMock ( ) <EOL> self . _call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertFalse ( mock_client . obtain_certificate . called ) <EOL> self . assertFalse ( mock_client . obtain_and_enroll_certificate . called ) <EOL> self . assertEqual ( mock_get_utility ( ) . add_message . call_count , <NUM_LIT:0> ) <EOL> def _test_certonly_csr_common ( self , extra_args = None ) : <EOL> certr = '<STR_LIT>' <EOL> chain = '<STR_LIT>' <EOL> mock_client = mock . MagicMock ( ) <EOL> mock_client . obtain_certificate_from_csr . return_value = ( certr , chain ) <EOL> cert_path = '<STR_LIT>' <EOL> mock_client . save_certificate . return_value = cert_path , None , None <EOL> with mock . patch ( '<STR_LIT>' ) as mock_init : <EOL> mock_init . return_value = mock_client <EOL> get_utility_path = '<STR_LIT>' <EOL> with mock . patch ( get_utility_path ) as mock_get_utility : <EOL> chain_path = '<STR_LIT>' <EOL> full_path = '<STR_LIT>' <EOL> args = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( <EOL> CSR , cert_path , chain_path , full_path ) . split ( ) <EOL> if extra_args : <EOL> args += extra_args <EOL> with mock . patch ( '<STR_LIT>' ) : <EOL> self . _call ( args ) <EOL> if '<STR_LIT>' in args : <EOL> self . assertFalse ( mock_client . save_certificate . called ) <EOL> else : <EOL> mock_client . save_certificate . assert_called_once_with ( <EOL> certr , chain , cert_path , chain_path , full_path ) <EOL> return mock_get_utility <EOL> def test_certonly_csr ( self ) : <EOL> mock_get_utility = self . _test_certonly_csr_common ( ) <EOL> cert_msg = mock_get_utility ( ) . add_message . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in cert_msg ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in mock_get_utility ( ) . add_message . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> def test_certonly_csr_dry_run ( self ) : <EOL> mock_get_utility = self . _test_certonly_csr_common ( [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( mock_get_utility ( ) . add_message . call_count , <NUM_LIT:1> ) <EOL> self . assertTrue ( <EOL> '<STR_LIT>' in mock_get_utility ( ) . add_message . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_revoke_with_key ( self , mock_acme_client ) : <EOL> server = '<STR_LIT>' <EOL> self . _call_no_clientmock ( [ '<STR_LIT>' , CERT , '<STR_LIT>' , KEY , <EOL> '<STR_LIT>' , server , '<STR_LIT>' ] ) <EOL> with open ( KEY ) as f : <EOL> mock_acme_client . Client . assert_called_once_with ( <EOL> server , key = jose . JWK . load ( f . read ( ) ) , net = mock . ANY ) <EOL> with open ( CERT ) as f : <EOL> cert = crypto_util . pyopenssl_load_certificate ( f . read ( ) ) [ <NUM_LIT:0> ] <EOL> mock_revoke = mock_acme_client . Client ( ) . revoke <EOL> mock_revoke . assert_called_once_with ( jose . ComparableX509 ( cert ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_revoke_without_key ( self , mock_determine_account ) : <EOL> mock_determine_account . return_value = ( mock . MagicMock ( ) , None ) <EOL> _ , _ , _ , client = self . _call ( [ '<STR_LIT>' , CERT , '<STR_LIT>' ] ) <EOL> with open ( CERT ) as f : <EOL> cert = crypto_util . pyopenssl_load_certificate ( f . read ( ) ) [ <NUM_LIT:0> ] <EOL> mock_revoke = client . acme_from_config_key ( ) . revoke <EOL> mock_revoke . assert_called_once_with ( jose . ComparableX509 ( cert ) ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_handle_exception ( self , mock_sys ) : <EOL> from acme import messages <EOL> config = mock . MagicMock ( ) <EOL> mock_open = mock . mock_open ( ) <EOL> with mock . patch ( '<STR_LIT>' , mock_open , create = True ) : <EOL> exception = Exception ( '<STR_LIT>' ) <EOL> config . verbose_count = <NUM_LIT:1> <EOL> main . _handle_exception ( <EOL> Exception , exc_value = exception , trace = None , config = None ) <EOL> mock_open ( ) . write . assert_called_once_with ( '<STR_LIT>' . join ( <EOL> traceback . format_exception_only ( Exception , exception ) ) ) <EOL> error_msg = mock_sys . exit . call_args_list [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> with mock . patch ( '<STR_LIT>' , mock_open , create = True ) : <EOL> mock_open . side_effect = [ KeyboardInterrupt ] <EOL> error = errors . Error ( '<STR_LIT>' ) <EOL> main . _handle_exception ( <EOL> errors . Error , exc_value = error , trace = None , config = None ) <EOL> mock_sys . exit . assert_any_call ( '<STR_LIT>' . join ( <EOL> traceback . format_exception_only ( errors . Error , error ) ) ) <EOL> exception = messages . Error ( detail = '<STR_LIT>' , typ = '<STR_LIT>' , <EOL> title = '<STR_LIT>' ) <EOL> config = mock . MagicMock ( debug = False , verbose_count = - <NUM_LIT:3> ) <EOL> main . _handle_exception ( <EOL> messages . Error , exc_value = exception , trace = None , config = config ) <EOL> error_msg = mock_sys . exit . call_args_list [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> self . assertTrue ( '<STR_LIT>' not in error_msg ) <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> config = mock . MagicMock ( debug = False , verbose_count = <NUM_LIT:1> ) <EOL> main . _handle_exception ( <EOL> messages . Error , exc_value = exception , trace = None , config = config ) <EOL> error_msg = mock_sys . exit . call_args_list [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> self . assertTrue ( '<STR_LIT>' in error_msg ) <EOL> interrupt = KeyboardInterrupt ( '<STR_LIT>' ) <EOL> main . _handle_exception ( <EOL> KeyboardInterrupt , exc_value = interrupt , trace = None , config = None ) <EOL> mock_sys . exit . assert_called_with ( '<STR_LIT>' . join ( <EOL> traceback . format_exception_only ( KeyboardInterrupt , interrupt ) ) ) <EOL> def test_read_file ( self ) : <EOL> rel_test_path = os . path . relpath ( os . path . join ( self . tmp_dir , '<STR_LIT:foo>' ) ) <EOL> self . assertRaises ( <EOL> argparse . ArgumentTypeError , cli . read_file , rel_test_path ) <EOL> test_contents = '<STR_LIT>' <EOL> with open ( rel_test_path , '<STR_LIT:w>' ) as f : <EOL> f . write ( test_contents ) <EOL> path , contents = cli . read_file ( rel_test_path ) <EOL> self . assertEqual ( path , os . path . abspath ( path ) ) <EOL> self . assertEqual ( contents , test_contents ) <EOL> def test_agree_dev_preview_config ( self ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mocked_run : <EOL> self . _call ( [ '<STR_LIT:-c>' , test_util . vector_path ( '<STR_LIT>' ) ] ) <EOL> self . assertTrue ( mocked_run . called ) <EOL> class DetermineAccountTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . args = mock . MagicMock ( account = None , email = None , <EOL> register_unsafely_without_email = False ) <EOL> self . config = configuration . NamespaceConfig ( self . args ) <EOL> self . accs = [ mock . MagicMock ( id = '<STR_LIT:x>' ) , mock . MagicMock ( id = '<STR_LIT:y>' ) ] <EOL> self . account_storage = account . AccountMemoryStorage ( ) <EOL> def _call ( self ) : <EOL> from certbot . main import _determine_account <EOL> with mock . patch ( '<STR_LIT>' ) as mock_storage : <EOL> mock_storage . return_value = self . account_storage <EOL> return _determine_account ( self . config ) <EOL> def test_args_account_set ( self ) : <EOL> self . account_storage . save ( self . accs [ <NUM_LIT:1> ] ) <EOL> self . config . account = self . accs [ <NUM_LIT:1> ] . id <EOL> self . assertEqual ( ( self . accs [ <NUM_LIT:1> ] , None ) , self . _call ( ) ) <EOL> self . assertEqual ( self . accs [ <NUM_LIT:1> ] . id , self . config . account ) <EOL> self . assertTrue ( self . config . email is None ) <EOL> def test_single_account ( self ) : <EOL> self . account_storage . save ( self . accs [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( ( self . accs [ <NUM_LIT:0> ] , None ) , self . _call ( ) ) <EOL> self . assertEqual ( self . accs [ <NUM_LIT:0> ] . id , self . config . account ) <EOL> self . assertTrue ( self . config . email is None ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_multiple_accounts ( self , mock_choose_accounts ) : <EOL> for acc in self . accs : <EOL> self . account_storage . save ( acc ) <EOL> mock_choose_accounts . return_value = self . accs [ <NUM_LIT:1> ] <EOL> self . assertEqual ( ( self . accs [ <NUM_LIT:1> ] , None ) , self . _call ( ) ) <EOL> self . assertEqual ( <EOL> set ( mock_choose_accounts . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) , set ( self . accs ) ) <EOL> self . assertEqual ( self . accs [ <NUM_LIT:1> ] . id , self . config . account ) <EOL> self . assertTrue ( self . config . email is None ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_no_accounts_no_email ( self , mock_get_email ) : <EOL> mock_get_email . return_value = '<STR_LIT>' <EOL> with mock . patch ( '<STR_LIT>' ) as client : <EOL> client . register . return_value = ( <EOL> self . accs [ <NUM_LIT:0> ] , mock . sentinel . acme ) <EOL> self . assertEqual ( ( self . accs [ <NUM_LIT:0> ] , mock . sentinel . acme ) , self . _call ( ) ) <EOL> client . register . assert_called_once_with ( <EOL> self . config , self . account_storage , tos_cb = mock . ANY ) <EOL> self . assertEqual ( self . accs [ <NUM_LIT:0> ] . id , self . config . account ) <EOL> self . assertEqual ( '<STR_LIT>' , self . config . email ) <EOL> def test_no_accounts_email ( self ) : <EOL> self . config . email = '<STR_LIT>' <EOL> with mock . patch ( '<STR_LIT>' ) as client : <EOL> client . register . return_value = ( self . accs [ <NUM_LIT:1> ] , mock . sentinel . acme ) <EOL> self . _call ( ) <EOL> self . assertEqual ( self . accs [ <NUM_LIT:1> ] . id , self . config . account ) <EOL> self . assertEqual ( '<STR_LIT>' , self . config . email ) <EOL> class DuplicativeCertsTest ( storage_test . BaseRenewableCertTest ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> super ( DuplicativeCertsTest , self ) . setUp ( ) <EOL> self . config . write ( ) <EOL> self . _write_out_ex_kinds ( ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . tempdir ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_find_duplicative_names ( self , unused_makedir ) : <EOL> from certbot . main import _find_duplicative_certs <EOL> test_cert = test_util . load_vector ( '<STR_LIT>' ) <EOL> with open ( self . test_rc . cert , '<STR_LIT:w>' ) as f : <EOL> f . write ( test_cert ) <EOL> result = _find_duplicative_certs ( <EOL> self . cli_config , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( result , ( None , None ) ) <EOL> result = _find_duplicative_certs ( <EOL> self . cli_config , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( result [ <NUM_LIT:0> ] . configfile . filename . endswith ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( result [ <NUM_LIT:1> ] , None ) <EOL> result = _find_duplicative_certs ( <EOL> self . cli_config , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( result [ <NUM_LIT:0> ] , None ) <EOL> self . assertTrue ( result [ <NUM_LIT:1> ] . configfile . filename . endswith ( '<STR_LIT>' ) ) <EOL> result = _find_duplicative_certs ( <EOL> self . cli_config , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( result , ( None , None ) ) <EOL> class DefaultTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . default1 = cli . _Default ( ) <EOL> self . default2 = cli . _Default ( ) <EOL> def test_boolean ( self ) : <EOL> self . assertFalse ( self . default1 ) <EOL> self . assertFalse ( self . default2 ) <EOL> def test_equality ( self ) : <EOL> self . assertEqual ( self . default1 , self . default2 ) <EOL> def test_hash ( self ) : <EOL> self . assertEqual ( hash ( self . default1 ) , hash ( self . default2 ) ) <EOL> class SetByCliTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> reload_module ( cli ) <EOL> def test_webroot_map ( self ) : <EOL> args = '<STR_LIT>' . split ( ) <EOL> verb = '<STR_LIT>' <EOL> self . assertTrue ( _call_set_by_cli ( '<STR_LIT>' , args , verb ) ) <EOL> def test_report_config_interaction_str ( self ) : <EOL> cli . report_config_interaction ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> cli . report_config_interaction ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . _test_report_config_interaction_common ( ) <EOL> def test_report_config_interaction_iterable ( self ) : <EOL> cli . report_config_interaction ( ( '<STR_LIT>' , ) , <EOL> ( '<STR_LIT>' , ) ) <EOL> cli . report_config_interaction ( ( '<STR_LIT>' , ) , ( '<STR_LIT>' , ) ) <EOL> self . _test_report_config_interaction_common ( ) <EOL> def _test_report_config_interaction_common ( self ) : <EOL> """<STR_LIT>""" <EOL> args = [ '<STR_LIT>' ] <EOL> verb = '<STR_LIT>' <EOL> for v in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertTrue ( _call_set_by_cli ( v , args , verb ) ) <EOL> cli . set_by_cli . detector = None <EOL> args = [ '<STR_LIT>' ] <EOL> for v in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . assertTrue ( _call_set_by_cli ( v , args , verb ) ) <EOL> self . assertFalse ( _call_set_by_cli ( '<STR_LIT>' , args , verb ) ) <EOL> def _call_set_by_cli ( var , args , verb ) : <EOL> with mock . patch ( '<STR_LIT>' ) as mock_parser : <EOL> mock_parser . args = args <EOL> mock_parser . verb = verb <EOL> return cli . set_by_cli ( var ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
