<s> import decimal <EOL> import os <EOL> from contextlib import contextmanager <EOL> from django . test import TestCase <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from mock import patch <EOL> from configurations . values import ( Value , BooleanValue , IntegerValue , <EOL> FloatValue , DecimalValue , ListValue , <EOL> TupleValue , SingleNestedTupleValue , <EOL> SingleNestedListValue , SetValue , <EOL> DictValue , URLValue , EmailValue , IPValue , <EOL> RegexValue , PathValue , SecretValue , <EOL> DatabaseURLValue , EmailURLValue , <EOL> CacheURLValue , BackendsValue , <EOL> CastingMixin , SearchURLValue , <EOL> setup_value ) <EOL> @ contextmanager <EOL> def env ( ** kwargs ) : <EOL> with patch . dict ( os . environ , clear = True , ** kwargs ) : <EOL> yield <EOL> class FailingCasterValue ( CastingMixin , Value ) : <EOL> caster = '<STR_LIT>' <EOL> class ValueTests ( TestCase ) : <EOL> def test_value_with_default ( self ) : <EOL> value = Value ( '<STR_LIT:default>' , environ = False ) <EOL> self . assertEqual ( type ( value ) , type ( '<STR_LIT:default>' ) ) <EOL> self . assertEqual ( value , '<STR_LIT:default>' ) <EOL> self . assertEqual ( str ( value ) , '<STR_LIT:default>' ) <EOL> def test_value_with_default_and_late_binding ( self ) : <EOL> value = Value ( '<STR_LIT:default>' , environ = False , late_binding = True ) <EOL> self . assertEqual ( type ( value ) , Value ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT:default>' ) <EOL> value = Value ( environ_name = '<STR_LIT>' ) <EOL> self . assertEqual ( type ( value ) , type ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( value , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( value ) , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' . format ( value ) , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:%s>' % value , '<STR_LIT>' ) <EOL> value = Value ( environ_name = '<STR_LIT>' , late_binding = True ) <EOL> self . assertEqual ( type ( value ) , Value ) <EOL> self . assertEqual ( value . value , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( value ) , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' . format ( value ) , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT:%s>' % value , '<STR_LIT>' ) <EOL> self . assertEqual ( repr ( value ) , repr ( '<STR_LIT>' ) ) <EOL> @ patch . dict ( os . environ , clear = True , DJANGO_TEST = '<STR_LIT>' ) <EOL> def test_env_var ( self ) : <EOL> value = Value ( '<STR_LIT:default>' ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( str ( value ) , '<STR_LIT>' ) <EOL> self . assertNotEqual ( value . setup ( '<STR_LIT>' ) , value . default ) <EOL> self . assertEqual ( value . to_python ( os . environ [ '<STR_LIT>' ] ) , <EOL> value . setup ( '<STR_LIT>' ) ) <EOL> def test_value_reuse ( self ) : <EOL> value1 = Value ( '<STR_LIT:default>' ) <EOL> value2 = Value ( value1 ) <EOL> self . assertEqual ( value1 . setup ( '<STR_LIT>' ) , '<STR_LIT:default>' ) <EOL> self . assertEqual ( value2 . setup ( '<STR_LIT>' ) , '<STR_LIT:default>' ) <EOL> with env ( DJANGO_TEST1 = '<STR_LIT>' , DJANGO_TEST2 = '<STR_LIT>' ) : <EOL> self . assertEqual ( value1 . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( value2 . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_value_var_equal ( self ) : <EOL> value1 = Value ( '<STR_LIT:default>' ) <EOL> value2 = Value ( '<STR_LIT:default>' ) <EOL> self . assertEqual ( value1 , value2 ) <EOL> self . assertTrue ( value1 in [ '<STR_LIT:default>' ] ) <EOL> def test_env_var_prefix ( self ) : <EOL> with patch . dict ( os . environ , clear = True , ACME_TEST = '<STR_LIT>' ) : <EOL> value = Value ( '<STR_LIT:default>' , environ_prefix = '<STR_LIT>' ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> with patch . dict ( os . environ , clear = True , TEST = '<STR_LIT>' ) : <EOL> value = Value ( '<STR_LIT:default>' , environ_prefix = '<STR_LIT>' ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> with patch . dict ( os . environ , clear = True , ACME_TEST = '<STR_LIT>' ) : <EOL> value = Value ( '<STR_LIT:default>' , environ_prefix = '<STR_LIT>' ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_boolean_values_true ( self ) : <EOL> value = BooleanValue ( False ) <EOL> for truthy in value . true_values : <EOL> with env ( DJANGO_TEST = truthy ) : <EOL> self . assertTrue ( value . setup ( '<STR_LIT>' ) ) <EOL> def test_boolean_values_faulty ( self ) : <EOL> self . assertRaises ( ValueError , BooleanValue , '<STR_LIT:false>' ) <EOL> def test_boolean_values_false ( self ) : <EOL> value = BooleanValue ( True ) <EOL> for falsy in value . false_values : <EOL> with env ( DJANGO_TEST = falsy ) : <EOL> self . assertFalse ( value . setup ( '<STR_LIT>' ) ) <EOL> def test_boolean_values_nonboolean ( self ) : <EOL> value = BooleanValue ( True ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_boolean_values_assign_false_to_another_booleanvalue ( self ) : <EOL> value1 = BooleanValue ( False ) <EOL> value2 = BooleanValue ( value1 ) <EOL> self . assertFalse ( value1 . setup ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( value2 . setup ( '<STR_LIT>' ) ) <EOL> def test_integer_values ( self ) : <EOL> value = IntegerValue ( <NUM_LIT:1> ) <EOL> with env ( DJANGO_TEST = '<STR_LIT:2>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , <NUM_LIT:2> ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_float_values ( self ) : <EOL> value = FloatValue ( <NUM_LIT:1.0> ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_decimal_values ( self ) : <EOL> value = DecimalValue ( decimal . Decimal ( <NUM_LIT:1> ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT:2>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , decimal . Decimal ( <NUM_LIT:2> ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_failing_caster ( self ) : <EOL> self . assertRaises ( ImproperlyConfigured , FailingCasterValue ) <EOL> def test_list_values_default ( self ) : <EOL> value = ListValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ '<STR_LIT:2>' , '<STR_LIT:2>' ] ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ '<STR_LIT:2>' , '<STR_LIT:2>' ] ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ ] ) <EOL> def test_list_values_separator ( self ) : <EOL> value = ListValue ( separator = '<STR_LIT::>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_List_values_converter ( self ) : <EOL> value = ListValue ( converter = int ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ <NUM_LIT:2> , <NUM_LIT:2> ] ) <EOL> value = ListValue ( converter = float ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> def test_list_values_custom_converter ( self ) : <EOL> value = ListValue ( converter = lambda x : x * <NUM_LIT:2> ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_list_values_converter_exception ( self ) : <EOL> value = ListValue ( converter = int ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_tuple_values_default ( self ) : <EOL> value = TupleValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , ( '<STR_LIT:2>' , '<STR_LIT:2>' ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , ( '<STR_LIT:2>' , '<STR_LIT:2>' ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , ( ) ) <EOL> def test_single_nested_list_values_default ( self ) : <EOL> value = SingleNestedListValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = [ [ '<STR_LIT:2>' , '<STR_LIT:3>' ] , [ '<STR_LIT:4>' , '<STR_LIT:5>' ] ] <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = [ [ '<STR_LIT:2>' ] , [ '<STR_LIT:3>' ] , [ '<STR_LIT:4>' ] , [ '<STR_LIT:5>' ] ] <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = [ [ '<STR_LIT:2>' , '<STR_LIT:3>' , '<STR_LIT:4>' , '<STR_LIT:5>' ] ] <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = [ [ '<STR_LIT:2>' , '<STR_LIT:3>' ] , [ '<STR_LIT:4>' , '<STR_LIT:5>' ] ] <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ ] ) <EOL> def test_single_nested_list_values_separator ( self ) : <EOL> value = SingleNestedListValue ( seq_separator = '<STR_LIT::>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ [ '<STR_LIT:2>' , '<STR_LIT:3>' ] , [ '<STR_LIT:4>' , '<STR_LIT:5>' ] ] ) <EOL> def test_single_nested_list_values_converter ( self ) : <EOL> value = SingleNestedListValue ( converter = int ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , [ [ <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT:5> ] ] ) <EOL> def test_single_nested_list_values_converter_default ( self ) : <EOL> value = SingleNestedListValue ( [ [ '<STR_LIT:2>' , '<STR_LIT:3>' ] , [ '<STR_LIT:4>' , '<STR_LIT:5>' ] ] , converter = int ) <EOL> self . assertEqual ( value . value , [ [ <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT:5> ] ] ) <EOL> def test_single_nested_tuple_values_default ( self ) : <EOL> value = SingleNestedTupleValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = ( ( '<STR_LIT:2>' , '<STR_LIT:3>' ) , ( '<STR_LIT:4>' , '<STR_LIT:5>' ) ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = ( ( '<STR_LIT:2>' , ) , ( '<STR_LIT:3>' , ) , ( '<STR_LIT:4>' , ) , ( '<STR_LIT:5>' , ) ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = ( ( '<STR_LIT:2>' , '<STR_LIT:3>' , '<STR_LIT:4>' , '<STR_LIT:5>' ) , ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> expected = ( ( '<STR_LIT:2>' , '<STR_LIT:3>' ) , ( '<STR_LIT:4>' , '<STR_LIT:5>' ) ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , ( ) ) <EOL> def test_single_nested_tuple_values_separator ( self ) : <EOL> value = SingleNestedTupleValue ( seq_separator = '<STR_LIT::>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , ( ( '<STR_LIT:2>' , '<STR_LIT:3>' ) , ( '<STR_LIT:4>' , '<STR_LIT:5>' ) ) ) <EOL> def test_single_nested_tuple_values_converter ( self ) : <EOL> value = SingleNestedTupleValue ( converter = int ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:4> , <NUM_LIT:5> ) ) ) <EOL> def test_single_nested_tuple_values_converter_default ( self ) : <EOL> value = SingleNestedTupleValue ( ( ( '<STR_LIT:2>' , '<STR_LIT:3>' ) , ( '<STR_LIT:4>' , '<STR_LIT:5>' ) ) , converter = int ) <EOL> self . assertEqual ( value . value , ( ( <NUM_LIT:2> , <NUM_LIT:3> ) , ( <NUM_LIT:4> , <NUM_LIT:5> ) ) ) <EOL> def test_set_values_default ( self ) : <EOL> value = SetValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , set ( [ '<STR_LIT:2>' , '<STR_LIT:2>' ] ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , set ( [ '<STR_LIT:2>' , '<STR_LIT:2>' ] ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , set ( ) ) <EOL> def test_dict_values_default ( self ) : <EOL> value = DictValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { <NUM_LIT:2> : <NUM_LIT:2> } ) <EOL> expected = { <NUM_LIT:2> : <NUM_LIT:2> , '<STR_LIT:3>' : '<STR_LIT:3>' , '<STR_LIT:4>' : [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] } <EOL> with env ( DJANGO_TEST = "<STR_LIT>" ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = """<STR_LIT>""" ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , expected ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { } ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_email_values ( self ) : <EOL> value = EmailValue ( '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_url_values ( self ) : <EOL> value = URLValue ( '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_url_values_with_no_default ( self ) : <EOL> value = URLValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_url_values_with_wrong_default ( self ) : <EOL> self . assertRaises ( ValueError , URLValue , '<STR_LIT>' ) <EOL> def test_ip_values ( self ) : <EOL> value = IPValue ( '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT:127.0.0.1>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT:127.0.0.1>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_regex_values ( self ) : <EOL> value = RegexValue ( '<STR_LIT>' , regex = r'<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_path_values_with_check ( self ) : <EOL> value = PathValue ( ) <EOL> with env ( DJANGO_TEST = '<STR_LIT:/>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT:/>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , os . path . expanduser ( '<STR_LIT>' ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_path_values_no_check ( self ) : <EOL> value = PathValue ( check_exists = False ) <EOL> with env ( DJANGO_TEST = '<STR_LIT:/>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT:/>' ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , <EOL> os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with env ( DJANGO_TEST = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_secret_value ( self ) : <EOL> self . assertRaises ( ValueError , SecretValue , '<STR_LIT:default>' ) <EOL> value = SecretValue ( ) <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> with env ( DJANGO_SECRET_KEY = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> value = SecretValue ( environ_name = '<STR_LIT>' , <EOL> environ_prefix = None , <EOL> late_binding = True ) <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> with env ( FACEBOOK_API_SECRET = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_database_url_value ( self ) : <EOL> value = DatabaseURLValue ( ) <EOL> self . assertEqual ( value . default , { } ) <EOL> with env ( DATABASE_URL = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } } ) <EOL> def test_database_url_additional_args ( self ) : <EOL> def mock_database_url_caster ( self , url , engine = None ) : <EOL> return { '<STR_LIT>' : url , '<STR_LIT>' : engine } <EOL> with patch ( '<STR_LIT>' , mock_database_url_caster ) : <EOL> value = DatabaseURLValue ( engine = '<STR_LIT>' ) <EOL> with env ( DATABASE_URL = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } ) <EOL> def test_email_url_value ( self ) : <EOL> value = EmailURLValue ( ) <EOL> self . assertEqual ( value . default , { } ) <EOL> with env ( EMAIL_URL = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True } ) <EOL> with env ( EMAIL_URL = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : False } ) <EOL> with env ( EMAIL_URL = '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , value . setup , '<STR_LIT>' ) <EOL> def test_cache_url_value ( self ) : <EOL> cache_setting = { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> cache_url = '<STR_LIT>' <EOL> value = CacheURLValue ( cache_url ) <EOL> self . assertEqual ( value . default , cache_setting ) <EOL> value = CacheURLValue ( ) <EOL> self . assertEqual ( value . default , { } ) <EOL> with env ( CACHE_URL = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , cache_setting ) <EOL> with env ( CACHE_URL = '<STR_LIT>' ) : <EOL> with self . assertRaises ( Exception ) as cm : <EOL> value . setup ( '<STR_LIT>' ) <EOL> self . assertEqual ( cm . exception . args [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> with env ( CACHE_URL = '<STR_LIT>' ) : <EOL> with self . assertRaises ( ValueError ) as cm : <EOL> value . setup ( '<STR_LIT>' ) <EOL> self . assertEqual ( cm . exception . args [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" ) <EOL> def test_search_url_value ( self ) : <EOL> value = SearchURLValue ( ) <EOL> self . assertEqual ( value . default , { } ) <EOL> with env ( SEARCH_URL = '<STR_LIT>' ) : <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , { <EOL> '<STR_LIT:default>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:index>' , <EOL> } } ) <EOL> def test_backend_list_value ( self ) : <EOL> backends = [ '<STR_LIT>' ] <EOL> value = BackendsValue ( backends ) <EOL> self . assertEqual ( value . setup ( '<STR_LIT>' ) , backends ) <EOL> backends = [ '<STR_LIT>' ] <EOL> self . assertRaises ( ValueError , BackendsValue , backends ) <EOL> def test_tuple_value ( self ) : <EOL> value = TupleValue ( None ) <EOL> self . assertEqual ( value . default , ( ) ) <EOL> self . assertEqual ( value . value , ( ) ) <EOL> value = TupleValue ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( value . default , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> self . assertEqual ( value . value , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> def test_set_value ( self ) : <EOL> value = SetValue ( ) <EOL> self . assertEqual ( value . default , set ( ) ) <EOL> self . assertEqual ( value . value , set ( ) ) <EOL> value = SetValue ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> self . assertEqual ( value . default , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> self . assertEqual ( value . value , set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_setup_value ( self ) : <EOL> class Target ( object ) : <EOL> pass <EOL> value = EmailURLValue ( ) <EOL> with env ( EMAIL_URL = '<STR_LIT>' ) : <EOL> setup_value ( Target , '<STR_LIT>' , value ) <EOL> self . assertEqual ( Target . EMAIL , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : True <EOL> } ) <EOL> self . assertEqual ( Target . EMAIL_BACKEND , '<STR_LIT>' ) <EOL> self . assertEqual ( Target . EMAIL_FILE_PATH , '<STR_LIT>' ) <EOL> self . assertEqual ( Target . EMAIL_HOST , '<STR_LIT>' ) <EOL> self . assertEqual ( Target . EMAIL_HOST_PASSWORD , '<STR_LIT:password>' ) <EOL> self . assertEqual ( Target . EMAIL_HOST_USER , '<STR_LIT>' ) <EOL> self . assertEqual ( Target . EMAIL_PORT , <NUM_LIT> ) <EOL> self . assertEqual ( Target . EMAIL_USE_TLS , True ) </s>
