示例#1
0
    def testObjectModelWithRefProps(self):
        """Test ObjectModelWithRefProps"""
        self.assertEqual(ObjectModelWithRefProps.myNumber,
                         NumberWithValidations)

        inst = ObjectModelWithRefProps(myNumber=15.0,
                                       myString="a",
                                       myBoolean=True)
        assert isinstance(inst, ObjectModelWithRefProps)
        assert isinstance(inst, frozendict)
        assert set(inst.keys()) == {"myNumber", "myString", "myBoolean"}
        assert inst.myNumber == 15.0
        assert isinstance(inst.myNumber, NumberWithValidations)
        assert inst.myString == 'a'
        assert isinstance(inst.myString, ObjectModelWithRefProps.myString)
        assert bool(inst.myBoolean) is True
        assert isinstance(inst.myBoolean, ObjectModelWithRefProps.myBoolean)
        assert isinstance(inst.myBoolean, BoolClass)
    def test_object_model_with_ref_props(self):
        """Test case for object_model_with_ref_props

        """
        from petstore_api.model.object_model_with_ref_props import ObjectModelWithRefProps
        from petstore_api.model.number_with_validations import NumberWithValidations
        endpoint = self.api.object_model_with_ref_props_endpoint
        assert endpoint.openapi_types['body'] == (ObjectModelWithRefProps, )
        assert endpoint.settings['response_type'] == (
            ObjectModelWithRefProps, )

        json_payloads = [
            {},  # only required + no optional properties works
            {  # optional properties works
                "my_number": 11.0,
                "my_string": 'a',
                "my_boolean": True,
            }
        ]
        # instantiation works
        expected_models = [
            ObjectModelWithRefProps(),
            ObjectModelWithRefProps(my_number=NumberWithValidations(11.0),
                                    my_string='a',
                                    my_boolean=True)
        ]

        pairs = zip(json_payloads, expected_models)
        # serialization + deserialization works
        for (json_payload, expected_model) in pairs:
            with patch.object(RESTClientObject, 'request') as mock_method:
                mock_method.return_value = self.mock_response(json_payload)

                response = self.api.object_model_with_ref_props(
                    body=expected_model)
                self.assert_request_called_with(
                    mock_method,
                    'http://petstore.swagger.io:80/v2/fake/refs/object_model_with_ref_props',
                    body=json_payload,
                )

                assert isinstance(response, expected_model.__class__)
                assert response == expected_model