def test_uses_json_decoder(schema_builder, json_spec):
    """ParameterBuilder should uses JSONDecoder for parameters with media application/json."""
    builder = ExtractorBuilder(schema_builder)
    extractor = builder.build_param_extractor(json_spec)
    assert isinstance(extractor.decoder, JSONDecoder)
    extractor = builder.build_body_extractor({'content': json_spec['content']})
    assert isinstance(extractor.decoder, JSONDecoder)
def test_unsupported_content_type(schema_builder):
    """ParamBuilder should raise UnsupportedContentTypeError if content type is unknown."""
    builder = ExtractorBuilder(schema_builder)
    spec = {'content': {'application/unknown': {'schema': {'type': 'number'}}}}
    with pytest.raises(UnsupportedContentTypeError,
                       match='application/unknown'):
        builder.build_body_extractor(spec)
    spec['in'] = 'path'
    spec['name'] = 'id'
    with pytest.raises(UnsupportedContentTypeError,
                       match='application/unknown'):
        builder.build_param_extractor(spec)
Example #3
0
def _extractor_factory(mocker):
    """Fixture providing ExtractorBuilder mock."""
    return mocker.Mock(wraps=ExtractorBuilder(SchemaBuilder.create()))
def test_uses_plain_decoder(schema_builder, simple_spec):
    """ParameterBuilder should use PlainDecoder for parameters defined without content keyword."""
    builder = ExtractorBuilder(schema_builder)
    extractor = builder.build_param_extractor(simple_spec)
    assert isinstance(extractor.decoder,
                      PlainDecoder), 'Should use PlainDecoder but does not.'
def _extractor_factory(schema_builder):
    """Fixture providing an instance of ExtractorBuilder."""
    return ExtractorBuilder(schema_builder)
def test_body_extractor_reader(schema_builder, json_spec):
    """Extractorbuilder should build extractors equiped with correct reader."""
    builder = ExtractorBuilder(schema_builder)
    extractor = builder.build_body_extractor({'content': json_spec['content']})
    assert extractor.read_data == read_body
def test_extractor_types(schema_builder, simple_spec):
    """ParamBuilder should base type of constructed extractor on 'in' parameter."""
    builder = ExtractorBuilder(schema_builder)
    extractor = builder.build_param_extractor(simple_spec)
    assert extractor.read_data.func == EXPECTED_READERS[simple_spec['in']]