コード例 #1
0
 def testEnumTest(self):
     """Test EnumTest"""
     # inline array of enums
     model = EnumTest(enum_string_required='lower',
                      inline_array_of_str_enum=[StringEnum('approved')])
     # refed array of enums
     model = EnumTest(enum_string_required='lower',
                      array_of_str_enum=ArrayOfEnums(
                          [StringEnum('approved')]))
コード例 #2
0
    def test_enum_test(self):
        """Test case for enum_test

        Object contains enum properties and array properties containing enums
        """
        from petstore_api.model.enum_test import EnumTest
        from petstore_api.model.string_enum import StringEnum
        from petstore_api.model.array_of_enums import ArrayOfEnums

        endpoint = self.api.enum_test_endpoint
        assert endpoint.openapi_types['enum_test'] == (EnumTest, )
        assert endpoint.settings['response_type'] == (EnumTest, )

        # serialization + deserialization works w/ inline array
        with patch.object(RESTClientObject, 'request') as mock_method:
            body = EnumTest(enum_string_required='lower',
                            inline_array_of_str_enum=[StringEnum('approved')])
            json_value = {
                'enum_string_required': 'lower',
                'InlineArrayOfStrEnum': ['approved']
            }
            mock_method.return_value = self.mock_response(json_value)

            response = self.api.enum_test(enum_test=body)
            self.assert_request_called_with(
                mock_method,
                'http://petstore.swagger.io:80/v2/fake/refs/enum-test',
                body=json_value,
            )

            assert isinstance(response, EnumTest)
            assert response == body

        # serialization + deserialization works w/ refed array
        with patch.object(RESTClientObject, 'request') as mock_method:
            body = EnumTest(enum_string_required='lower',
                            array_of_str_enum=ArrayOfEnums(
                                [StringEnum('approved')]))
            json_value = {
                'enum_string_required': 'lower',
                'ArrayOfStrEnum': ['approved']
            }
            mock_method.return_value = self.mock_response(json_value)

            response = self.api.enum_test(enum_test=body)
            self.assert_request_called_with(
                mock_method,
                'http://petstore.swagger.io:80/v2/fake/refs/enum-test',
                body=json_value,
            )

            assert isinstance(response, EnumTest)
            assert response == body
コード例 #3
0
 def test_array_of_enums(self):
     from petstore_api.model.array_of_enums import ArrayOfEnums
     from petstore_api.api.fake_api_endpoints.array_of_enums import _response_for_200
     from petstore_api.model import string_enum
     data = ["placed", None]
     response = self.__response(data)
     deserialized = _response_for_200.deserialize(response,
                                                  self.configuration)
     assert isinstance(deserialized.body, ArrayOfEnums)
     expected_results = ArrayOfEnums(
         [string_enum.StringEnum(v) for v in data])
     assert expected_results == deserialized.body
コード例 #4
0
    def testEnumTest(self):
        """Test EnumTest"""
        required_kwargs = dict(enum_string_required='lower')

        # inline array of enums
        model = EnumTest(inline_array_of_str_enum=[StringEnum('approved')],
                         **required_kwargs)
        # refed array of enums
        model = EnumTest(array_of_str_enum=ArrayOfEnums(
            [StringEnum('approved')]),
                         **required_kwargs)

        # inline bool enum
        model = EnumTest(enum_bool=False, **required_kwargs)
        # refed bool enum
        model = EnumTest(bool_enum=BooleanEnum(True), **required_kwargs)