|
3 | 3 | import pytest |
4 | 4 |
|
5 | 5 | from weaviate.collections.batch.grpc_batch import _validate_props |
6 | | -from weaviate.collections.classes.batch import MAX_STORED_RESULTS, BatchObjectReturn |
| 6 | +from weaviate.collections.classes.batch import MAX_STORED_RESULTS, BatchObjectReturn, BatchReference |
7 | 7 | from weaviate.exceptions import WeaviateInsertInvalidPropertyError |
| 8 | +from weaviate.types import BEACON |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def test_batch_object_return_add() -> None: |
@@ -53,3 +54,30 @@ def test_validate_props_raises_for_top_level_vector() -> None: |
53 | 54 | def test_validate_props_raises_for_nested_vector() -> None: |
54 | 55 | with pytest.raises(WeaviateInsertInvalidPropertyError): |
55 | 56 | _validate_props({"vector": [0.1, 0.2]}, nested=True) |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.parametrize( |
| 60 | + ("to_object_collection", "expected_to"), |
| 61 | + [ |
| 62 | + (None, f"{BEACON}28f3f61b-b524-45e0-9bbe-2c1550bf73d2"), |
| 63 | + ("Target", f"{BEACON}Target/28f3f61b-b524-45e0-9bbe-2c1550bf73d2"), |
| 64 | + ], |
| 65 | +) |
| 66 | +def test_batch_reference_to_internal_is_idempotent( |
| 67 | + to_object_collection: str | None, expected_to: str |
| 68 | +) -> None: |
| 69 | + ref = BatchReference( |
| 70 | + from_object_collection="Source", |
| 71 | + from_object_uuid="1c9cd584-88fe-5010-83d0-017cb3fcb446", |
| 72 | + from_property_name="link", |
| 73 | + to_object_collection=to_object_collection, |
| 74 | + to_object_uuid="28f3f61b-b524-45e0-9bbe-2c1550bf73d2", |
| 75 | + index=0, |
| 76 | + ) |
| 77 | + |
| 78 | + first = ref._to_internal() |
| 79 | + second = ref._to_internal() |
| 80 | + |
| 81 | + assert ref.to_object_collection == to_object_collection |
| 82 | + assert first.to == expected_to |
| 83 | + assert second.to == expected_to |
0 commit comments