1
1
# -*- coding: utf-8 -*-
2
2
from datetime import datetime , timezone
3
- from typing import List
3
+ from typing import List , Optional
4
4
5
5
import pytest # type: ignore
6
6
from nisystemlink .clients .core import ApiException
7
7
from nisystemlink .clients .dataframe import DataFrameClient
8
8
from nisystemlink .clients .dataframe import models
9
9
10
+ basic_table_model = models .CreateTableRequest (
11
+ columns = [
12
+ models .Column (
13
+ name = "index" ,
14
+ data_type = models .DataType .Int32 ,
15
+ column_type = models .ColumnType .Index ,
16
+ )
17
+ ]
18
+ )
19
+
10
20
11
21
@pytest .fixture (scope = "class" )
12
22
def client (enterprise_config ):
@@ -19,8 +29,8 @@ def create_table(client: DataFrameClient):
19
29
"""Fixture to return a factory that creates tables."""
20
30
tables = []
21
31
22
- def _create_table (table : models .CreateTableRequest ) -> str :
23
- id = client .create_table (table )
32
+ def _create_table (table : Optional [ models .CreateTableRequest ] = None ) -> str :
33
+ id = client .create_table (table or basic_table_model )
24
34
tables .append (id )
25
35
return id
26
36
@@ -85,17 +95,7 @@ def test__create_table__metadata_is_corect(
85
95
]
86
96
87
97
def test__get_table__correct_timestamp (self , client : DataFrameClient , create_table ):
88
- id = create_table (
89
- models .CreateTableRequest (
90
- columns = [
91
- models .Column (
92
- name = "index" ,
93
- data_type = models .DataType .Int32 ,
94
- column_type = models .ColumnType .Index ,
95
- )
96
- ]
97
- )
98
- )
98
+ id = create_table (basic_table_model )
99
99
table = client .get_table_metadata (id )
100
100
101
101
now = datetime .now ().timestamp ()
@@ -156,17 +156,7 @@ def test__query_tables__returns(
156
156
assert second_page .continuation_token is None
157
157
158
158
def test__modify_table__returns (self , client : DataFrameClient , create_table ):
159
- id = create_table (
160
- models .CreateTableRequest (
161
- columns = [
162
- models .Column (
163
- name = "index" ,
164
- data_type = models .DataType .Int32 ,
165
- column_type = models .ColumnType .Index ,
166
- )
167
- ]
168
- )
169
- )
159
+ id = create_table (basic_table_model )
170
160
171
161
client .modify_table (
172
162
id ,
@@ -213,59 +203,76 @@ def test__modify_table__returns(self, client: DataFrameClient, create_table):
213
203
assert table .columns [0 ].properties == {}
214
204
215
205
def test__delete_table__deletes (self , client : DataFrameClient ):
216
- id = client .create_table ( # Don't use fixture to avoid deleting the table twice
217
- models .CreateTableRequest (
218
- columns = [
219
- models .Column (
220
- name = "index" ,
221
- data_type = models .DataType .Int32 ,
222
- column_type = models .ColumnType .Index ,
223
- )
224
- ]
225
- )
226
- )
206
+ id = client .create_table (
207
+ basic_table_model
208
+ ) # Don't use fixture to avoid deleting the table twice
227
209
228
210
assert client .delete_table (id ) is None
229
211
230
212
with pytest .raises (ApiException , match = "404 Not Found" ):
231
213
client .get_table_metadata (id )
232
214
233
215
def test__delete_tables__deletes (self , client : DataFrameClient ):
234
- ids = [
235
- client .create_table (
236
- models .CreateTableRequest (
237
- columns = [
238
- models .Column (
239
- name = "index" ,
240
- data_type = models .DataType .Int32 ,
241
- column_type = models .ColumnType .Index ,
242
- )
243
- ]
244
- )
245
- )
246
- for _ in range (3 )
247
- ]
216
+ ids = [client .create_table (basic_table_model ) for _ in range (3 )]
248
217
249
218
assert client .delete_tables (ids ) is None
250
219
251
220
assert client .list_tables (id = ids ).tables == []
252
221
253
222
def test__delete_tables__returns_partial_success (self , client : DataFrameClient ):
254
- id = client .create_table (
255
- models .CreateTableRequest (
256
- columns = [
257
- models .Column (
258
- name = "index" ,
259
- data_type = models .DataType .Int32 ,
260
- column_type = models .ColumnType .Index ,
261
- )
262
- ]
263
- )
264
- )
223
+ id = client .create_table (basic_table_model )
265
224
266
225
response = client .delete_tables ([id , "invalid_id" ])
267
226
268
227
assert response is not None
269
228
assert response .deleted_table_ids == [id ]
270
229
assert response .failed_table_ids == ["invalid_id" ]
271
230
assert len (response .error .inner_errors ) == 1
231
+
232
+ def test__modify_tables__modifies_tables (
233
+ self , client : DataFrameClient , create_table
234
+ ):
235
+ ids = [create_table (basic_table_model ) for _ in range (3 )]
236
+
237
+ updates = [
238
+ models .TableMetdataModification (
239
+ id = id , name = "Modified table" , properties = {"duck" : "quack" }
240
+ )
241
+ for id in ids
242
+ ]
243
+
244
+ assert client .modify_tables (models .ModifyTablesRequest (tables = updates )) is None
245
+
246
+ for table in client .list_tables (id = ids ).tables :
247
+ assert table .name == "Modified table"
248
+ assert table .properties == {"duck" : "quack" }
249
+
250
+ updates = [
251
+ models .TableMetdataModification (id = id , properties = {"pig" : "oink" })
252
+ for id in ids
253
+ ]
254
+
255
+ assert (
256
+ client .modify_tables (
257
+ models .ModifyTablesRequest (tables = updates , replace = True )
258
+ )
259
+ is None
260
+ )
261
+
262
+ for table in client .list_tables (id = ids ).tables :
263
+ assert table .properties == {"pig" : "oink" }
264
+
265
+ def test__modify_tables__returns_partial_success (self , client : DataFrameClient ):
266
+ id = client .create_table (basic_table_model )
267
+
268
+ updates = [
269
+ models .TableMetdataModification (id = id , name = "Modified table" )
270
+ for id in [id , "invalid_id" ]
271
+ ]
272
+
273
+ response = client .modify_tables (models .ModifyTablesRequest (tables = updates ))
274
+
275
+ assert response is not None
276
+ assert response .modified_table_ids == [id ]
277
+ assert response .failed_modifications == [updates [1 ]]
278
+ assert len (response .error .inner_errors ) == 1
0 commit comments