@@ -63,6 +63,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
6363 "datasetId" : "starry-skies" ,
6464 "tableId" : "northern-hemisphere" ,
6565 }
66+ DEFAULT_ROUNDING_MODE = "ROUND_HALF_EVEN"
6667 RESOURCE = {
6768 "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
6869 "etag" : "etag" ,
@@ -73,6 +74,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
7374 "defaultTableExpirationMs" : "3600" ,
7475 "labels" : LABELS ,
7576 "access" : [{"role" : "OWNER" , "userByEmail" : USER_EMAIL }, {"view" : VIEW }],
77+ "defaultRoundingMode" : DEFAULT_ROUNDING_MODE ,
7678 }
7779 conn = client ._connection = make_connection (RESOURCE )
7880 entries = [
@@ -88,8 +90,9 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
8890 before .default_table_expiration_ms = 3600
8991 before .location = LOCATION
9092 before .labels = LABELS
93+ before .default_rounding_mode = DEFAULT_ROUNDING_MODE
9194 after = client .create_dataset (before )
92-
95+ print ( after )
9396 assert after .dataset_id == DS_ID
9497 assert after .project == PROJECT
9598 assert after .etag == RESOURCE ["etag" ]
@@ -99,6 +102,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
99102 assert after .location == LOCATION
100103 assert after .default_table_expiration_ms == 3600
101104 assert after .labels == LABELS
105+ assert after .default_rounding_mode == DEFAULT_ROUNDING_MODE
102106
103107 conn .api_request .assert_called_once_with (
104108 method = "POST" ,
@@ -109,6 +113,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
109113 "friendlyName" : FRIENDLY_NAME ,
110114 "location" : LOCATION ,
111115 "defaultTableExpirationMs" : "3600" ,
116+ "defaultRoundingMode" : DEFAULT_ROUNDING_MODE ,
112117 "access" : [
113118 {"role" : "OWNER" , "userByEmail" : USER_EMAIL },
114119 {"view" : VIEW , "role" : None },
@@ -365,3 +370,106 @@ def test_create_dataset_alreadyexists_w_exists_ok_true(PROJECT, DS_ID, LOCATION)
365370 mock .call (method = "GET" , path = get_path , timeout = DEFAULT_TIMEOUT ),
366371 ]
367372 )
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