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
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
def document_schema(): return DocumentSchema()
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
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
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]
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
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
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
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
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]