Skip to content

Commit c615fc7

Browse files
[DAPS-1857-2] python client schema support (#1895)
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
1 parent 1dae067 commit c615fc7

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

core/database/foxx/api/schema_router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function parseSchemaId(schId) {
5858
}
5959

6060
if (colonCount === 0) {
61-
return { id: schId, ver: 0 };
61+
return { id: schId, ver: null };
6262
}
6363

6464
const idx = schId.indexOf(":");

tests/end-to-end/test_api_schema.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def test_schema_create_missing_definition(self):
124124
"""Must provide either definition or definition_file."""
125125

126126
with self.assertRaises(Exception) as ctx:
127-
self._df_api.schemaCreate("test_no_def",
128-
description="test bad schema"
129-
)
130-
127+
self._df_api.schemaCreate(
128+
"test_no_def",
129+
description="test bad schema"
130+
)
131131
self.assertIn("Must specify", str(ctx.exception))
132132

133133
def test_schema_create_both_definition_sources(self):
@@ -138,7 +138,30 @@ def test_schema_create_both_definition_sources(self):
138138
"test_both_def",
139139
definition='{"type": "object", "properties": {}}',
140140
definition_file="/tmp/fake.json",
141-
description="test bad schema"
141+
)
142+
143+
self.assertIn("Cannot specify both", str(ctx.exception))
144+
145+
def test_schema_update_both_definition_sources(self):
146+
"""Cannot specify both definition and definition_file for schemaUpdate."""
147+
148+
with self.assertRaises(Exception) as ctx:
149+
self._df_api.schemaUpdate(
150+
"test_update_both_def",
151+
definition='{"type": "object", "properties": {}}',
152+
definition_file="/tmp/fake.json",
153+
)
154+
155+
self.assertIn("Cannot specify both", str(ctx.exception))
156+
157+
def test_schema_revise_both_definition_sources(self):
158+
"""Cannot specify both definition and definition_file for schemaRevise."""
159+
160+
with self.assertRaises(Exception) as ctx:
161+
self._df_api.schemaRevise(
162+
"test_revise_both_def",
163+
definition='{"type": "object", "properties": {}}',
164+
definition_file="/tmp/fake.json",
142165
)
143166

144167
self.assertIn("Cannot specify both", str(ctx.exception))
@@ -383,6 +406,18 @@ def test_metadata_validate_requires_input(self):
383406

384407
self.assertIn("Must specify", str(ctx.exception))
385408

409+
def test_metadata_validate_metadata_file_cannot_be_opened(self):
410+
"""metadata_file set but file cannot be opened should raise expected error."""
411+
412+
bad_path = "/path/does/not/exist"
413+
414+
with self.assertRaises(Exception) as ctx:
415+
self._df_api.metadataValidate("any_schema", metadata_file=bad_path)
416+
417+
# The client should surface a clear file-open error that includes the path.
418+
self.assertIn("Could not open metadata file:", str(ctx.exception))
419+
self.assertIn(bad_path, str(ctx.exception))
420+
386421
def test_schema_create_from_file(self):
387422
"""Test creating a schema from a definition file."""
388423

@@ -432,6 +467,7 @@ def tearDown(self):
432467
suite.addTest(TestDataFedPythonAPISchemaCRUD("test_metadata_validate_client_rejects_bad_json"))
433468
suite.addTest(TestDataFedPythonAPISchemaCRUD("test_metadata_validate_requires_input"))
434469
suite.addTest(TestDataFedPythonAPISchemaCRUD("test_schema_create_from_file"))
470+
suite.addTest(TestDataFedPythonAPISchemaCRUD("test_metadata_validate_metadata_file_cannot_be_opened"))
435471
runner = unittest.TextTestRunner()
436472
result = runner.run(suite)
437473
sys.exit(not result.wasSuccessful())

0 commit comments

Comments
 (0)