@ -1,4 +1,4 @@
# Copyright (C) 2020 Intel Corporation
# Copyright (C) 2020 -2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
@ -67,47 +67,47 @@ class _DbTestBase(APITestCase):
cls . admin = user_admin
cls . user = user_dummy
def _put_api_v 1 _task_id_annotations( self , tid , data ) :
def _put_api_v 2 _task_id_annotations( self , tid , data ) :
with ForceLogin ( self . admin , self . client ) :
response = self . client . put ( " /api/ v1/ tasks/%s /annotations " % tid ,
response = self . client . put ( " /api/ tasks/%s /annotations " % tid ,
data = data , format = " json " )
return response
def _put_api_v 1 _job_id_annotations( self , jid , data ) :
def _put_api_v 2 _job_id_annotations( self , jid , data ) :
with ForceLogin ( self . admin , self . client ) :
response = self . client . put ( " /api/ v1/ jobs/%s /annotations " % jid ,
response = self . client . put ( " /api/ jobs/%s /annotations " % jid ,
data = data , format = " json " )
return response
def _patch_api_v 1 _task_id_annotations( self , tid , data , action , user ) :
def _patch_api_v 2 _task_id_annotations( self , tid , data , action , user ) :
with ForceLogin ( user , self . client ) :
response = self . client . patch (
" /api/ v1/ tasks/{} /annotations?action= {} " . format ( tid , action ) ,
" /api/ tasks/{} /annotations?action= {} " . format ( tid , action ) ,
data = data , format = " json " )
return response
def _patch_api_v 1 _job_id_annotations( self , jid , data , action , user ) :
def _patch_api_v 2 _job_id_annotations( self , jid , data , action , user ) :
with ForceLogin ( user , self . client ) :
response = self . client . patch (
" /api/ v1/ jobs/{} /annotations?action= {} " . format ( jid , action ) ,
" /api/ jobs/{} /annotations?action= {} " . format ( jid , action ) ,
data = data , format = " json " )
return response
def _create_task ( self , data , image_data ) :
with ForceLogin ( self . user , self . client ) :
response = self . client . post ( ' /api/ v1/ tasks' , data = data , format = " json " )
response = self . client . post ( ' /api/ tasks' , data = data , format = " json " )
assert response . status_code == status . HTTP_201_CREATED , response . status_code
tid = response . data [ " id " ]
response = self . client . post ( " /api/ v1/ tasks/%s /data " % tid ,
response = self . client . post ( " /api/ tasks/%s /data " % tid ,
data = image_data )
assert response . status_code == status . HTTP_202_ACCEPTED , response . status_code
response = self . client . get ( " /api/ v1/ tasks/%s " % tid )
response = self . client . get ( " /api/ tasks/%s " % tid )
task = response . data
return task
@ -140,7 +140,7 @@ class _DbTestBase(APITestCase):
def _get_jobs ( self , task_id ) :
with ForceLogin ( self . admin , self . client ) :
response = self . client . get ( " /api/ v1/ tasks/{} /jobs " . format ( task_id ) )
response = self . client . get ( " /api/ tasks/{} /jobs " . format ( task_id ) )
return response . data
def _get_request ( self , path , user ) :
@ -175,22 +175,22 @@ class _DbTestBase(APITestCase):
self . assertEqual ( response . status_code , status . HTTP_201_CREATED )
def _generate_url_dump_tasks_annotations ( self , task_id ) :
return f " /api/ v1/ tasks/{ task_id } /annotations "
return f " /api/ tasks/{ task_id } /annotations "
def _generate_url_upload_tasks_annotations ( self , task_id , upload_format_name ) :
return f " /api/ v1/ tasks/{ task_id } /annotations?format= { upload_format_name } "
return f " /api/ tasks/{ task_id } /annotations?format= { upload_format_name } "
def _generate_url_dump_job_annotations ( self , job_id ) :
return f " /api/ v1/ jobs/{ job_id } /annotations "
return f " /api/ jobs/{ job_id } /annotations "
def _generate_url_upload_job_annotations ( self , job_id , upload_format_name ) :
return f " /api/ v1/ jobs/{ job_id } /annotations?format= { upload_format_name } "
return f " /api/ jobs/{ job_id } /annotations?format= { upload_format_name } "
def _generate_url_dump_dataset ( self , task_id ) :
return f " /api/ v1/ tasks/{ task_id } /dataset "
return f " /api/ tasks/{ task_id } /dataset "
def _remove_annotations ( self , tid ) :
response = self . _delete_request ( f " /api/ v1/ tasks/{ tid } /annotations " , self . admin )
response = self . _delete_request ( f " /api/ tasks/{ tid } /annotations " , self . admin )
self . assertEqual ( response . status_code , status . HTTP_204_NO_CONTENT )
return response
@ -200,7 +200,7 @@ class _DbTestBase(APITestCase):
return response
def _delete_task ( self , tid ) :
response = self . _delete_request ( ' /api/ v1/ tasks/{} ' . format ( tid ) , self . admin )
response = self . _delete_request ( ' /api/ tasks/{} ' . format ( tid ) , self . admin )
self . assertEqual ( response . status_code , status . HTTP_204_NO_CONTENT )
return response
@ -383,7 +383,7 @@ class Task3DTest(_DbTestBase):
}
return task_data
def test_api_v 1 _create_annotation_in_job( self ) :
def test_api_v 2 _create_annotation_in_job( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -391,7 +391,7 @@ class Task3DTest(_DbTestBase):
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
for user , edata in list ( self . expected_action . items ( ) ) :
with self . subTest ( format = edata [ " name " ] ) :
response = self . _patch_api_v 1 _task_id_annotations( task_id , annotation , CREATE_ACTION , user )
response = self . _patch_api_v 2 _task_id_annotations( task_id , annotation , CREATE_ACTION , user )
self . assertEqual ( response . status_code , edata [ " code " ] )
if edata [ " annotation_changed " ] :
task_ann = TaskAnnotation ( task_id )
@ -401,13 +401,13 @@ class Task3DTest(_DbTestBase):
self . assertEqual ( task_shape , annotation [ " shapes " ] [ 0 ] )
self . _remove_annotations ( task_id )
def test_api_v 1 _update_annotation_in_task( self ) :
def test_api_v 2 _update_annotation_in_task( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
task_id = task [ " id " ]
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
for user , edata in list ( self . expected_action . items ( ) ) :
@ -416,7 +416,7 @@ class Task3DTest(_DbTestBase):
task_ann_prev . init_from_db ( )
annotation [ " shapes " ] [ 0 ] [ " points " ] = [ x + 0.1 for x in annotation [ " shapes " ] [ 0 ] [ " points " ] ]
annotation [ " shapes " ] [ 0 ] [ " id " ] = task_ann_prev . data [ " shapes " ] [ 0 ] [ " id " ]
response = self . _patch_api_v 1 _task_id_annotations( task_id , annotation , UPDATE_ACTION , user )
response = self . _patch_api_v 2 _task_id_annotations( task_id , annotation , UPDATE_ACTION , user )
self . assertEqual ( response . status_code , edata [ " code " ] , task_id )
if edata [ " annotation_changed " ] :
@ -424,7 +424,7 @@ class Task3DTest(_DbTestBase):
task_ann . init_from_db ( )
self . assertEqual ( task_ann . data [ " shapes " ] , annotation [ " shapes " ] )
def test_api_v 1 _remove_annotation_in_task( self ) :
def test_api_v 2 _remove_annotation_in_task( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -433,13 +433,13 @@ class Task3DTest(_DbTestBase):
for user , edata in list ( self . expected_action . items ( ) ) :
with self . subTest ( format = edata [ " name " ] ) :
response = self . _patch_api_v 1 _task_id_annotations( task_id , annotation , CREATE_ACTION , self . admin )
response = self . _patch_api_v 2 _task_id_annotations( task_id , annotation , CREATE_ACTION , self . admin )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )
annotation [ " shapes " ] [ 0 ] [ " id " ] = task_ann_prev . data [ " shapes " ] [ 0 ] [ " id " ]
response = self . _patch_api_v 1 _task_id_annotations( task_id , annotation , DELETE_ACTION , user )
response = self . _patch_api_v 2 _task_id_annotations( task_id , annotation , DELETE_ACTION , user )
self . assertEqual ( response . status_code , edata [ " code " ] )
if edata [ " annotation_changed " ] :
@ -447,7 +447,7 @@ class Task3DTest(_DbTestBase):
task_ann . init_from_db ( )
self . assertTrue ( len ( task_ann . data [ " shapes " ] ) == 0 )
def test_api_v 1 _create_annotation_in_jobs( self ) :
def test_api_v 2 _create_annotation_in_jobs( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -456,7 +456,7 @@ class Task3DTest(_DbTestBase):
jobs = self . _get_jobs ( task_id )
for user , edata in list ( self . expected_action . items ( ) ) :
with self . subTest ( format = edata [ " name " ] ) :
response = self . _patch_api_v 1 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , CREATE_ACTION , user )
response = self . _patch_api_v 2 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , CREATE_ACTION , user )
self . assertEqual ( response . status_code , edata [ " code " ] )
task_ann = TaskAnnotation ( task_id )
@ -467,7 +467,7 @@ class Task3DTest(_DbTestBase):
self . assertEqual ( task_shape , annotation [ " shapes " ] [ 0 ] )
self . _remove_annotations ( task_id )
def test_api_v 1 _update_annotation_in_job( self ) :
def test_api_v 2 _update_annotation_in_job( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -475,7 +475,7 @@ class Task3DTest(_DbTestBase):
jobs = self . _get_jobs ( task_id )
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
for user , edata in list ( self . expected_action . items ( ) ) :
@ -486,7 +486,7 @@ class Task3DTest(_DbTestBase):
annotation [ " shapes " ] [ 0 ] [ " points " ] = [ x + 0.1 for x in annotation [ " shapes " ] [ 0 ] [ " points " ] ]
annotation [ " shapes " ] [ 0 ] [ " id " ] = task_ann_prev . data [ " shapes " ] [ 0 ] [ " id " ]
response = self . _patch_api_v 1 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , UPDATE_ACTION , user )
response = self . _patch_api_v 2 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , UPDATE_ACTION , user )
self . assertEqual ( response . status_code , edata [ " code " ] )
if edata [ " annotation_changed " ] :
@ -494,7 +494,7 @@ class Task3DTest(_DbTestBase):
task_ann . init_from_db ( )
self . assertEqual ( task_ann . data [ " shapes " ] , annotation [ " shapes " ] )
def test_api_v 1 _remove_annotation_in_job( self ) :
def test_api_v 2 _remove_annotation_in_job( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -504,13 +504,13 @@ class Task3DTest(_DbTestBase):
for user , edata in list ( self . expected_action . items ( ) ) :
with self . subTest ( format = edata [ " name " ] ) :
response = self . _patch_api_v 1 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , CREATE_ACTION , self . admin )
response = self . _patch_api_v 2 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , CREATE_ACTION , self . admin )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )
annotation [ " shapes " ] [ 0 ] [ " id " ] = task_ann_prev . data [ " shapes " ] [ 0 ] [ " id " ]
response = self . _patch_api_v 1 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , DELETE_ACTION , user )
response = self . _patch_api_v 2 _job_id_annotations( jobs [ 0 ] [ " id " ] , annotation , DELETE_ACTION , user )
self . assertEqual ( response . status_code , edata [ " code " ] )
if edata [ " annotation_changed " ] :
@ -518,7 +518,7 @@ class Task3DTest(_DbTestBase):
task_ann . init_from_db ( )
self . assertTrue ( len ( task_ann . data [ " shapes " ] ) == 0 )
def test_api_v 1 _dump_and_upload_annotation( self ) :
def test_api_v 2 _dump_and_upload_annotation( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -526,7 +526,7 @@ class Task3DTest(_DbTestBase):
for format_name in self . format_names :
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )
@ -571,7 +571,7 @@ class Task3DTest(_DbTestBase):
self . assertEqual ( len ( task_ann_prev . data [ " shapes " ] ) , len ( task_ann . data [ " shapes " ] ) )
self . assertEqual ( task_ann_prev . data [ " shapes " ] , task_ann . data [ " shapes " ] )
def test_api_v 1 _rewrite_annotation( self ) :
def test_api_v 2 _rewrite_annotation( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -579,7 +579,7 @@ class Task3DTest(_DbTestBase):
for format_name in self . format_names :
with self . subTest ( format = f " { format_name } " ) :
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )
@ -596,7 +596,7 @@ class Task3DTest(_DbTestBase):
# rewrite annotation
annotation_copy = copy . deepcopy ( annotation )
annotation_copy [ " shapes " ] [ 0 ] [ " points " ] = [ 0 ] * 16
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation_copy )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation_copy )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
file_name = osp . join ( test_dir , f " { format_name } .zip " )
@ -612,7 +612,7 @@ class Task3DTest(_DbTestBase):
self . assertEqual ( len ( task_ann_prev . data [ " shapes " ] ) , len ( task_ann . data [ " shapes " ] ) )
self . assertEqual ( task_ann_prev . data [ " shapes " ] , task_ann . data [ " shapes " ] )
def test_api_v 1 _dump_and_upload_empty_annotation( self ) :
def test_api_v 2 _dump_and_upload_empty_annotation( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -643,7 +643,7 @@ class Task3DTest(_DbTestBase):
self . assertEqual ( len ( task_ann . data [ " shapes " ] ) , 0 )
self . assertEqual ( task_ann_prev . data [ " shapes " ] , task_ann . data [ " shapes " ] )
def test_api_v 1 _dump_and_upload_several_jobs( self ) :
def test_api_v 2 _dump_and_upload_several_jobs( self ) :
job_test_cases = [ " first " , " all " ]
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
@ -656,10 +656,10 @@ class Task3DTest(_DbTestBase):
jobs = self . _get_jobs ( task_id )
if job_test_case == " all " :
for job in jobs :
response = self . _put_api_v 1 _job_id_annotations( job [ " id " ] , annotation )
response = self . _put_api_v 2 _job_id_annotations( job [ " id " ] , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
else :
response = self . _put_api_v 1 _job_id_annotations( jobs [ 1 ] [ " id " ] , annotation )
response = self . _put_api_v 2 _job_id_annotations( jobs [ 1 ] [ " id " ] , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )
@ -673,7 +673,7 @@ class Task3DTest(_DbTestBase):
self . _remove_annotations ( task_id )
def test_api_v 1 _upload_annotation_with_attributes( self ) :
def test_api_v 2 _upload_annotation_with_attributes( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task_with_attributes , task_data )
@ -681,7 +681,7 @@ class Task3DTest(_DbTestBase):
for format_name in self . format_names :
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )
@ -711,7 +711,7 @@ class Task3DTest(_DbTestBase):
self . assertEqual ( task_ann_prev . data [ " shapes " ] [ 0 ] [ " attributes " ] ,
task_ann . data [ " shapes " ] [ 0 ] [ " attributes " ] )
def test_api_v 1 _export_dataset( self ) :
def test_api_v 2 _export_dataset( self ) :
with TestDir ( ) as test_dir :
task_data = self . copy_pcd_file_and_get_task_data ( test_dir )
task = self . _create_task ( self . task , task_data )
@ -719,7 +719,7 @@ class Task3DTest(_DbTestBase):
for format_name in self . format_names :
annotation = self . _get_tmp_annotation ( task , self . cuboid_example )
response = self . _put_api_v 1 _task_id_annotations( task_id , annotation )
response = self . _put_api_v 2 _task_id_annotations( task_id , annotation )
self . assertEqual ( response . status_code , status . HTTP_200_OK )
task_ann_prev = TaskAnnotation ( task_id )
task_ann_prev . init_from_db ( )