@@ -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,8 @@ 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-
9395 assert after .dataset_id == DS_ID
9496 assert after .project == PROJECT
9597 assert after .etag == RESOURCE ["etag" ]
@@ -99,6 +101,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
99101 assert after .location == LOCATION
100102 assert after .default_table_expiration_ms == 3600
101103 assert after .labels == LABELS
104+ assert after .default_rounding_mode == DEFAULT_ROUNDING_MODE
102105
103106 conn .api_request .assert_called_once_with (
104107 method = "POST" ,
@@ -109,6 +112,7 @@ def test_create_dataset_w_attrs(client, PROJECT, DS_ID):
109112 "friendlyName" : FRIENDLY_NAME ,
110113 "location" : LOCATION ,
111114 "defaultTableExpirationMs" : "3600" ,
115+ "defaultRoundingMode" : DEFAULT_ROUNDING_MODE ,
112116 "access" : [
113117 {"role" : "OWNER" , "userByEmail" : USER_EMAIL },
114118 {"view" : VIEW , "role" : None },
@@ -365,3 +369,100 @@ def test_create_dataset_alreadyexists_w_exists_ok_true(PROJECT, DS_ID, LOCATION)
365369 mock .call (method = "GET" , path = get_path , timeout = DEFAULT_TIMEOUT ),
366370 ]
367371 )
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