@@ -295,7 +295,8 @@ def test_check_parameters_wrong_key(self):
295
295
self .assertListEqual (
296
296
raised .exception .detail ,
297
297
[ErrorDetail (string = "The convert action accepts only these parameters: "
298
- "dataset_id, format, bounding_box, skip_check, converter_options" ,
298
+ "dataset_id, format, bounding_box, skip_check, converter_options, "
299
+ "remove_downloaded, ttl" ,
299
300
code = 'invalid' )])
300
301
301
302
def test_check_parameters_wrong_format (self ):
@@ -314,7 +315,8 @@ def test_check_parameters_extra_param(self):
314
315
self .assertListEqual (
315
316
raised .exception .detail ,
316
317
[ErrorDetail (string = "The convert action accepts only these parameters: "
317
- "dataset_id, format, bounding_box, skip_check, converter_options" ,
318
+ "dataset_id, format, bounding_box, skip_check, converter_options, "
319
+ "remove_downloaded, ttl" ,
318
320
code = 'invalid' )])
319
321
320
322
def test_check_parameters_wrong_type_for_dataset_id (self ):
@@ -348,15 +350,34 @@ def test_check_parameters_wrong_converter_options_type(self):
348
350
models .ConvertJob .check_parameters (
349
351
{'dataset_id' : 1 , 'format' : 'idf' , 'converter_options' : '2' })
350
352
353
+ def test_check_parameters_ttl (self ):
354
+ """`check_parameters()` must not raise an exception if 'ttl' is
355
+ a dict or None
356
+ """
357
+ self .assertEqual (
358
+ models .ConvertJob .check_parameters (
359
+ {'dataset_id' : 1 , 'format' : 'syntool' , 'ttl' : {'days' : 2 }}),
360
+ {'dataset_id' : 1 , 'format' : 'syntool' , 'ttl' : {'days' : 2 }})
361
+ self .assertEqual (
362
+ models .ConvertJob .check_parameters (
363
+ {'dataset_id' : 1 , 'format' : 'syntool' , 'ttl' : None }),
364
+ {'dataset_id' : 1 , 'format' : 'syntool' , 'ttl' : None })
365
+
366
+ def test_check_parameters_wrong_ttl_type (self ):
367
+ """`check_parameters()` must raise an exception if the 'ttl'
368
+ value is of the wrong type"""
369
+ with self .assertRaises (ValidationError ):
370
+ models .ConvertJob .check_parameters (
371
+ {'dataset_id' : 1 , 'format' : 'syntool' , 'ttl' : 2 })
372
+
351
373
def test_get_signature_syntool (self ):
352
374
"""Test the right signature is returned"""
353
- self .maxDiff = None
354
375
base_chain = celery .chain (
355
376
tasks_core .download .signature (),
356
377
tasks_core .unarchive .signature (),
357
378
tasks_core .crop .signature (
358
379
kwargs = {'bounding_box' : [0 , 20 , 20 , 0 ]}),
359
- tasks_syntool .convert .signature (kwargs = {'converter_options' : None }),
380
+ tasks_syntool .convert .signature (kwargs = {'converter_options' : None , 'ttl' : None }),
360
381
tasks_syntool .db_insert .signature (),
361
382
tasks_core .remove_downloaded .signature ())
362
383
@@ -459,11 +480,26 @@ def test_get_signature(self):
459
480
'geospaas_rest_api.processing_api.models.tasks_core' ) as mock_core_tasks , \
460
481
mock .patch ('celery.chain' ) as mock_chain :
461
482
_ = models .SyntoolCompareJob .get_signature ({})
462
- mock_chain .assert_called_once_with (
483
+ mock_chain .assert_called_once_with ([
463
484
mock_syntool_tasks .compare_profiles .signature .return_value ,
464
485
mock_syntool_tasks .db_insert .signature .return_value ,
465
486
mock_core_tasks .remove_downloaded .signature .return_value ,
466
- )
487
+ ])
488
+
489
+ def test_get_signature_no_remove (self ):
490
+ """Test that remove_downloaded is not added to the signature if
491
+ the parameter is False
492
+ """
493
+ with mock .patch (
494
+ 'geospaas_rest_api.processing_api.models.tasks_syntool' ) as mock_syntool_tasks , \
495
+ mock .patch (
496
+ 'geospaas_rest_api.processing_api.models.tasks_core' ) as mock_core_tasks , \
497
+ mock .patch ('celery.chain' ) as mock_chain :
498
+ _ = models .SyntoolCompareJob .get_signature ({'remove_downloaded' : False })
499
+ mock_chain .assert_called_once_with ([
500
+ mock_syntool_tasks .compare_profiles .signature .return_value ,
501
+ mock_syntool_tasks .db_insert .signature .return_value ,
502
+ ])
467
503
468
504
def test_check_parameters_ok (self ):
469
505
"""Test that check_parameters() returns the parameters when
@@ -472,10 +508,36 @@ def test_check_parameters_ok(self):
472
508
self .assertDictEqual (
473
509
models .SyntoolCompareJob .check_parameters ({
474
510
'model' : (123 , '/foo' ),
475
- 'profiles' : ((456 , '/bar' ), (789 , '/baz' ))
511
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' )),
476
512
}),
477
513
{'model' : (123 , '/foo' ), 'profiles' : ((456 , '/bar' ), (789 , '/baz' ))})
478
514
515
+ def test_check_parameters_ttl (self ):
516
+ """ttl must be a dict or None"""
517
+ self .assertDictEqual (
518
+ models .SyntoolCompareJob .check_parameters ({
519
+ 'model' : (123 , '/foo' ),
520
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' )),
521
+ 'ttl' : {'days' : 2 },
522
+ }),
523
+ {
524
+ 'model' : (123 , '/foo' ),
525
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' )),
526
+ 'ttl' : {'days' : 2 },
527
+ })
528
+ self .assertDictEqual (
529
+ models .SyntoolCompareJob .check_parameters ({
530
+ 'model' : (123 , '/foo' ),
531
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' )),
532
+ 'ttl' : None ,
533
+ }),
534
+ {
535
+ 'model' : (123 , '/foo' ),
536
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' )),
537
+ 'ttl' : None ,
538
+ })
539
+
540
+
479
541
def test_check_parameters_unknown (self ):
480
542
"""An error should be raised when an unknown parameter is given
481
543
"""
@@ -529,6 +591,13 @@ def test_check_parameters_wrong_type(self):
529
591
'model' : (123 , '/foo' ),
530
592
'profiles' : ((456 , '/bar' ), (789 , False ))
531
593
})
594
+ # wrong ttl type
595
+ with self .assertRaises (ValidationError ):
596
+ models .SyntoolCompareJob .check_parameters ({
597
+ 'model' : (123 , '/foo' ),
598
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' )),
599
+ 'ttl' : 2 ,
600
+ })
532
601
533
602
def test_make_task_parameters (self ):
534
603
"""Test that the right arguments are builts from the request
@@ -582,6 +651,29 @@ def test_make_task_parameters(self):
582
651
(({'foo' : 'bar' },), {}))
583
652
584
653
654
+ class WorkdirCleanupJobTests (unittest .TestCase ):
655
+ """Tests for WorkdirCleanupJob"""
656
+
657
+ def test_get_signature (self ):
658
+ """The signature is the cleanup_workdir task"""
659
+ self .assertEqual (
660
+ models .WorkdirCleanupJob .get_signature ({}),
661
+ tasks_core .cleanup_workdir .signature ()
662
+ )
663
+
664
+ def test_check_parameters (self ):
665
+ """No check needed"""
666
+ parameters = mock .Mock ()
667
+ self .assertEqual (
668
+ models .WorkdirCleanupJob .check_parameters (parameters ),
669
+ parameters )
670
+
671
+ def test_make_task_parameters (self ):
672
+ """No parameters needed"""
673
+ self .assertTupleEqual (
674
+ models .WorkdirCleanupJob .make_task_parameters ({}),
675
+ (tuple (), {}))
676
+
585
677
class JobViewSetTests (django .test .TestCase ):
586
678
"""Test jobs/ endpoints"""
587
679
@@ -874,13 +966,15 @@ def test_list_tasks(self):
874
966
"dataset" : 1 ,
875
967
"path" : "ingested/product_name/granule_name_1/" ,
876
968
"type" : "syntool" ,
877
- "created" : "2023-10-25T15:38:47Z"
969
+ "created" : "2023-10-25T15:38:47Z" ,
970
+ "ttl" : None ,
878
971
}, {
879
972
"id" : 2 ,
880
973
"dataset" : 2 ,
881
974
"path" : "ingested/product_name/granule_name_2/" ,
882
975
"type" : "syntool" ,
883
- "created" : "2023-10-26T09:10:19Z"
976
+ "created" : "2023-10-26T09:10:19Z" ,
977
+ "ttl" : None ,
884
978
}
885
979
]
886
980
}
@@ -894,5 +988,6 @@ def test_retrieve_task(self):
894
988
"dataset" : 1 ,
895
989
"path" : "ingested/product_name/granule_name_1/" ,
896
990
"type" : "syntool" ,
897
- "created" : "2023-10-25T15:38:47Z"
991
+ "created" : "2023-10-25T15:38:47Z" ,
992
+ "ttl" : None ,
898
993
})
0 commit comments