mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-21 19:07:08 +00:00
Adding decimal support for python client generation (#19203)
* Adding decimal to template for Python generator * Rerunning the build steps * Add tests for decimal serialization and deserialization. * Move test to python not legacy pydantic sample * readd old imports --------- Co-authored-by: Adam <abolfik@pollyex.com>
This commit is contained in:
@@ -10,6 +10,7 @@ $ pytest
|
||||
"""
|
||||
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
from enum import Enum
|
||||
|
||||
from dateutil.parser import parse
|
||||
@@ -180,6 +181,11 @@ class ApiClientTests(unittest.TestCase):
|
||||
result = self.api_client.sanitize_for_serialization(data)
|
||||
self.assertEqual(result, "1997-07-16T19:20:30.450000+01:00")
|
||||
|
||||
def test_sanitize_for_serialization_decimal(self):
|
||||
data = Decimal("1.0")
|
||||
result = self.api_client.sanitize_for_serialization(data)
|
||||
self.assertEquals(result, "1.0")
|
||||
|
||||
def test_sanitize_for_serialization_list_enum(self):
|
||||
class EnumSerialization(int, Enum):
|
||||
NUMBER_0 = 0
|
||||
|
||||
@@ -14,6 +14,7 @@ import os
|
||||
import time
|
||||
import unittest
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest as pytest
|
||||
|
||||
@@ -130,6 +131,15 @@ class DeserializationTests(unittest.TestCase):
|
||||
deserialized = self.deserialize(response, "datetime", 'application/json')
|
||||
self.assertTrue(isinstance(deserialized, datetime.datetime))
|
||||
|
||||
def test_deserialize_decimal(self):
|
||||
""" deserialize decimal """
|
||||
data = 1.1
|
||||
response = json.dumps(data)
|
||||
|
||||
deserialized = self.deserialize(response, "decimal", 'application/json')
|
||||
self.assertTrue(isinstance(deserialized, Decimal))
|
||||
self.assertEqual(deserialized, Decimal(1.1))
|
||||
|
||||
def test_deserialize_pet(self):
|
||||
""" deserialize pet """
|
||||
data = {
|
||||
|
||||
Reference in New Issue
Block a user