示例#1
0
 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
示例#2
0
 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
示例#3
0
 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
示例#4
0
def annotation_schema():
    return AnnotationSchema()
示例#5
0
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
示例#6
0
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
示例#7
0
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
示例#8
0
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
示例#9
0
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]
示例#10
0
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
示例#11
0
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
示例#12
0
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
示例#13
0
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