예제 #1
0
 def create_document(self, project_id: int, document_name: str, content: IO,
                     document_format: str = InceptionFormat.DEFAULT, document_state: str = DocumentState.DEFAULT):
     response = self.client.post(f"/projects/{project_id}/documents", form_data={"name": document_name,
                                                                                 "format": document_format,
                                                                                 "state": document_state},
                                 files={"content": ('test/path', content)},
                                 allowed_statuses=(201, 200))
     document = DocumentSchema().load(response.json()['body'], many=False)
     document.project_id = project_id
     return document
예제 #2
0
 def documents(self, project: Union[Project, int]) -> List[Document]:
     project_id = self._get_object_id(project)
     response = self.client.get(f'/projects/{project_id}/documents',
                                allowed_statuses=(200, ))
     document_list = DocumentSchema().load(response.json()['body'],
                                           many=True)
     for document in document_list:
         document.project_id = project_id
     return document_list
예제 #3
0
def document_schema():
    return DocumentSchema()
예제 #4
0
def test_document_schema_load_list_of_dicts_many_true(
        document_schema: DocumentSchema, serialized_document: dict):
    assert type(document_schema.load([serialized_document],
                                     many=True)[0]) is Document
예제 #5
0
def test_document_schema_load_list_no_empty_many_true(
        document_schema: DocumentSchema, serialized_document: dict):
    assert len(document_schema.load([serialized_document], many=True)) == 1
예제 #6
0
def test_document_schema_load_one_dict_many_true(
        document_schema: DocumentSchema, deserialized_document: Document,
        serialized_document: dict):
    assert document_schema.load([serialized_document],
                                many=True) == [deserialized_document]
예제 #7
0
def test_document_schema_dump_one_dict_many_false(
        document_schema: DocumentSchema, deserialized_document: Document,
        serialized_document: dict):
    assert document_schema.dump(deserialized_document) == serialized_document
예제 #8
0
def test_document_schema_load_one_dict_many_false(
        document_schema: DocumentSchema, deserialized_document: Document,
        serialized_document: dict):
    assert document_schema.load(serialized_document) == deserialized_document
예제 #9
0
def test_document_schema_dump_list_of_dicts_many_true(
        document_schema: DocumentSchema, deserialized_document: Document):
    assert type(document_schema.dump([deserialized_document],
                                     many=True)[0]) is dict
예제 #10
0
def test_document_schema_dump_list_no_empty_many_true(
        document_schema: DocumentSchema, deserialized_document: Document):
    assert len(document_schema.dump([deserialized_document], many=True)) == 1
예제 #11
0
def test_document_schema_dump_one_dict_many_true(
        document_schema: DocumentSchema, deserialized_document: Document,
        serialized_document: dict):
    assert document_schema.dump([deserialized_document],
                                many=True) == [serialized_document]