@@ -455,6 +455,89 @@ def test_project_upload_dataset(self):
455
455
for mock in mocks .values ():
456
456
mock .stop ()
457
457
458
+ def test_get_batches_success (self ):
459
+ expected_url = f"{ API_URL } /{ WORKSPACE_NAME } /{ PROJECT_NAME } /batches?api_key={ ROBOFLOW_API_KEY } "
460
+ mock_response = {
461
+ "batches" : [
462
+ {
463
+ "name" : "Uploaded on 11/22/22 at 1:39 pm" ,
464
+ "numJobs" : 2 ,
465
+ "images" : 115 ,
466
+ "uploaded" : {"_seconds" : 1669146024 , "_nanoseconds" : 818000000 },
467
+ "id" : "batch-1" ,
468
+ },
469
+ {
470
+ "numJobs" : 0 ,
471
+ "images" : 11 ,
472
+ "uploaded" : {"_seconds" : 1669236873 , "_nanoseconds" : 47000000 },
473
+ "name" : "Upload via API" ,
474
+ "id" : "batch-2" ,
475
+ },
476
+ ]
477
+ }
478
+
479
+ responses .add (responses .GET , expected_url , json = mock_response , status = 200 )
480
+
481
+ batches = self .project .get_batches ()
482
+
483
+ self .assertIsInstance (batches , dict )
484
+ self .assertIn ("batches" , batches )
485
+ self .assertEqual (len (batches ["batches" ]), 2 )
486
+ self .assertEqual (batches ["batches" ][0 ]["id" ], "batch-1" )
487
+ self .assertEqual (batches ["batches" ][0 ]["name" ], "Uploaded on 11/22/22 at 1:39 pm" )
488
+ self .assertEqual (batches ["batches" ][0 ]["images" ], 115 )
489
+ self .assertEqual (batches ["batches" ][0 ]["numJobs" ], 2 )
490
+ self .assertEqual (batches ["batches" ][1 ]["id" ], "batch-2" )
491
+ self .assertEqual (batches ["batches" ][1 ]["name" ], "Upload via API" )
492
+
493
+ def test_get_batches_error (self ):
494
+ expected_url = f"{ API_URL } /{ WORKSPACE_NAME } /{ PROJECT_NAME } /batches?api_key={ ROBOFLOW_API_KEY } "
495
+ error_response = {"error" : "Cannot retrieve batches" }
496
+
497
+ responses .add (responses .GET , expected_url , json = error_response , status = 404 )
498
+
499
+ with self .assertRaises (RuntimeError ) as context :
500
+ self .project .get_batches ()
501
+
502
+ self .assertEqual (str (context .exception ), "Cannot retrieve batches" )
503
+
504
+ def test_get_batch_success (self ):
505
+ batch_id = "batch-123"
506
+ expected_url = f"{ API_URL } /{ WORKSPACE_NAME } /{ PROJECT_NAME } /batches/{ batch_id } ?api_key={ ROBOFLOW_API_KEY } "
507
+ mock_response = {
508
+ "batch" : {
509
+ "name" : "Uploaded on 11/22/22 at 1:39 pm" ,
510
+ "numJobs" : 2 ,
511
+ "images" : 115 ,
512
+ "uploaded" : {"_seconds" : 1669146024 , "_nanoseconds" : 818000000 },
513
+ "id" : batch_id ,
514
+ }
515
+ }
516
+
517
+ responses .add (responses .GET , expected_url , json = mock_response , status = 200 )
518
+
519
+ batch = self .project .get_batch (batch_id )
520
+
521
+ self .assertIsInstance (batch , dict )
522
+ self .assertIn ("batch" , batch )
523
+ self .assertEqual (batch ["batch" ]["id" ], batch_id )
524
+ self .assertEqual (batch ["batch" ]["name" ], "Uploaded on 11/22/22 at 1:39 pm" )
525
+ self .assertEqual (batch ["batch" ]["images" ], 115 )
526
+ self .assertEqual (batch ["batch" ]["numJobs" ], 2 )
527
+ self .assertIn ("uploaded" , batch ["batch" ])
528
+
529
+ def test_get_batch_error (self ):
530
+ batch_id = "nonexistent-batch"
531
+ expected_url = f"{ API_URL } /{ WORKSPACE_NAME } /{ PROJECT_NAME } /batches/{ batch_id } ?api_key={ ROBOFLOW_API_KEY } "
532
+ error_response = {"error" : "Batch not found" }
533
+
534
+ responses .add (responses .GET , expected_url , json = error_response , status = 404 )
535
+
536
+ with self .assertRaises (RuntimeError ) as context :
537
+ self .project .get_batch (batch_id )
538
+
539
+ self .assertEqual (str (context .exception ), "Batch not found" )
540
+
458
541
def test_classification_dataset_upload (self ):
459
542
from roboflow .util import folderparser
460
543
0 commit comments