Skip to content

Commit

Permalink
Updated the code coverage
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 committed Jul 20, 2018
1 parent ee07865 commit d702997
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
15 changes: 0 additions & 15 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 Down Expand Up @@ -233,18 +230,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 d702997

Please sign in to comment.