|
7 | 7 | from kiota_abstractions.serialization.serialization_writer import SerializationWriter |
8 | 8 | from kiota_abstractions.method import Method |
9 | 9 | from kiota_abstractions.headers_collection import HeadersCollection as RequestHeaders |
| 10 | +from kiota_serialization_json.json_serialization_writer_factory import JsonSerializationWriterFactory |
10 | 11 | from msgraph_core.requests.batch_request_item import BatchRequestItem |
11 | 12 |
|
12 | 13 | base_url = "https://graph.microsoft.com/v1.0/me" |
13 | 14 |
|
14 | 15 |
|
15 | 16 | @pytest.fixture |
16 | 17 | def request_info(): |
17 | | - request_info = RequestInformation() |
| 18 | + request_info = RequestInformation() |
18 | 19 | request_info.http_method = "GET" |
19 | | - request_info.url = "f{base_url}/me" |
| 20 | + request_info.url = base_url |
20 | 21 | request_info.headers = RequestHeaders() |
| 22 | + request_info.headers.add("Content-Type", "application/json") |
21 | 23 | request_info.content = b'{"key": "value"}' |
22 | 24 | return request_info |
23 | 25 |
|
24 | 26 |
|
25 | 27 | @pytest.fixture |
26 | 28 | def batch_request_item(request_info): |
27 | | - return BatchRequestItem(request_information=request_info) |
| 29 | + return BatchRequestItem(request_information=request_info, id="123") |
28 | 30 |
|
29 | 31 |
|
30 | 32 | def test_initialization(batch_request_item, request_info): |
| 33 | + assert batch_request_item.id == "123" |
31 | 34 | assert batch_request_item.method == "GET" |
32 | | - assert batch_request_item.url == "f{base_url}/me" |
| 35 | + assert batch_request_item.url == base_url |
| 36 | + assert batch_request_item.headers == {"content-type": "application/json"} |
33 | 37 | assert batch_request_item.body == b'{"key": "value"}' |
34 | 38 |
|
35 | 39 |
|
@@ -128,9 +132,13 @@ def test_depends_on_property(batch_request_item): |
128 | 132 | assert batch_request_item.depends_on == ["request1", "request2"] |
129 | 133 |
|
130 | 134 |
|
131 | | -def test_serialize(batch_request_item): |
132 | | - writer = Mock(spec=SerializationWriter) |
| 135 | +def test_serialize_json(batch_request_item): |
| 136 | + writer = JsonSerializationWriterFactory().get_serialization_writer('application/json') |
133 | 137 | batch_request_item.serialize(writer) |
134 | | - writer.write_additional_data_value.assert_any_call({'headers': batch_request_item._headers}) |
135 | | - json_object = json.loads(batch_request_item._body) |
136 | | - writer.write_additional_data_value.assert_called_with({'body': json_object}) |
| 138 | + content = json.loads(writer.get_serialized_content()) |
| 139 | + assert content["id"] == "123" |
| 140 | + assert content["method"] == "GET" |
| 141 | + assert content["url"] == base_url |
| 142 | + assert content["headers"] == {"content-type": "application/json"} |
| 143 | + assert content["body"] == {"key": "value"} |
| 144 | + |
0 commit comments