Commit 1ac3ec59 authored by Thomas Gambier's avatar Thomas Gambier

util: fix getSerialisation when some software_type has different serialisation

parent a9ed7398
Pipeline #22384 failed with stage
in 0 seconds
...@@ -246,10 +246,12 @@ class TestUtil(unittest.TestCase): ...@@ -246,10 +246,12 @@ class TestUtil(unittest.TestCase):
class SoftwareReleaseSchemaTestXmlSerialisationMixin: class SoftwareReleaseSchemaTestXmlSerialisationMixin:
serialisation = SoftwareReleaseSerialisation.Xml serialisation = SoftwareReleaseSerialisation.Xml
serialisation_alt = SoftwareReleaseSerialisation.JsonInXml
class SoftwareReleaseSchemaTestJsonInXmlSerialisationMixin: class SoftwareReleaseSchemaTestJsonInXmlSerialisationMixin:
serialisation = SoftwareReleaseSerialisation.JsonInXml serialisation = SoftwareReleaseSerialisation.JsonInXml
serialisation_alt = SoftwareReleaseSerialisation.Xml
class SoftwareReleaseSchemaTestMixin(object): class SoftwareReleaseSchemaTestMixin(object):
...@@ -257,6 +259,7 @@ class SoftwareReleaseSchemaTestMixin(object): ...@@ -257,6 +259,7 @@ class SoftwareReleaseSchemaTestMixin(object):
""" """
software_url = None # type: str software_url = None # type: str
serialisation = None # type: SoftwareReleaseSerialisation serialisation = None # type: SoftwareReleaseSerialisation
serialisation_alt = None # type: SoftwareReleaseSerialisation
def test_software_schema(self): def test_software_schema(self):
...@@ -269,6 +272,10 @@ class SoftwareReleaseSchemaTestMixin(object): ...@@ -269,6 +272,10 @@ class SoftwareReleaseSchemaTestMixin(object):
schema = SoftwareReleaseSchema(self.software_url, None) schema = SoftwareReleaseSchema(self.software_url, None)
self.assertEqual(schema.getSerialisation(), self.serialisation) self.assertEqual(schema.getSerialisation(), self.serialisation)
def test_serialisation_alternate_software_type(self):
schema = SoftwareReleaseSchema(self.software_url, 'alternate')
self.assertEqual(schema.getSerialisation(), self.serialisation_alt)
def test_instance_request_parameter_schema_default_software_type(self): def test_instance_request_parameter_schema_default_software_type(self):
schema = SoftwareReleaseSchema(self.software_url, None) schema = SoftwareReleaseSchema(self.software_url, None)
self.assertTrue(schema.getInstanceRequestParameterSchemaURL()) self.assertTrue(schema.getInstanceRequestParameterSchemaURL())
...@@ -307,7 +314,7 @@ class SoftwareReleaseSchemaTestMixin(object): ...@@ -307,7 +314,7 @@ class SoftwareReleaseSchemaTestMixin(object):
instance_ok = {'key': 'value', 'type': 'alternate'} instance_ok = {'key': 'value', 'type': 'alternate'}
schema.validateInstanceParameterDict(instance_ok) schema.validateInstanceParameterDict(instance_ok)
if self.serialisation == SoftwareReleaseSerialisation.JsonInXml: if self.serialisation_alt == SoftwareReleaseSerialisation.JsonInXml:
# already serialized values are also tolerated # already serialized values are also tolerated
schema.validateInstanceParameterDict({'_': json.dumps(instance_ok)}) schema.validateInstanceParameterDict({'_': json.dumps(instance_ok)})
...@@ -357,6 +364,7 @@ class SoftwareReleaseSchemaTestFileSoftwareReleaseMixin(SoftwareReleaseSchemaTes ...@@ -357,6 +364,7 @@ class SoftwareReleaseSchemaTestFileSoftwareReleaseMixin(SoftwareReleaseSchemaTes
"alternate": { "alternate": {
"title": "Alternate", "title": "Alternate",
"description": "Alternate type", "description": "Alternate type",
"serialisation": self.serialisation_alt,
"request": "instance-alternate-input-schema.json", "request": "instance-alternate-input-schema.json",
"response": "instance-alternate-output-schema.json", "response": "instance-alternate-output-schema.json",
"index": 0 "index": 0
......
...@@ -396,6 +396,8 @@ class SoftwareReleaseSchema(object): ...@@ -396,6 +396,8 @@ class SoftwareReleaseSchema(object):
# type: () -> Optional[SoftwareReleaseSerialisation] # type: () -> Optional[SoftwareReleaseSerialisation]
"""Returns the serialisation method used for parameters. """Returns the serialisation method used for parameters.
""" """
software_schema = self.getSoftwareTypeSchema()
if software_schema is None or 'serialisation' not in software_schema:
software_schema = self.getSoftwareSchema() software_schema = self.getSoftwareSchema()
if software_schema is None: if software_schema is None:
return None return None
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment