|
| 1 | +import pytest |
| 2 | +from io import BytesIO |
| 3 | +from kiota_abstractions.request_information import RequestInformation |
| 4 | +from msgraph_core.requests.batch_request_item import BatchRequestItem |
| 5 | +from msgraph_core.requests.batch_request_content_collection import BatchRequestContentCollection |
| 6 | +from kiota_abstractions.headers_collection import HeadersCollection as RequestHeaders |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def batch_request_content_collection(): |
| 11 | + return BatchRequestContentCollection() |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture |
| 15 | +def request_info(): |
| 16 | + request_info = RequestInformation() |
| 17 | + request_info.http_method = "GET" |
| 18 | + request_info.url = "https://graph.microsoft.com/v1.0/me" |
| 19 | + request_info.headers = RequestHeaders() |
| 20 | + request_info.headers.add("Content-Type", "application/json") |
| 21 | + request_info.content = BytesIO(b'{"key": "value"}') |
| 22 | + return request_info |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture |
| 26 | +def batch_request_item1(request_info): |
| 27 | + return BatchRequestItem(request_information=request_info, id="1") |
| 28 | + |
| 29 | + |
| 30 | +@pytest.fixture |
| 31 | +def batch_request_item2(request_info): |
| 32 | + return BatchRequestItem(request_information=request_info, id="2") |
| 33 | + |
| 34 | + |
| 35 | +def test_init_batches(batch_request_content_collection): |
| 36 | + assert len(batch_request_content_collection.batches) == 1 |
| 37 | + assert batch_request_content_collection.current_batch is not None |
| 38 | + |
| 39 | + |
| 40 | +def test_add_batch_request_item(batch_request_content_collection, batch_request_item1, batch_request_item2): |
| 41 | + batch_request_content_collection.add_batch_request_item(batch_request_item1) |
| 42 | + batch_request_content_collection.add_batch_request_item(batch_request_item2) |
| 43 | + assert len(batch_request_content_collection.batches) == 1 |
| 44 | + assert len(batch_request_content_collection.current_batch.requests) == 2 |
0 commit comments