Skip to content

Commit

Permalink
Increase the code coverage (#631)
Browse files Browse the repository at this point in the history
removed the validate_defaults method from Operation because the new swagger_spec_validation version do this validation
    added tests for AbstractApi._handle_add_operation_error
  • Loading branch information
dutradda authored and hjacobs committed Jul 21, 2018
1 parent ee07865 commit e326711
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
18 changes: 1 addition & 17 deletions connexion/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
import logging
from copy import deepcopy

from jsonschema import ValidationError

from .decorators import validation
from .decorators.decorator import (BeginOfRequestLifecycleDecorator,
EndOfRequestLifecycleDecorator)
from .decorators.metrics import UWSGIMetricsCollector
Expand All @@ -15,8 +12,7 @@
security_passthrough, verify_oauth_local,
verify_oauth_remote)
from .decorators.uri_parsing import AlwaysMultiURIParser
from .decorators.validation import (ParameterValidator, RequestBodyValidator,
TypeValidationError)
from .decorators.validation import ParameterValidator, RequestBodyValidator
from .exceptions import InvalidSpecification
from .utils import all_json, is_nullable

Expand Down Expand Up @@ -233,18 +229,6 @@ def __init__(self, api, method, path, operation, resolver, app_produces, app_con
self.operation_id = resolution.operation_id
self.__undecorated_function = resolution.function

self.validate_defaults()

def validate_defaults(self):
for param in self.parameters:
try:
if param['in'] == 'query' and 'default' in param:
validation.validate_type(param, param['default'], 'query', param['name'])
except (TypeValidationError, ValidationError):
raise InvalidSpecification('The parameter \'{param_name}\' has a default value which is not of'
' type \'{param_type}\''.format(param_name=param['name'],
param_type=param['type']))

def resolve_reference(self, schema):
schema = deepcopy(schema) # avoid changing the original schema
self.check_references(schema)
Expand Down
18 changes: 18 additions & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yaml
from swagger_spec_validator.common import SwaggerValidationError

import mock
import pytest
from conftest import TEST_FOLDER, build_app_from_fixture
from connexion import App
Expand Down Expand Up @@ -187,3 +188,20 @@ def test_default_query_param_does_not_match_defined_type(
default_param_error_spec_dir):
with pytest.raises(SwaggerValidationError):
build_app_from_fixture(default_param_error_spec_dir, validate_responses=True, debug=False)


def test_handle_add_operation_error_debug(simple_api_spec_dir):
app = App(__name__, specification_dir=simple_api_spec_dir, debug=True)
app.api_cls = type('AppTest', (app.api_cls,), {})
app.api_cls.add_operation = mock.MagicMock(side_effect=Exception('operation error!'))
api = app.add_api('swagger.yaml', resolver=lambda oid: (lambda foo: 'bar'))
assert app.api_cls.add_operation.called
assert api.resolver.resolve_function_from_operation_id('faux')('bah') == 'bar'


def test_handle_add_operation_error(simple_api_spec_dir):
app = App(__name__, specification_dir=simple_api_spec_dir)
app.api_cls = type('AppTest', (app.api_cls,), {})
app.api_cls.add_operation = mock.MagicMock(side_effect=Exception('operation error!'))
with pytest.raises(Exception):
app.add_api('swagger.yaml', resolver=lambda oid: (lambda foo: 'bar'))

0 comments on commit e326711

Please sign in to comment.