@@ -63,6 +63,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
63
63
"datasetId" : "starry-skies" ,
64
64
"tableId" : "northern-hemisphere" ,
65
65
}
66
+ DEFAULT_ROUNDING_MODE = "ROUND_HALF_EVEN"
66
67
RESOURCE = {
67
68
"datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
68
69
"etag" : "etag" ,
@@ -73,6 +74,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
73
74
"defaultTableExpirationMs" : "3600" ,
74
75
"labels" : LABELS ,
75
76
"access" : [{"role" : "OWNER" , "userByEmail" : USER_EMAIL }, {"view" : VIEW }],
77
+ "defaultRoundingMode" : DEFAULT_ROUNDING_MODE ,
76
78
}
77
79
conn = client ._connection = make_connection (RESOURCE )
78
80
entries = [
@@ -88,8 +90,8 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
88
90
before .default_table_expiration_ms = 3600
89
91
before .location = LOCATION
90
92
before .labels = LABELS
93
+ before .default_rounding_mode = DEFAULT_ROUNDING_MODE
91
94
after = client .create_dataset (before )
92
-
93
95
assert after .dataset_id == DS_ID
94
96
assert after .project == PROJECT
95
97
assert after .etag == RESOURCE ["etag" ]
@@ -99,6 +101,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
99
101
assert after .location == LOCATION
100
102
assert after .default_table_expiration_ms == 3600
101
103
assert after .labels == LABELS
104
+ assert after .default_rounding_mode == DEFAULT_ROUNDING_MODE
102
105
103
106
conn .api_request .assert_called_once_with (
104
107
method = "POST" ,
@@ -109,6 +112,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
109
112
"friendlyName" : FRIENDLY_NAME ,
110
113
"location" : LOCATION ,
111
114
"defaultTableExpirationMs" : "3600" ,
115
+ "defaultRoundingMode" : DEFAULT_ROUNDING_MODE ,
112
116
"access" : [
113
117
{"role" : "OWNER" , "userByEmail" : USER_EMAIL },
114
118
{"view" : VIEW , "role" : None },
@@ -365,3 +369,100 @@ def test_create_dataset_alreadyexists_w_exists_ok_true(PROJECT, DS_ID, LOCATION)
365
369
mock .call (method = "GET" , path = get_path , timeout = DEFAULT_TIMEOUT ),
366
370
]
367
371
)
372
+
373
+
374
+ def test_create_dataset_with_default_rounding_mode_if_value_is_none (
375
+ PROJECT , DS_ID , LOCATION
376
+ ):
377
+ default_rounding_mode = None
378
+ path = "/projects/%s/datasets" % PROJECT
379
+ resource = {
380
+ "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
381
+ "etag" : "etag" ,
382
+ "id" : "{}:{}" .format (PROJECT , DS_ID ),
383
+ "location" : LOCATION ,
384
+ }
385
+ client = make_client (location = LOCATION )
386
+ conn = client ._connection = make_connection (resource )
387
+
388
+ ds_ref = DatasetReference (PROJECT , DS_ID )
389
+ before = Dataset (ds_ref )
390
+ before .default_rounding_mode = default_rounding_mode
391
+ after = client .create_dataset (before )
392
+
393
+ assert after .dataset_id == DS_ID
394
+ assert after .project == PROJECT
395
+ assert after .default_rounding_mode is None
396
+
397
+ conn .api_request .assert_called_once_with (
398
+ method = "POST" ,
399
+ path = path ,
400
+ data = {
401
+ "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
402
+ "labels" : {},
403
+ "location" : LOCATION ,
404
+ "defaultRoundingMode" : "ROUNDING_MODE_UNSPECIFIED" ,
405
+ },
406
+ timeout = DEFAULT_TIMEOUT ,
407
+ )
408
+
409
+
410
+ def test_create_dataset_with_default_rounding_mode_if_value_is_not_string (
411
+ PROJECT , DS_ID , LOCATION
412
+ ):
413
+ default_rounding_mode = 10
414
+ ds_ref = DatasetReference (PROJECT , DS_ID )
415
+ dataset = Dataset (ds_ref )
416
+ with pytest .raises (ValueError ) as e :
417
+ dataset .default_rounding_mode = default_rounding_mode
418
+ assert str (e .value ) == "Pass a string, or None"
419
+
420
+
421
+ def test_create_dataset_with_default_rounding_mode_if_value_is_not_in_possible_values (
422
+ PROJECT , DS_ID
423
+ ):
424
+ default_rounding_mode = "ROUND_HALF_AWAY_FROM_ZEROS"
425
+ ds_ref = DatasetReference (PROJECT , DS_ID )
426
+ dataset = Dataset (ds_ref )
427
+ with pytest .raises (ValueError ) as e :
428
+ dataset .default_rounding_mode = default_rounding_mode
429
+ assert (
430
+ str (e .value )
431
+ == "rounding mode needs to be one of ROUNDING_MODE_UNSPECIFIED,ROUND_HALF_AWAY_FROM_ZERO,ROUND_HALF_EVEN"
432
+ )
433
+
434
+
435
+ def test_create_dataset_with_default_rounding_mode_if_value_is_in_possible_values (
436
+ PROJECT , DS_ID , LOCATION
437
+ ):
438
+ default_rounding_mode = "ROUND_HALF_AWAY_FROM_ZERO"
439
+ path = "/projects/%s/datasets" % PROJECT
440
+ resource = {
441
+ "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
442
+ "etag" : "etag" ,
443
+ "id" : "{}:{}" .format (PROJECT , DS_ID ),
444
+ "location" : LOCATION ,
445
+ }
446
+ client = make_client (location = LOCATION )
447
+ conn = client ._connection = make_connection (resource )
448
+
449
+ ds_ref = DatasetReference (PROJECT , DS_ID )
450
+ before = Dataset (ds_ref )
451
+ before .default_rounding_mode = default_rounding_mode
452
+ after = client .create_dataset (before )
453
+
454
+ assert after .dataset_id == DS_ID
455
+ assert after .project == PROJECT
456
+ assert after .default_rounding_mode is None
457
+
458
+ conn .api_request .assert_called_once_with (
459
+ method = "POST" ,
460
+ path = path ,
461
+ data = {
462
+ "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
463
+ "labels" : {},
464
+ "location" : LOCATION ,
465
+ "defaultRoundingMode" : default_rounding_mode ,
466
+ },
467
+ timeout = DEFAULT_TIMEOUT ,
468
+ )
0 commit comments