def create_annotation(self, project_id: int, document_id: int, user_name: str, content: IO, annotation_format: str = InceptionFormat.DEFAULT, annotation_state: str = AnnotationState.DEFAULT): response = self.client.post(f"/projects/{project_id}/documents/{document_id}/annotations/{user_name}", form_data={'format': annotation_format, 'state': annotation_state}, files={"content": ('test/path', content)}, allowed_statuses=(201, 200)) annotation = AnnotationSchema().load(response.json()['body'], many=False) annotation.project_id = project_id annotation.document_id = document_id return annotation
def annotations(self, project_id: int, document_id: int) -> List[Annotation]: response = self.client.get(f'/projects/{project_id}/documents/{document_id}/annotations', allowed_statuses=(200,)) annotation_list = AnnotationSchema().load(response.json()['body'], many=True) for annotation in annotation_list: annotation.project_id = project_id annotation.document_id = document_id return annotation_list
def annotations(self, project: Union[Project, int], document: Union[Document, int]) -> List[Annotation]: project_id = self._get_object_id(project) document_id = self._get_object_id(document) response = self.client.get( f'/projects/{project_id}/documents/{document_id}/annotations', allowed_statuses=(200, )) annotation_list = AnnotationSchema().load(response.json()['body'], many=True) for annotation in annotation_list: annotation.project_id = project_id annotation.document_id = document_id return annotation_list
def annotation_schema(): return AnnotationSchema()
def test_annotation_schema_dump_none_datetime_as_null( annotation_schema: AnnotationSchema, deserialized_annotation: Annotation): deserialized_annotation.timestamp = None assert annotation_schema.dump(deserialized_annotation)['timestamp'] is None
def test_annotation_schema_load_null_datetime_as_none( annotation_schema: AnnotationSchema, serialized_annotation: dict): serialized_annotation['timestamp'] = None annotation = annotation_schema.load(serialized_annotation) assert annotation.timestamp is None
def test_annotation_schema_load_list_of_dicts_many_true( annotation_schema: AnnotationSchema, serialized_annotation: dict): assert type(annotation_schema.load([serialized_annotation], many=True)[0]) is Annotation
def test_annotation_schema_load_list_no_empty_many_true( annotation_schema: AnnotationSchema, serialized_annotation: dict): assert len(annotation_schema.load([serialized_annotation], many=True)) == 1
def test_annotation_schema_load_one_dict_many_true( annotation_schema: AnnotationSchema, deserialized_annotation: Annotation, serialized_annotation: dict): assert annotation_schema.load([serialized_annotation], many=True) == [deserialized_annotation]
def test_annotation_schema_load_one_dict_many_false( annotation_schema: AnnotationSchema, deserialized_annotation: Annotation, serialized_annotation: dict): assert annotation_schema.load( serialized_annotation) == deserialized_annotation
def test_annotation_schema_dump_one_dict_many_false( annotation_schema: AnnotationSchema, deserialized_annotation: Annotation, serialized_annotation: dict): assert annotation_schema.dump( deserialized_annotation) == serialized_annotation
def test_annotation_schema_dump_list_of_dicts_many_true( annotation_schema: AnnotationSchema, deserialized_annotation: Annotation): assert type( annotation_schema.dump([deserialized_annotation], many=True)[0]) is dict
def test_annotation_schema_dump_list_no_empty_many_true( annotation_schema: AnnotationSchema, deserialized_annotation: Annotation): assert len(annotation_schema.dump([deserialized_annotation], many=True)) == 1