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