Skip to content

Commit

Permalink
testme
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaTP committed Apr 9, 2024
1 parent b2d4971 commit 5112a5a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
50 changes: 25 additions & 25 deletions it/python/discriminator/test_serdeser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,52 @@
from kiota_serialization_json.json_parse_node_factory import JsonParseNodeFactory
from kiota_serialization_json.json_serialization_writer_factory import JsonSerializationWriterFactory

from client.models.object import Object
from client.models.object1 import Object1
from client.models.object2 import Object2
from client.models.component import Component
from client.models.component1 import Component1
from client.models.component2 import Component2

@pytest.mark.asyncio
async def test_object1_deser():
async def test_component1_deser():
factory = JsonParseNodeFactory()
root = factory.get_root_parse_node('application/json', '{"objectType": "obj1", "one": "foo"}'.encode('utf-8'))
result = root.get_object_value(Object)
assert hasattr(result, "object1")
assert not hasattr(result, "object2")
assert isinstance(result.object1, Object1)
assert result.object1.object_type == "obj1"
assert result.object1.one == "foo"
result = root.get_object_value(Component)
assert hasattr(result, "component1")
assert not hasattr(result, "component2")
assert isinstance(result.component1, Component1)
assert result.component1.object_type == "obj1"
assert result.component1.one == "foo"

@pytest.mark.asyncio
async def test_object2_deser():
async def test_component2_deser():
factory = JsonParseNodeFactory()
root = factory.get_root_parse_node('application/json', '{"objectType": "obj2", "two": "bar"}'.encode('utf-8'))
result = root.get_object_value(Object)
assert hasattr(result, "object2")
assert not hasattr(result, "object1")
assert isinstance(result.object2, Object2)
assert result.object2.object_type == "obj2"
assert result.object2.two == "bar"
result = root.get_object_value(Component)
assert hasattr(result, "component2")
assert not hasattr(result, "component1")
assert isinstance(result.component2, Component2)
assert result.component2.object_type == "obj2"
assert result.component2.two == "bar"

@pytest.mark.asyncio
async def test_object1_ser():
obj = Object()
obj1 = Object1()
async def test_component1_ser():
obj = Component()
obj1 = Component1()
obj1.object_type = "obj1"
obj1.one = "foo"
obj.object1 = obj1
obj.component1 = obj1
factory = JsonSerializationWriterFactory()
writer = factory.get_serialization_writer('application/json')
obj.serialize(writer)
content = writer.get_serialized_content().decode('utf-8')
assert content == '{"objectType": "obj1", "one": "foo"}'

@pytest.mark.asyncio
async def test_object2_ser():
obj = Object()
obj2 = Object2()
async def test_component2_ser():
obj = Component()
obj2 = Component2()
obj2.object_type = "obj2"
obj2.two = "bar"
obj.object2 = obj2
obj.component2 = obj2
factory = JsonSerializationWriterFactory()
writer = factory.get_serialization_writer('application/json')
obj.serialize(writer)
Expand Down
2 changes: 0 additions & 2 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,5 @@ six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'

sniffio==1.3.1 ; python_version >= '3.7'

uritemplate==4.1.1 ; python_version >= '3.6'

yarl==1.9.4 ; python_version >= '3.7'

18 changes: 9 additions & 9 deletions tests/Kiota.Builder.IntegrationTests/DiscriminatorSample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Object"
$ref: "#/components/schemas/Component"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Object"
$ref: "#/components/schemas/Component"
components:
schemas:
Object:
Component:
oneOf:
- $ref: "#/components/schemas/Object1"
- $ref: "#/components/schemas/Object2"
- $ref: "#/components/schemas/Component1"
- $ref: "#/components/schemas/Component2"
discriminator:
propertyName: objectType
mapping:
obj1: "#/components/schemas/Object1"
obj2: "#/components/schemas/Object2"
Object1:
obj1: "#/components/schemas/Component1"
obj2: "#/components/schemas/Component2"
Component1:
type: object
required:
- objectType
Expand All @@ -40,7 +40,7 @@ components:
type: string
one:
type: string
Object2:
Component2:
type: object
required:
- objectType
Expand Down

0 comments on commit 5112a5a

Please sign in to comment.