<s> import pytest <EOL> from mock import MagicMock , patch <EOL> from simple_settings . special_settings import ( <EOL> override_settings_by_env , <EOL> process_special_settings , <EOL> required_settings , <EOL> SPECIAL_SETTINGS_MAPPING , <EOL> ) <EOL> class TestSpecialSettings ( object ) : <EOL> @ pytest . fixture <EOL> def settings_dict_to_override ( self ) : <EOL> return { <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> <EOL> } <EOL> @ pytest . fixture <EOL> def settings_dict_required ( self ) : <EOL> return { '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> } } <EOL> def test_should_override_by_env ( self , settings_dict_to_override ) : <EOL> def mock_env_side_effect ( k , d = None ) : <EOL> return u'<STR_LIT>' if k == '<STR_LIT>' else d <EOL> with patch ( '<STR_LIT>' , side_effect = mock_env_side_effect ) : <EOL> override_settings_by_env ( settings_dict_to_override ) <EOL> assert settings_dict_to_override [ '<STR_LIT>' ] == u'<STR_LIT>' <EOL> assert settings_dict_to_override [ '<STR_LIT>' ] == <NUM_LIT:1> <EOL> def test_should_dont_override_by_env_if_settings_dont_have_special_key ( <EOL> self , settings_dict_to_override <EOL> ) : <EOL> def mock_env_side_effect ( k , d = None ) : <EOL> return u'<STR_LIT>' if k == '<STR_LIT>' else d <EOL> settings_dict_to_override [ '<STR_LIT>' ] [ '<STR_LIT>' ] = False <EOL> with patch ( '<STR_LIT>' , side_effect = mock_env_side_effect ) : <EOL> override_settings_by_env ( settings_dict_to_override ) <EOL> assert settings_dict_to_override [ '<STR_LIT>' ] == u'<STR_LIT>' <EOL> def test_required_settings_should_raise_value_error_for_a_lost_setting ( <EOL> self , settings_dict_required <EOL> ) : <EOL> with pytest . raises ( ValueError ) as exc : <EOL> required_settings ( settings_dict_required ) <EOL> assert '<STR_LIT>' in str ( exc ) <EOL> def test_should_call_functions_in_process_special_settings ( self ) : <EOL> mock = MagicMock ( ) <EOL> settings_dict = { '<STR_LIT>' : { '<STR_LIT:foo>' : mock } } <EOL> with patch . dict ( SPECIAL_SETTINGS_MAPPING , { '<STR_LIT:foo>' : mock } ) : <EOL> process_special_settings ( settings_dict ) <EOL> assert mock . called </s>
