<commit_before>import unittest
import colander

from cornice_swagger.swagger import ResponseHandler, CorniceSwaggerException
from cornice_swagger.converters import convert_schema
from .support import (BodySchema, HeaderSchema, ResponseSchema, response_schemas,
                      DeclarativeSchema, AnotherDeclarativeSchema)


class SchemaResponseConversionTest(unittest.TestCase):

    def setUp(self):
        self.handler = ResponseHandler()

    def test_sanity(self):
        self.handler.from_schema_mapping(response_schemas)

    def test_status_codes(self):
        responses = self.handler.from_schema_mapping(response_schemas)
        self.assertIn('200', responses)
        self.assertIn('404', responses)
        self.assertEquals(responses['200']['description'], 'Return ice cream')
        self.assertEquals(responses['404']['description'], 'Return sadness')

    def test_response_schema(self):
        responses = self.handler.from_schema_mapping(response_schemas)
        self.assertDictEqual(responses['200']['schema'],
                             convert_schema(BodySchema(title='BodySchema')))
        self.assertDictEqual(responses['200']['headers'],
                             {'bar': {'type': 'string'}})

    def test_cornice_location_synonyms(self):

        class ReponseSchema(colander.MappingSchema):
            header = HeaderSchema()

        response_schemas = {'200': ReponseSchema(description='Return gelatto')}
        responses = self.handler.from_schema_mapping(response_schemas)

        self.assertDictEqual(responses['200']['headers'],
                             {'bar': {'type': 'string'}})

    def test_raise_exception_without_description(self):

        response_schemas = {
            '200': ResponseSchema()
        }

        self.assertRaises(CorniceSwaggerException,
                          self.handler.from_schema_mapping, response_schemas)


class RefResponseTest(unittest.TestCase):

    def setUp(self):
        self.handler = ResponseHandler(ref=1)
        self.handler.responses = {}

    def test_from_schema_mapping(self):
        responses = self.handler.from_schema_mapping(response_schemas)
        expected = {
            '200': {'$ref': '#/responses/ResponseSchema'},
            '404': {'$ref': '#/responses/ResponseSchema'}<commit_msg>fix small typo in test<commit_after>import unittest
import colander

from cornice_swagger.swagger import ResponseHandler, CorniceSwaggerException
from cornice_swagger.converters import convert_schema
from .support import (BodySchema, HeaderSchema, ResponseSchema, response_schemas,
                      DeclarativeSchema, AnotherDeclarativeSchema)


class SchemaResponseConversionTest(unittest.TestCase):

    def setUp(self):
        self.handler = ResponseHandler()

    def test_sanity(self):
        self.handler.from_schema_mapping(response_schemas)

    def test_status_codes(self):
        responses = self.handler.from_schema_mapping(response_schemas)
        self.assertIn('200', responses)
        self.assertIn('404', responses)
        self.assertEquals(responses['200']['description'], 'Return ice cream')
        self.assertEquals(responses['404']['description'], 'Return sadness')

    def test_response_schema(self):
        responses = self.handler.from_schema_mapping(response_schemas)
        self.assertDictEqual(responses['200']['schema'],
                             convert_schema(BodySchema(title='BodySchema')))
        self.assertDictEqual(responses['200']['headers'],
                             {'bar': {'type': 'string'}})

    def test_cornice_location_synonyms(self):

        class ResponseSchema(colander.MappingSchema):
            header = HeaderSchema()

        response_schemas = {'200': ResponseSchema(description='Return gelatto')}
        responses = self.handler.from_schema_mapping(response_schemas)

        self.assertDictEqual(responses['200']['headers'],
                             {'bar': {'type': 'string'}})

    def test_raise_exception_without_description(self):

        response_schemas = {
            '200': ResponseSchema()
        }

        self.assertRaises(CorniceSwaggerException,
                          self.handler.from_schema_mapping, response_schemas)


class RefResponseTest(unittest.TestCase):

    def setUp(self):
        self.handler = ResponseHandler(ref=1)
        self.handler.responses = {}

    def test_from_schema_mapping(self):
        responses = self.handler.from_schema_mapping(response_schemas)
        expected = {
            '200': {'$ref': '#/responses/ResponseSchema'},
            '404': {'$ref': '#/responses/ResponseSchema'}
{'fraction_non_alphanumeric': 0.11003236245954692, 'fraction_numerical': 0.014670981661272923, 'mean_word_length': 3.218380345768881, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805977', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1195, 'n_words': 199}