<s> """<STR_LIT>""" <EOL> import unittest <EOL> from mock import patch <EOL> from fabric . state import env <EOL> from prestoadmin import topology <EOL> from prestoadmin . standalone import config <EOL> from prestoadmin . standalone . config import StandaloneConfig <EOL> from prestoadmin . util . exception import ConfigurationError <EOL> from tests . unit . base_unit_case import BaseUnitCase <EOL> class TestTopologyConfig ( BaseUnitCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestTopologyConfig , self ) . setUp ( capture_output = True ) <EOL> @ patch ( '<STR_LIT>' ) <EOL> def test_fill_conf ( self , get_conf_from_file_mock ) : <EOL> get_conf_from_file_mock . return_value = { "<STR_LIT:username>" : "<STR_LIT>" , "<STR_LIT:port>" : "<STR_LIT:100>" } <EOL> config = StandaloneConfig ( ) <EOL> conf = config . read_conf ( ) <EOL> self . assertEqual ( conf , { "<STR_LIT:username>" : "<STR_LIT>" , "<STR_LIT:port>" : <NUM_LIT:100> , <EOL> "<STR_LIT>" : "<STR_LIT:localhost>" , <EOL> "<STR_LIT>" : [ "<STR_LIT:localhost>" ] } ) <EOL> def test_invalid_property ( self ) : <EOL> conf = { "<STR_LIT:username>" : "<STR_LIT>" , <EOL> "<STR_LIT:port>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> self . assertRaisesRegexp ( ConfigurationError , <EOL> "<STR_LIT>" , <EOL> config . validate , conf ) <EOL> def test_basic_valid_conf ( self ) : <EOL> conf = { "<STR_LIT:username>" : "<STR_LIT:user>" , <EOL> "<STR_LIT:port>" : <NUM_LIT> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] } <EOL> self . assertEqual ( config . validate ( conf . copy ( ) ) , conf ) <EOL> def test_valid_string_port_to_int ( self ) : <EOL> conf = { '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> validated_conf = config . validate ( conf . copy ( ) ) <EOL> self . assertEqual ( validated_conf [ '<STR_LIT:port>' ] , <NUM_LIT> ) <EOL> def test_empty_host ( self ) : <EOL> self . assertRaisesRegexp ( ConfigurationError , <EOL> "<STR_LIT>" , <EOL> config . validate_coordinator , ( "<STR_LIT>" ) ) <EOL> def test_valid_workers ( self ) : <EOL> workers = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assertEqual ( config . validate_workers ( workers ) , workers ) <EOL> def test_no_workers ( self ) : <EOL> self . assertRaisesRegexp ( ConfigurationError , <EOL> "<STR_LIT>" , <EOL> config . validate_workers , ( [ ] ) ) <EOL> def test_invalid_workers_type ( self ) : <EOL> self . assertRaisesRegexp ( ConfigurationError , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> config . validate_workers , ( "<STR_LIT>" ) ) <EOL> def test_invalid_coordinator_type ( self ) : <EOL> self . assertRaisesRegexp ( ConfigurationError , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> config . validate_coordinator , <EOL> ( [ "<STR_LIT>" , "<STR_LIT:list>" ] ) ) <EOL> def test_validate_workers_for_prompt ( self ) : <EOL> workers_input = "<STR_LIT>" <EOL> workers_list = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> self . assertEqual ( config . validate_workers_for_prompt ( workers_input ) , <EOL> workers_list ) <EOL> def test_show ( self ) : <EOL> env . roledefs = { '<STR_LIT>' : [ '<STR_LIT:hello>' ] , '<STR_LIT>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' ] , <EOL> '<STR_LIT:all>' : [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:hello>' ] } <EOL> env . user = '<STR_LIT:user>' <EOL> env . port = '<STR_LIT>' <EOL> self . remove_runs_once_flag ( topology . show ) <EOL> topology . show ( ) <EOL> self . assertEqual ( "<STR_LIT>" , self . test_stderr . getvalue ( ) ) <EOL> self . assertEqual ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> self . test_stdout . getvalue ( ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
