@@ -269,6 +269,15 @@ def test_check_parameters_wrong_bounding_box_type(self):
269
269
with self .assertRaises (ValidationError ):
270
270
models .DownloadJob .check_parameters ({'dataset_id' : 1 , 'bounding_box' : [2 ]})
271
271
272
+ def test_check_parameters_wrong_publish_type (self ):
273
+ """`check_parameters()` must raise an exception if the
274
+ 'publish' value is of the wrong type
275
+ """
276
+ with self .assertRaises (ValidationError ):
277
+ models .DownloadJob .check_parameters ({'dataset_id' : 1 , 'publish' : 'False' })
278
+ with self .assertRaises (ValidationError ):
279
+ models .DownloadJob .check_parameters ({'dataset_id' : 1 , 'publish' : 1 })
280
+
272
281
273
282
class ConvertJobTests (unittest .TestCase ):
274
283
"""Tests for the ConvertJob class"""
@@ -439,6 +448,97 @@ def test_make_task_parameters(self):
439
448
(({'id' : 539 },), {}))
440
449
441
450
451
+ class SyntoolCompareJobTests (unittest .TestCase ):
452
+ """Tests for the SyntoolCompareJob class"""
453
+
454
+ def test_get_signature (self ):
455
+ """Test getting the right signature"""
456
+ with mock .patch (
457
+ 'geospaas_rest_api.processing_api.models.tasks_syntool' ) as mock_syntool_tasks , \
458
+ mock .patch ('celery.chain' ) as mock_chain :
459
+ _ = models .SyntoolCompareJob .get_signature ({})
460
+ mock_chain .assert_called_once_with (
461
+ mock_syntool_tasks .compare_profiles .signature .return_value ,
462
+ mock_syntool_tasks .db_insert .signature .return_value ,
463
+ )
464
+
465
+ def test_check_parameters_ok (self ):
466
+ """Test that check_parameters() returns the parameters when
467
+ they are valid
468
+ """
469
+ self .assertDictEqual (
470
+ models .SyntoolCompareJob .check_parameters ({
471
+ 'model' : (123 , '/foo' ),
472
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' ))
473
+ }),
474
+ {'model' : (123 , '/foo' ), 'profiles' : ((456 , '/bar' ), (789 , '/baz' ))})
475
+
476
+ def test_check_parameters_unknown (self ):
477
+ """An error should be raised when an unknown parameter is given
478
+ """
479
+ with self .assertRaises (ValidationError ):
480
+ models .SyntoolCompareJob .check_parameters ({'foo' : 'bar' })
481
+
482
+ def test_check_parameters_no_criteria (self ):
483
+ """An error should be raised when the criteria parameter is
484
+ absent
485
+ """
486
+ with self .assertRaises (ValidationError ):
487
+ models .SyntoolCompareJob .check_parameters ({})
488
+
489
+ def test_check_parameters_wrong_type (self ):
490
+ """An error should be raised when the parameters have the
491
+ wrong type
492
+ """
493
+ # model not a sequence
494
+ with self .assertRaises (ValidationError ):
495
+ models .SyntoolCompareJob .check_parameters (
496
+ {'model' : 123 , 'profiles' : ((123 , '/bar' ),)})
497
+ # wrong model ID type
498
+ with self .assertRaises (ValidationError ):
499
+ models .SyntoolCompareJob .check_parameters (
500
+ {'model' : ('123' , '/foo' ), 'profiles' : ((123 , '/bar' ),)})
501
+ # wrong model path type
502
+ with self .assertRaises (ValidationError ):
503
+ models .SyntoolCompareJob .check_parameters (
504
+ {'model' : (123 , True ), 'profiles' : ((123 , '/bar' ),)})
505
+ # profile not a sequence
506
+ with self .assertRaises (ValidationError ):
507
+ models .SyntoolCompareJob .check_parameters ({
508
+ 'model' : (123 , '/foo' ),
509
+ 'profiles' : 456
510
+ })
511
+ # profile not a sequence of couples
512
+ with self .assertRaises (ValidationError ):
513
+ models .SyntoolCompareJob .check_parameters ({
514
+ 'model' : (123 , '/foo' ),
515
+ 'profiles' : (456 , 789 )
516
+ })
517
+ # wrong profile ID type
518
+ with self .assertRaises (ValidationError ):
519
+ models .SyntoolCompareJob .check_parameters ({
520
+ 'model' : (123 , '/foo' ),
521
+ 'profiles' : (('456' , '/bar' ), (789 , '/baz' ))
522
+ })
523
+ # wrong profile path type
524
+ with self .assertRaises (ValidationError ):
525
+ models .SyntoolCompareJob .check_parameters ({
526
+ 'model' : (123 , '/foo' ),
527
+ 'profiles' : ((456 , '/bar' ), (789 , False ))
528
+ })
529
+
530
+ def test_make_task_parameters (self ):
531
+ """Test that the right arguments are builts from the request
532
+ parameters
533
+ """
534
+ self .assertTupleEqual (
535
+ models .SyntoolCompareJob .make_task_parameters ({
536
+ 'model' : (123 , '/foo' ),
537
+ 'profiles' : ((456 , '/bar' ), (789 , '/baz' ))
538
+ }),
539
+ ((((123 , '/foo' ), ((456 , '/bar' ), (789 , '/baz' ))),), {}))
540
+
541
+
442
542
class HarvestJobTests (unittest .TestCase ):
443
543
"""Tests for the HarvestJob class"""
444
544
0 commit comments