def test_create(client: CouchClient, async_run: Callable): response = async_run(client.doc_create_or_update( db_name, doc_name, dict(val=1) )) assert response.status_code == 201 assert response.model.id == doc_name assert response.model.rev is not None response = async_run(client.doc_create_or_update( db_name, doc_name, dict(val=2), rev=response.model.rev )) assert response.status_code == 201 assert response.model.ok is True _rev = response.model.rev response = async_run(client.doc_create_or_update( db_name, doc_name, dict(val=2), rev='2342&###&&&(**88' )) assert response.status_code == 400 response = async_run(client.doc_create_or_update( db_name, doc_name, dict(val=2), rev='non_existing_revision' )) assert response.status_code == 400 response = async_run(client.doc_create_or_update( db_name, doc_name, dict(val=2), rev=_rev, batch='ok' )) assert response.status_code == 202 assert response.model.ok is True
def prepare_all(client: CouchClient, async_run: Callable): response = async_run(client.db_create(db_name)) assert response.status_code == 201 response = async_run(client.doc_create_or_update( db_name, f'_design/{design_name}', design_body)) assert response.status_code == 201 yield response = async_run(client.db_delete(db_name)) assert response.status_code == 200
def test_create_with_attachments(client: CouchClient, async_run: Callable): attachments = MultipartRelatedAttachment( name=b'text', data=b'test_text', mime_type=b'text/plain') response = async_run(client.doc_create_or_update( db_name, doc_with_attachments, dict(val=-1), attachments=[attachments] )) assert response.status_code == 201 assert response.model.ok is True response = async_run(client.doc_get( db_name, doc_with_attachments, attachments=True)) assert response.status_code == 200 assert response.model._files[1].decode() == attachments.data