@@ -466,3 +466,82 @@ def test_create_dataset_with_default_rounding_mode_if_value_is_in_possible_value
466466 },
467467 timeout = DEFAULT_TIMEOUT ,
468468 )
469+
470+
471+ def test_create_dataset_with_max_time_travel_hours (PROJECT , DS_ID , LOCATION ):
472+ path = "/projects/%s/datasets" % PROJECT
473+ max_time_travel_hours = 24 * 3
474+
475+ resource = {
476+ "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
477+ "etag" : "etag" ,
478+ "id" : "{}:{}" .format (PROJECT , DS_ID ),
479+ "location" : LOCATION ,
480+ "maxTimeTravelHours" : max_time_travel_hours ,
481+ }
482+ client = make_client (location = LOCATION )
483+ conn = client ._connection = make_connection (resource )
484+
485+ ds_ref = DatasetReference (PROJECT , DS_ID )
486+ before = Dataset (ds_ref )
487+ before .max_time_travel_hours = max_time_travel_hours
488+ after = client .create_dataset (before )
489+ assert after .dataset_id == DS_ID
490+ assert after .project == PROJECT
491+ assert after .max_time_travel_hours == max_time_travel_hours
492+
493+ conn .api_request .assert_called_once_with (
494+ method = "POST" ,
495+ path = path ,
496+ data = {
497+ "datasetReference" : {"projectId" : PROJECT , "datasetId" : DS_ID },
498+ "labels" : {},
499+ "location" : LOCATION ,
500+ "maxTimeTravelHours" : max_time_travel_hours ,
501+ },
502+ timeout = DEFAULT_TIMEOUT ,
503+ )
504+
505+
506+ def test_create_dataset_with_max_time_travel_hours_not_multiple_of_24 (
507+ PROJECT , DS_ID , LOCATION
508+ ):
509+ ds_ref = DatasetReference (PROJECT , DS_ID )
510+ dataset = Dataset (ds_ref )
511+ with pytest .raises (ValueError ) as e :
512+ dataset .max_time_travel_hours = 50
513+ assert str (e .value ) == "Time Travel Window should be multiple of 24"
514+
515+
516+ def test_create_dataset_with_max_time_travel_hours_is_less_than_2_days (
517+ PROJECT , DS_ID , LOCATION
518+ ):
519+ ds_ref = DatasetReference (PROJECT , DS_ID )
520+ dataset = Dataset (ds_ref )
521+ with pytest .raises (ValueError ) as e :
522+ dataset .max_time_travel_hours = 24
523+ assert (
524+ str (e .value )
525+ == "Time Travel Window should be from 48 to 168 hours (2 to 7 days)"
526+ )
527+
528+
529+ def test_create_dataset_with_max_time_travel_hours_is_greater_than_7_days (
530+ PROJECT , DS_ID , LOCATION
531+ ):
532+ ds_ref = DatasetReference (PROJECT , DS_ID )
533+ dataset = Dataset (ds_ref )
534+ with pytest .raises (ValueError ) as e :
535+ dataset .max_time_travel_hours = 192
536+ assert (
537+ str (e .value )
538+ == "Time Travel Window should be from 48 to 168 hours (2 to 7 days)"
539+ )
540+
541+
542+ def test_create_dataset_with_max_time_travel_hours_is_not_int (PROJECT , DS_ID , LOCATION ):
543+ ds_ref = DatasetReference (PROJECT , DS_ID )
544+ dataset = Dataset (ds_ref )
545+ with pytest .raises (ValueError ) as e :
546+ dataset .max_time_travel_hours = "50"
547+ assert str (e .value ) == "max_time_travel_hours must be an integer. Got 50"
0 commit comments