11# -*- coding: utf-8 -*-
2+ import warnings
23from datetime import datetime , timezone
3- from typing import List , Optional
4+ from typing import Callable , List , Optional
45
56import pytest # type: ignore
67import responses
@@ -84,6 +85,21 @@ def test_tables(create_table):
8485 return ids
8586
8687
88+ @pytest .fixture (scope = "class" )
89+ def supports_test_result_id (client : DataFrameClient ) -> bool :
90+ """Fixture to determine if the server supports test result IDs."""
91+ api_info = client .api_info ()
92+ result = api_info .operations .create_tables .version >= 2
93+ if not result :
94+ warnings .warn (
95+ (
96+ "The selected version of the DataFrame Service does not support test "
97+ "result IDs. Tests will not attempt to set a test result ID."
98+ )
99+ )
100+ return result
101+
102+
87103@pytest .mark .enterprise
88104@pytest .mark .integration
89105class TestDataFrame :
@@ -126,6 +142,43 @@ def test__create_table__metadata_is_correct(
126142 properties = {},
127143 ),
128144 ]
145+ assert table_metadata .test_result_id is None
146+
147+ def test__create_table__supports_test_result (
148+ self ,
149+ client : DataFrameClient ,
150+ create_table : Callable [[CreateTableRequest ], str ],
151+ supports_test_result_id : bool ,
152+ ):
153+ test_result_id = "Test result" if supports_test_result_id else None
154+ id = create_table (
155+ CreateTableRequest (
156+ columns = [
157+ Column (
158+ name = "index" ,
159+ data_type = DataType .Int32 ,
160+ column_type = ColumnType .Index ,
161+ )
162+ ],
163+ name = "Test table with test result ID" ,
164+ test_result_id = test_result_id ,
165+ )
166+ )
167+
168+ table = client .get_table_metadata (id )
169+ assert table .test_result_id == test_result_id
170+
171+ page = client .list_tables (take = 1 , id = [id ])
172+ assert len (page .tables ) == 1
173+ assert page .tables [0 ].test_result_id == test_result_id
174+ assert page .continuation_token is None
175+
176+ page = client .query_tables (
177+ QueryTablesRequest (filter = "id == @0" , substitutions = [id ], take = 1 )
178+ )
179+ assert len (page .tables ) == 1
180+ assert page .tables [0 ].test_result_id == test_result_id
181+ assert page .continuation_token is None
129182
130183 def test__get_table__correct_timestamp (self , client : DataFrameClient , create_table ):
131184 id = create_table (basic_table_model )
@@ -188,24 +241,33 @@ def test__query_tables__returns(
188241 assert len (second_page .tables ) == 1
189242 assert second_page .continuation_token is None
190243
191- def test__modify_table__returns (self , client : DataFrameClient , create_table ):
244+ def test__modify_table__returns (
245+ self , client : DataFrameClient , create_table , supports_test_result_id : bool
246+ ):
192247 id = create_table (basic_table_model )
193248
194249 client .modify_table (
195250 id ,
196- ModifyTableRequest (
197- metadata_revision = 2 ,
198- name = "Modified table" ,
199- properties = {"cow" : "moo" },
200- columns = [
201- ColumnMetadataPatch (name = "index" , properties = {"sheep" : "baa" })
202- ],
251+ self ._remove_test_result_id_if_not_supported (
252+ ModifyTableRequest (
253+ metadata_revision = 2 ,
254+ name = "Modified table" ,
255+ test_result_id = "Test result" ,
256+ properties = {"cow" : "moo" },
257+ columns = [
258+ ColumnMetadataPatch (name = "index" , properties = {"sheep" : "baa" })
259+ ],
260+ ),
261+ supports_test_result_id ,
203262 ),
204263 )
205264 table = client .get_table_metadata (id )
206265
207266 assert table .metadata_revision == 2
208267 assert table .name == "Modified table"
268+ assert table .test_result_id == (
269+ "Test result" if supports_test_result_id else None
270+ )
209271 assert table .properties == {"cow" : "moo" }
210272 assert table .columns [0 ].properties == {"sheep" : "baa" }
211273
@@ -214,23 +276,41 @@ def test__modify_table__returns(self, client: DataFrameClient, create_table):
214276
215277 assert table .properties == {"cow" : "moo" , "bee" : "buzz" }
216278 assert table .name == "Modified table"
279+ assert table .test_result_id == (
280+ "Test result" if supports_test_result_id else None
281+ )
217282
218283 client .modify_table (
219284 id ,
220- ModifyTableRequest (
221- metadata_revision = 4 ,
222- name = None ,
223- properties = {"cow" : None },
224- columns = [ColumnMetadataPatch (name = "index" , properties = {"sheep" : None })],
285+ self ._remove_test_result_id_if_not_supported (
286+ ModifyTableRequest (
287+ metadata_revision = 4 ,
288+ name = None ,
289+ test_result_id = None ,
290+ properties = {"cow" : None },
291+ columns = [
292+ ColumnMetadataPatch (name = "index" , properties = {"sheep" : None })
293+ ],
294+ ),
295+ supports_test_result_id ,
225296 ),
226297 )
227298 table = client .get_table_metadata (id )
228299
229300 assert table .metadata_revision == 4
230301 assert table .name == id
302+ assert table .test_result_id is None
231303 assert table .properties == {"bee" : "buzz" }
232304 assert table .columns [0 ].properties == {}
233305
306+ @staticmethod
307+ def _remove_test_result_id_if_not_supported (
308+ model : ModifyTableRequest , supports_test_result_id : bool
309+ ) -> ModifyTableRequest :
310+ if not supports_test_result_id :
311+ del model .test_result_id
312+ return model
313+
234314 def test__delete_table__deletes (self , client : DataFrameClient ):
235315 id = client .create_table (
236316 basic_table_model
@@ -259,13 +339,16 @@ def test__delete_tables__returns_partial_success(self, client: DataFrameClient):
259339 assert len (response .error .inner_errors ) == 1
260340
261341 def test__modify_tables__modifies_tables (
262- self , client : DataFrameClient , create_table
342+ self , client : DataFrameClient , create_table , supports_test_result_id : bool
263343 ):
264344 ids = [create_table (basic_table_model ) for _ in range (3 )]
265345
266346 updates = [
267347 TableMetadataModification (
268- id = id , name = "Modified table" , properties = {"duck" : "quack" }
348+ id = id ,
349+ name = "Modified table" ,
350+ test_result_id = "Test result" if supports_test_result_id else None ,
351+ properties = {"duck" : "quack" },
269352 )
270353 for id in ids
271354 ]
@@ -274,6 +357,9 @@ def test__modify_tables__modifies_tables(
274357
275358 for table in client .list_tables (id = ids ).tables :
276359 assert table .name == "Modified table"
360+ assert table .test_result_id == (
361+ "Test result" if supports_test_result_id else None
362+ )
277363 assert table .properties == {"duck" : "quack" }
278364
279365 updates = [
@@ -286,15 +372,34 @@ def test__modify_tables__modifies_tables(
286372 )
287373
288374 for table in client .list_tables (id = ids ).tables :
375+ assert table .name == "Modified table"
376+ assert table .test_result_id == (
377+ "Test result" if supports_test_result_id else None
378+ )
289379 assert table .properties == {"pig" : "oink" }
290380
381+ if supports_test_result_id :
382+ updates = [
383+ TableMetadataModification (id = id , test_result_id = "" ) for id in ids
384+ ]
385+
386+ assert client .modify_tables (ModifyTablesRequest (tables = updates )) is None
387+
388+ for table in client .list_tables (id = ids ).tables :
389+ assert table .name == "Modified table"
390+ assert table .test_result_id is None
391+
291392 def test__modify_tables__returns_partial_success (
292- self , client : DataFrameClient , create_table
393+ self , client : DataFrameClient , create_table , supports_test_result_id : bool
293394 ):
294395 id = create_table (basic_table_model )
295396
296397 updates = [
297- TableMetadataModification (id = id , name = "Modified table" )
398+ TableMetadataModification (
399+ id = id ,
400+ name = "Modified table" ,
401+ test_result_id = "Test result" if supports_test_result_id else None ,
402+ )
298403 for id in [id , "invalid_id" ]
299404 ]
300405
0 commit comments