Ejemplo n.º 1
0
 def test_gather_and_enforce_request_args_enumerated_defaults_values_for_default_cast_function_and_raise_value(self,
                                                                                                               tu_get_parm):
     tu_get_parm.return_value = 'ice'
     with current_app.test_request_context('/whatever?vanilla=ice'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'vanilla'}])
         assert fetched_value == {'vanilla': 'ice'}
         assert tu_get_parm.called_once_with('vanilla', default=None, cast_function=None, raise_value_error=True)
Ejemplo n.º 2
0
 def test_gather_and_enforce_request_args_enumerated_gets_nothing_when_parm_optional_and_absent_and_no_default(
         self):
     with current_app.test_request_context('/whatever'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{
             'name':
             'vanilla'
         }])
         assert fetched_value == {}
Ejemplo n.º 3
0
 def test_gather_and_enforce_request_args_enumerated_gets_parm_when_parm_optional_and_present(
         self):
     with current_app.test_request_context('/whatever?party=started'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{
             'name':
             'party'
         }])
         assert fetched_value == {'party': 'started'}
Ejemplo n.º 4
0
 def test_gather_and_enforce_request_args_enumerated_gets_default_when_parm_optional_and_absent_and_default(
         self):
     with current_app.test_request_context('/whatever'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{
             'name':
             'hammer',
             'default':
             'dont_hurt_em'
         }])
         assert fetched_value == {'hammer': 'dont_hurt_em'}
Ejemplo n.º 5
0
 def test_gather_and_enforce_request_args_enumerated_gets_parm_when_parm_required_and_present(
         self):
     with current_app.test_request_context('/whatever?c=d'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{
             'name':
             'c',
             'required':
             True
         }])
         assert fetched_value == {'c': 'd'}
Ejemplo n.º 6
0
 def test_gather_and_enforce_request_args_enumerated_throws_dce_when_no_name_supplied(
         self):
     with current_app.test_request_context('/whatever?yoo=hoo'):
         with pytest.raises(DocumentConfigurationError) as exception_info:
             fetched_value = tu.gather_and_enforce_request_args_enumerated(
                 [{
                     'required': True
                 }])
         assert 'bad call to gather_and_enforce_request_args: no name supplied' in str(
             exception_info.value)
Ejemplo n.º 7
0
 def test_gather_and_enforce_request_args_enumerated_passes_error_when_cast_fails(
         self):
     with current_app.test_request_context('/whatever?yoo=hoo'):
         with pytest.raises(ValueError) as exception_info:
             fetched_value = tu.gather_and_enforce_request_args_enumerated(
                 [{
                     'name': 'yoo',
                     'cast_function': int
                 }])
         assert 'problem casting parameter yoo (value hoo) as type int' in str(
             exception_info.value)
Ejemplo n.º 8
0
 def test_gather_and_enforce_request_args_enumerated_throws_dce_when_parm_required_and_absent(
         self):
     with current_app.test_request_context('/whatever?yoo=hoo'):
         with pytest.raises(DocumentConfigurationError) as exception_info:
             fetched_value = tu.gather_and_enforce_request_args_enumerated(
                 [{
                     'name': 'a',
                     'required': True
                 }])
         assert 'required parameter a not supplied in request' in str(
             exception_info.value)
Ejemplo n.º 9
0
 def test_gather_and_enforce_request_args_enumerated_defaults_values_for_default_cast_function_and_raise_value(
         self, tu_get_parm):
     tu_get_parm.return_value = 'ice'
     with current_app.test_request_context('/whatever?vanilla=ice'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{
             'name':
             'vanilla'
         }])
         assert fetched_value == {'vanilla': 'ice'}
         assert tu_get_parm.called_once_with('vanilla',
                                             default=None,
                                             cast_function=None,
                                             raise_value_error=True)
Ejemplo n.º 10
0
 def test_gather_and_enforce_request_args_enumerated_throws_dce_when_no_name_supplied(self):
     with current_app.test_request_context('/whatever?yoo=hoo'):
         with pytest.raises(DocumentConfigurationError) as exception_info:
             fetched_value = tu.gather_and_enforce_request_args_enumerated([{'required': True}])
         assert 'bad call to gather_and_enforce_request_args: no name supplied' in str(exception_info.value)
Ejemplo n.º 11
0
 def test_gather_and_enforce_request_args_enumerated_passes_error_when_cast_fails(self):
     with current_app.test_request_context('/whatever?yoo=hoo'):
         with pytest.raises(ValueError) as exception_info:
             fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'yoo', 'cast_function': int}])
         assert 'problem casting parameter yoo (value hoo) as type int' in str(exception_info.value)
Ejemplo n.º 12
0
 def test_gather_and_enforce_request_args_enumerated_gets_nothing_when_parm_optional_and_absent_and_no_default(self):
     with current_app.test_request_context('/whatever'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'vanilla'}])
         assert fetched_value == {}
Ejemplo n.º 13
0
 def test_gather_and_enforce_request_args_enumerated_gets_default_when_parm_optional_and_absent_and_default(self):
     with current_app.test_request_context('/whatever'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'hammer', 'default': 'dont_hurt_em'}])
         assert fetched_value == {'hammer': 'dont_hurt_em'}
Ejemplo n.º 14
0
 def test_gather_and_enforce_request_args_enumerated_gets_parm_when_parm_optional_and_present(self):
     with current_app.test_request_context('/whatever?party=started'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'party'}])
         assert fetched_value == {'party': 'started'}
Ejemplo n.º 15
0
 def test_gather_and_enforce_request_args_enumerated_gets_parm_when_parm_required_and_present(self):
     with current_app.test_request_context('/whatever?c=d'):
         fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'c', 'required': True}])
         assert fetched_value == {'c': 'd'}
Ejemplo n.º 16
0
 def test_gather_and_enforce_request_args_enumerated_throws_dce_when_parm_required_and_absent(self):
     with current_app.test_request_context('/whatever?yoo=hoo'):
         with pytest.raises(DocumentConfigurationError) as exception_info:
             fetched_value = tu.gather_and_enforce_request_args_enumerated([{'name': 'a', 'required': True}])
         assert 'required parameter a not supplied in request' in str(exception_info.value)