@@ -32,11 +32,12 @@ async def test_MediaType(httpx_mock, with_schema_itemSchema):
3232 import pydantic
3333
3434 api = OpenAPI ("https://example.org/api/" , with_schema_itemSchema , session_factory = httpx .AsyncClient )
35- ServerSentEvent : pydantic .BaseModel = api .components .schemas ["ServerSentEvent" ].get_type ()
3635
3736 records = with_schema_itemSchema ["components" ]["examples" ]["LogJSONPerLine" ]["value" ].strip ("\n " ).split ("\n " )
37+
38+ ServerSentEvent : pydantic .BaseModel = api .components .schemas ["ServerSentEvent" ].get_type ()
3839 t = pydantic .TypeAdapter (list [ServerSentEvent ])
39- ct = "\n \n " .join (f"data: { i } " for i in records * 16 )
40+ ct = "\n \n " .join (f"data: { i } \n : { idx } " for idx , i in enumerate ( records * 16 ) )
4041
4142 httpx_mock .add_response (
4243 url = "https://example.org/api/json_seq" ,
@@ -95,15 +96,46 @@ def test_MediaType_itemSchema_sync(httpx_mock, with_schema_itemSchema):
9596
9697 records = with_schema_itemSchema ["components" ]["examples" ]["LogJSONPerLine" ]["value" ].strip ("\n " ).split ("\n " )
9798
99+ ServerSentEvent : pydantic .BaseModel = api .components .schemas ["ServerSentEvent" ].get_type ()
100+ t = pydantic .TypeAdapter (list [ServerSentEvent ])
101+ ct = "\n \n " .join (f"data: { i } \n : { idx } " for idx , i in enumerate (records * 16 ))
102+
98103 httpx_mock .add_response (
99104 url = "https://example.org/api/json_seq" ,
100105 headers = {"Content-Type" : "application/json-seq" },
101106 stream = IteratorStream ([b"\x1e " + i .encode () + b"\n " for i in (records * 16 )]),
102107 )
108+ httpx_mock .add_response (
109+ url = "https://example.org/api/jsonl" ,
110+ headers = {"Content-Type" : "application/jsonl" },
111+ stream = IteratorStream ([i .encode () + b"\n " for i in (records * 16 )]),
112+ )
113+ httpx_mock .add_response (
114+ url = "https://example.org/api/ndjson" ,
115+ headers = {"Content-Type" : "application/x-ndjson" },
116+ stream = IteratorStream ([i .encode () + b"\n " for i in (records * 16 )]),
117+ )
118+ httpx_mock .add_response (
119+ url = "https://example.org/api/text_events" , headers = {"Content-Type" : "text/event-stream" }, content = ct
120+ )
103121
104122 req = api .createRequest ("json_seq" )
105123 with req .sequence () as sequence :
106- print (sequence .headers )
124+ for obj in sequence :
125+ print (obj )
126+
127+ req = api .createRequest ("jsonl" )
128+ with req .sequence () as sequence :
129+ for obj in sequence :
130+ print (obj )
131+
132+ req = api .createRequest ("ndjson" )
133+ with req .sequence () as sequence :
134+ for obj in sequence :
135+ print (obj )
136+
137+ req = api .createRequest ("text_events" )
138+ with req .sequence () as sequence :
107139 for obj in sequence :
108140 print (obj )
109141
0 commit comments