|
1 | 1 | # pylint: disable=invalid-name, redefined-outer-name, unused-import, missing-module-docstring, missing-class-docstring |
2 | 2 |
|
| 3 | +from pydantic import Field |
| 4 | + |
| 5 | +from pyneo4j_ogm.core.node import NodeModel |
| 6 | +from pyneo4j_ogm.fields.property_options import WithOptions |
3 | 7 | from pyneo4j_ogm.pydantic_utils import IS_PYDANTIC_V2, get_schema |
4 | 8 | from tests.fixtures.db_setup import Coffee, Consumed, Developer |
5 | 9 | from tests.utils.string_utils import assert_string_equality |
@@ -124,3 +128,25 @@ def test_schema(): |
124 | 128 | schema["definitions"]["Developer"]["properties"]["colleagues"]["properties"]["allow_multiple"]["type"] |
125 | 129 | == "boolean" |
126 | 130 | ) |
| 131 | + |
| 132 | + |
| 133 | +def test_schema_with_index_and_constraint(): |
| 134 | + class TestModel(NodeModel): |
| 135 | + uid: WithOptions(str, text_index=True, unique=True) = Field("test-uid") # type: ignore |
| 136 | + |
| 137 | + setattr(TestModel, "_client", None) |
| 138 | + |
| 139 | + schema = get_schema(TestModel) |
| 140 | + |
| 141 | + if IS_PYDANTIC_V2: |
| 142 | + assert "text_index" in schema["properties"]["uid"] |
| 143 | + assert schema["properties"]["uid"]["text_index"] |
| 144 | + |
| 145 | + assert "uniqueness_constraint" in schema["properties"]["uid"] |
| 146 | + assert schema["properties"]["uid"]["uniqueness_constraint"] |
| 147 | + else: |
| 148 | + assert "text_index" in schema["properties"]["uid"] |
| 149 | + assert schema["properties"]["uid"]["text_index"] |
| 150 | + |
| 151 | + assert "uniqueness_constraint" in schema["properties"]["uid"] |
| 152 | + assert schema["properties"]["uid"]["uniqueness_constraint"] |
0 commit comments