Exemple #1
0
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
Exemple #2
0
def database(client: CouchClient, async_run: Callable):
    response = async_run(client.db_create(db_name))
    assert response.status_code == 201

    yield

    response = async_run(client.db_delete(db_name))
    assert response.status_code == 200
Exemple #3
0
def test_delete(async_run: Callable, client: CouchClient):
    response = async_run(client.db_delete(db_name))
    assert response.status_code == 200

    response = async_run(client.db_delete(invalid_db_name))
    assert response.status_code == 404

    response = async_run(client.db_delete(non_existing_db))
    assert response.status_code == 404
Exemple #4
0
def test_delete(client: CouchClient, async_run: Callable):
    doc = async_run(client.doc_get(db_name, doc_name))
    assert doc.status_code == 200

    response = async_run(client.doc_delete(db_name, doc_name, doc.model._rev))
    assert response.status_code == 200
    assert response.model.ok is True

    response = async_run(client.doc_delete(db_name, doc_name, doc.model._rev))
    assert response.status_code == 404
Exemple #5
0
def test_create(async_run: Callable, client: CouchClient):
    response = async_run(client.db_create(invalid_db_name))
    assert response.status_code == 400

    response = async_run(client.db_create(db_name))
    assert response.status_code == 201
    assert response.json().get('ok') is True

    response = async_run(client.db_create(db_name))
    assert response.status_code == 412
Exemple #6
0
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
Exemple #7
0
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
Exemple #8
0
def test_create_doc(async_run: Callable, client: CouchClient):
    global doc_id
    doc = dict(test=True)

    response = async_run(client.db_create_doc(db_name, doc))
    assert response.status_code == 201

    doc_id = response.model.id

    response = async_run(client.db_create_doc(db_name, doc, batch='ok'))
    assert response.status_code == 202

    response = async_run(client.db_create_doc(non_existing_db, doc))
    assert response.status_code == 404
Exemple #9
0
def test_get(client: CouchClient, async_run: Callable):
    response = async_run(client.doc_get(db_name, doc_name,
                                        attachments=True,
                                        att_encoding_info=True,
                                        conflicts=True,
                                        deleted_conflicts=True,
                                        latest=True,
                                        local_seq=True,
                                        meta=True,
                                        revs=True,
                                        revs_info=True))
    assert response.status_code == 200
    assert response.model._id == doc_name
    assert response.model.doc.get('val') == 2

    response = async_run(client.doc_get(db_name, 'invalid_%%%_name'))
    assert response.status_code == 404

    response = async_run(client.doc_get(db_name, 'non_existing'))
    assert response.status_code == 404
Exemple #10
0
def test_copy(client: CouchClient, async_run: Callable):
    original = async_run(client.doc_get(db_name, doc_name))
    assert original.status_code == 200

    response = async_run(client.doc_copy(
        db_name, doc_name, 'test_copy', rev=original.model._rev))
    assert response.model.ok is True
    assert response.status_code == 201

    copied = async_run(client.doc_get(db_name, 'test_copy'))
    assert copied.status_code == 200
    assert copied.model.doc.get('val') == original.model.doc.get('val')
    assert copied.model.doc.get('val') == 2

    response = async_run(client.doc_copy(
        db_name, doc_name, 'test_copy2', batch='ok'))
    assert response.model.ok is True
    # todo: returns 201 rather then 202
    # assert response.status_code == 202

    response = async_run(client.doc_copy(
        db_name, 'non_existing', 'test_new_copy'))
    assert response.status_code == 404
Exemple #11
0
def test_view_exec(client: CouchClient, async_run: Callable):
    result = async_run(client.view_exec(db_name, design_name, 'test_view'))

    assert result.status_code == 200
    assert result.model.total_rows == 0
Exemple #12
0
def test_design_info(client: CouchClient, async_run: Callable):
    result = async_run(client.des_info(db_name, design_name))

    assert result.status_code == 200
    assert result.model.name == 'test_design_doc'
    assert result.model.view_index.get('language') == 'javascript'
Exemple #13
0
def test_exists(client: CouchClient, async_run: Callable):
    response = async_run(client.doc_exists(db_name, doc_name))
    assert response.status_code == 200

    response = async_run(client.doc_exists(db_name, 'non_existing_doc'))
    assert response.status_code == 404
Exemple #14
0
def test_design_docs(async_run: Callable, client: CouchClient):
    response = async_run(client.db_design_docs(db_name, keys=[doc_id]))
    assert response.status_code == 200
    assert len(response.model.rows) == 1
Exemple #15
0
def test_existing(async_run: Callable, client: CouchClient):
    response = async_run(client.db_exists(non_existing_db))
    assert response.status_code == 404

    response = async_run(client.db_exists(db_name))
    assert response.status_code == 200