def test_update_moves_document_to_another_folder(self, sample_doc, home_folder): assert sample_doc not in home_folder.documents DocumentsManager.update(sample_doc, folder=home_folder.id) assert sample_doc.folder == home_folder assert sample_doc in home_folder.documents
def test_update_ignores_empty_data(self, mocker, sample_doc, other_user): orig_title = sample_doc.title orig_description = sample_doc.description orig_editor = sample_doc.editor orig_updated = sample_doc.updated with mocker.patch("doxapi.managers.get_current_user", return_value=other_user): DocumentsManager.update(sample_doc) assert sample_doc.title == orig_title assert sample_doc.description == orig_description assert sample_doc.editor == orig_editor assert sample_doc.updated == orig_updated
def test_update_modifies_existing_document(self, sample_doc, modified_properties, user): orig_title = sample_doc.title orig_payload = sample_doc.payload orig_description = sample_doc.description DocumentsManager.update(sample_doc, **modified_properties) assert sample_doc.title == modified_properties.get("title", orig_title) assert sample_doc.payload == modified_properties.get( "payload", orig_payload) assert sample_doc.description == modified_properties.get( "description", orig_description) assert sample_doc.created < sample_doc.updated assert sample_doc.editor == user assert sample_doc == Document.query.get(sample_doc.id)
def post(self): if "folder" in api.payload: folder = FoldersManager.get(api.payload["folder"]) del api.payload["folder"] else: folder = FoldersManager.get_root() document = DocumentsManager.create(folder, **api.payload) return document.dump_ref(), 201
def delete(self, document_id): DocumentsManager.delete(document_id)
def put(self, document_id): document = DocumentsManager.get(document_id) DocumentsManager.update(document, **api.payload)
def get(self, document_id): return DocumentsManager.get_dump(document_id)
def get(self): return [doc.dump_ref() for doc in DocumentsManager.get_all()]
def test_get_all_returns_doc_list(self, sample_doc): result = DocumentsManager.get_all() assert isinstance(result, list) assert len(result) == 1 assert result[0] == sample_doc
def test_create_raises_conflict_error_for_duplicated_title( self, folder, sample_doc): with pytest.raises(Conflict): DocumentsManager.create(folder, title=sample_doc.title)
def sample_doc(folder, doc_data): return DocumentsManager.create(folder, **doc_data)
def test_get_all_returns_empty_list(self): result = DocumentsManager.get_all() assert result == []
def test_get_raises_not_found_error_for_non_existing_doc(self): with pytest.raises(NotFound): DocumentsManager.get(1)
def test_get_returns_doc(self, sample_doc): result = DocumentsManager.get(sample_doc.id) assert result == sample_doc
def test_update_raises_conflict_error_for_duplicated_title( self, folder, sample_doc): test_doc = DocumentsManager.create(folder, title="Do not duplicate") with pytest.raises(Conflict): DocumentsManager.update(sample_doc, title=test_doc.title)