@ -1177,7 +1177,7 @@ class JobAnnotationAPITestCase(APITestCase):
" mutable " : False ,
" input_type " : " select " ,
" default_value " : " mazda " ,
" values " : [ " bmw " , " mazda " , " ren o " ]
" values " : [ " bmw " , " mazda " , " ren ault " ]
} ,
{
" name " : " parked " ,
@ -1212,6 +1212,27 @@ class JobAnnotationAPITestCase(APITestCase):
return ( task , jobs )
@staticmethod
def _get_default_attr_values ( task ) :
default_attr_values = { }
for label in task [ " labels " ] :
default_attr_values [ label [ " id " ] ] = {
" mutable " : [ ] ,
" immutable " : [ ] ,
" all " : [ ] ,
}
for attr in label [ " attributes " ] :
default_value = {
" spec_id " : attr [ " id " ] ,
" value " : attr [ " default_value " ] ,
}
if attr [ " mutable " ] :
default_attr_values [ label [ " id " ] ] [ " mutable " ] . append ( default_value )
else :
default_attr_values [ label [ " id " ] ] [ " immutable " ] . append ( default_value )
default_attr_values [ label [ " id " ] ] [ " all " ] . append ( default_value )
return default_attr_values
def _put_api_v1_jobs_id_data ( self , jid , user , data ) :
with ForceLogin ( user , self . client ) :
response = self . client . put ( " /api/v1/jobs/ {} /annotations " . format ( jid ) ,
@ -1288,7 +1309,7 @@ class JobAnnotationAPITestCase(APITestCase):
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
}
] ,
" points " : [ 1.0 , 2.1 , 100 , 300.222 ] ,
@ -1310,7 +1331,12 @@ class JobAnnotationAPITestCase(APITestCase):
" frame " : 0 ,
" label_id " : task [ " labels " ] [ 0 ] [ " id " ] ,
" group " : None ,
" attributes " : [ ] ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
] ,
" shapes " : [
{
" frame " : 0 ,
@ -1319,14 +1345,10 @@ class JobAnnotationAPITestCase(APITestCase):
" occluded " : False ,
" outside " : False ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
}
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
} ,
]
} ,
{
@ -1357,6 +1379,8 @@ class JobAnnotationAPITestCase(APITestCase):
} ,
]
}
default_attr_values = self . _get_default_attr_values ( task )
response = self . _put_api_v1_jobs_id_data ( job [ " id " ] , annotator , data )
data [ " version " ] + = 1 # need to update the version
self . assertEqual ( response . status_code , HTTP_200_OK )
@ -1364,6 +1388,9 @@ class JobAnnotationAPITestCase(APITestCase):
response = self . _get_api_v1_jobs_id_data ( job [ " id " ] , annotator )
self . assertEqual ( response . status_code , HTTP_200_OK )
# server should add default attribute values if puted data doesn't contain it
data [ " tags " ] [ 0 ] [ " attributes " ] = default_attr_values [ data [ " tags " ] [ 0 ] [ " label_id " ] ] [ " all " ]
data [ " tracks " ] [ 0 ] [ " shapes " ] [ 1 ] [ " attributes " ] = default_attr_values [ data [ " tracks " ] [ 0 ] [ " label_id " ] ] [ " mutable " ]
self . _check_response ( response , data )
response = self . _delete_api_v1_jobs_id_data ( job [ " id " ] , annotator )
@ -1402,7 +1429,7 @@ class JobAnnotationAPITestCase(APITestCase):
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
}
] ,
" points " : [ 1.0 , 2.1 , 100 , 300.222 ] ,
@ -1424,7 +1451,12 @@ class JobAnnotationAPITestCase(APITestCase):
" frame " : 0 ,
" label_id " : task [ " labels " ] [ 0 ] [ " id " ] ,
" group " : None ,
" attributes " : [ ] ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
] ,
" shapes " : [
{
" frame " : 0 ,
@ -1433,14 +1465,10 @@ class JobAnnotationAPITestCase(APITestCase):
" occluded " : False ,
" outside " : False ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
}
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
} ,
]
} ,
{
@ -1479,6 +1507,9 @@ class JobAnnotationAPITestCase(APITestCase):
response = self . _get_api_v1_jobs_id_data ( job [ " id " ] , annotator )
self . assertEqual ( response . status_code , HTTP_200_OK )
# server should add default attribute values if puted data doesn't contain it
data [ " tags " ] [ 0 ] [ " attributes " ] = default_attr_values [ data [ " tags " ] [ 0 ] [ " label_id " ] ] [ " all " ]
data [ " tracks " ] [ 0 ] [ " shapes " ] [ 1 ] [ " attributes " ] = default_attr_values [ data [ " tracks " ] [ 0 ] [ " label_id " ] ] [ " mutable " ]
self . _check_response ( response , data )
data = response . data
@ -1576,7 +1607,7 @@ class JobAnnotationAPITestCase(APITestCase):
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
}
]
} ,
@ -1733,7 +1764,12 @@ class TaskAnnotationAPITestCase(JobAnnotationAPITestCase):
" frame " : 0 ,
" label_id " : task [ " labels " ] [ 0 ] [ " id " ] ,
" group " : None ,
" attributes " : [ ] ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
] ,
" shapes " : [
{
" frame " : 0 ,
@ -1742,13 +1778,9 @@ class TaskAnnotationAPITestCase(JobAnnotationAPITestCase):
" occluded " : False ,
" outside " : False ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
}
]
} ,
@ -1782,10 +1814,15 @@ class TaskAnnotationAPITestCase(JobAnnotationAPITestCase):
}
response = self . _put_api_v1_tasks_id_annotations ( task [ " id " ] , annotator , data )
data [ " version " ] + = 1
self . assertEqual ( response . status_code , HTTP_200_OK )
self . _check_response ( response , data )
default_attr_values = self . _get_default_attr_values ( task )
response = self . _get_api_v1_tasks_id_annotations ( task [ " id " ] , annotator )
# server should add default attribute values if puted data doesn't contain it
data [ " tags " ] [ 0 ] [ " attributes " ] = default_attr_values [ data [ " tags " ] [ 0 ] [ " label_id " ] ] [ " all " ]
data [ " tracks " ] [ 0 ] [ " shapes " ] [ 1 ] [ " attributes " ] = default_attr_values [ data [ " tracks " ] [ 0 ] [ " label_id " ] ] [ " mutable " ]
self . assertEqual ( response . status_code , HTTP_200_OK )
self . _check_response ( response , data )
@ -1847,7 +1884,12 @@ class TaskAnnotationAPITestCase(JobAnnotationAPITestCase):
" frame " : 0 ,
" label_id " : task [ " labels " ] [ 0 ] [ " id " ] ,
" group " : None ,
" attributes " : [ ] ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
] ,
" shapes " : [
{
" frame " : 0 ,
@ -1856,13 +1898,9 @@ class TaskAnnotationAPITestCase(JobAnnotationAPITestCase):
" occluded " : False ,
" outside " : False ,
" attributes " : [
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " values " ] [ 0 ]
} ,
{
" spec_id " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " id " ] ,
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 0 ] [ " default_value " ]
" value " : task [ " labels " ] [ 0 ] [ " attributes " ] [ 1 ] [ " default_value " ]
}
]
} ,
@ -1901,6 +1939,9 @@ class TaskAnnotationAPITestCase(JobAnnotationAPITestCase):
self . _check_response ( response , data )
response = self . _get_api_v1_tasks_id_annotations ( task [ " id " ] , annotator )
# server should add default attribute values if puted data doesn't contain it
data [ " tags " ] [ 0 ] [ " attributes " ] = default_attr_values [ data [ " tags " ] [ 0 ] [ " label_id " ] ] [ " all " ]
data [ " tracks " ] [ 0 ] [ " shapes " ] [ 1 ] [ " attributes " ] = default_attr_values [ data [ " tracks " ] [ 0 ] [ " label_id " ] ] [ " mutable " ]
self . assertEqual ( response . status_code , HTTP_200_OK )
self . _check_response ( response , data )