Example #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
Example #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
Example #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
Example #4
0
def annotation_schema():
    return AnnotationSchema()
Example #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
Example #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
Example #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
Example #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
Example #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]
Example #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
Example #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
Example #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
Example #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