|
1 | 1 | import http |
| 2 | +import json |
| 3 | +import warnings |
2 | 4 | from collections.abc import AsyncGenerator |
3 | 5 |
|
4 | 6 | import httpx |
@@ -38,6 +40,56 @@ async def test_retrieve_success(typename: str, test_thing_id: str, bubble_raw_cl |
38 | 40 | assert response_body["response"]["text"] == "integration test" |
39 | 41 |
|
40 | 42 |
|
| 43 | +async def test_bulk_create_success(typename: str, bubble_raw_client: raw_client.RawClient): |
| 44 | + """Test that bulk_create creates multiple things and returns their IDs.""" |
| 45 | + created_ids: list[str] = [] |
| 46 | + |
| 47 | + try: |
| 48 | + response = await bubble_raw_client.bulk_create( |
| 49 | + typename=typename, |
| 50 | + data=[{"text": "bulk test 1"}, {"text": "bulk test 2"}], |
| 51 | + ) |
| 52 | + |
| 53 | + # bubble returns text/plain with newline-delimited JSON |
| 54 | + assert response.status_code == http.HTTPStatus.OK |
| 55 | + assert response.headers["content-type"] == "text/plain" |
| 56 | + lines = response.text.strip().split("\n") |
| 57 | + assert len(lines) == 2 |
| 58 | + |
| 59 | + # parse each line and extract IDs for cleanup |
| 60 | + for line in lines: |
| 61 | + result = json.loads(line) |
| 62 | + assert result["status"] == "success" |
| 63 | + assert "id" in result |
| 64 | + created_ids.append(result["id"]) |
| 65 | + |
| 66 | + # verify both items exist with correct data |
| 67 | + expected_texts = ["bulk test 1", "bulk test 2"] |
| 68 | + for uid, expected_text in zip(created_ids, expected_texts, strict=True): |
| 69 | + retrieve_response = await bubble_raw_client.retrieve(typename=typename, uid=uid) |
| 70 | + assert retrieve_response.status_code == http.HTTPStatus.OK |
| 71 | + assert retrieve_response.json()["response"]["text"] == expected_text |
| 72 | + |
| 73 | + finally: |
| 74 | + # cleanup all created items |
| 75 | + for uid in created_ids: |
| 76 | + try: |
| 77 | + await bubble_raw_client.delete(typename=typename, uid=uid) |
| 78 | + except Exception as e: |
| 79 | + warnings.warn(f"cleanup failed for {uid}: {e}", stacklevel=2) |
| 80 | + |
| 81 | + |
| 82 | +async def test_update_success(typename: str, test_thing_id: str, bubble_raw_client: raw_client.RawClient): |
| 83 | + """Test that we can update a thing.""" |
| 84 | + response = await bubble_raw_client.update(typename=typename, uid=test_thing_id, data={"text": "updated text"}) |
| 85 | + # 204 No Content = success |
| 86 | + assert response.status_code == http.HTTPStatus.NO_CONTENT |
| 87 | + |
| 88 | + # verify the update |
| 89 | + response = await bubble_raw_client.retrieve(typename=typename, uid=test_thing_id) |
| 90 | + assert response.json()["response"]["text"] == "updated text" |
| 91 | + |
| 92 | + |
41 | 93 | async def test_delete_success(typename: str, bubble_raw_client: raw_client.RawClient): |
42 | 94 | """Test that we can delete a thing.""" |
43 | 95 | response_create = await bubble_raw_client.create(typename, data={"text": "integration test delete success"}) |
|
0 commit comments