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