Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions async_couch/clients/database/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from async_couch.clients.designs.responses import ExecuteViewResponse
from async_couch.http_clients.base_client import BaseEndpoint
from . import responses as resp
from . import models


class DatabaseEndpoint(BaseEndpoint):
Expand Down Expand Up @@ -551,8 +552,8 @@ async def db_design_docs(self,

async def db_bulk_get(self,
db: str,
revs: bool = None,
id: int = None) -> types.UniversalResponse:
docs: typing.List[models.Doc],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно внимательно смотреть, какие из параметров являются обязательными

revs: bool = None) -> types.UniversalResponse:
"""
This method can be called to query several documents in bulk. It is
well suited for fetching a specific revision of documents, as
Expand Down Expand Up @@ -581,13 +582,11 @@ async def db_bulk_get(self,
if revs:
query['revs'] = revs

result = dict()

if id:
result['id'] = id
json_data = dict()
json_data['docs'] = [item.dump() for item in docs]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

неправильное обьявление json-данных


return await self.http_client.make_request(
endpoint='/db/_bulk_get',
endpoint='/{db}/_bulk_get',
method=types.HttpMethod.POST,
statuses={
200: 'Request completed successfully',
Expand All @@ -599,14 +598,14 @@ async def db_bulk_get(self,
},
query=query,
path={'db': db},
json_data=result,
json_data=json_data,
response_model=ExecuteViewResponse
)

async def db_bulk_docs(self,
db: str,
docs: list,
new_edits: bool=True) -> types.UniversalResponse:
docs: typing.List[models.ExtendedDoc],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нужно сделать нормальные модели для запросов, если речь идет о POST-запросе

new_edits: bool = True) -> types.UniversalResponse:

"""
The bulk document API allows you to create and update multiple
Expand Down Expand Up @@ -641,21 +640,22 @@ async def db_bulk_docs(self,
"""

query = dict()

if docs:
query['docs'] = docs
if new_edits:
query['new_edits'] = new_edits

json_data = dict()
json_data['docs'] = [item.dump() for item in docs]

return await self.http_client.make_request(
endpoint='/db/_bulk_docs',
endpoint='/{db}/_bulk_docs',
method=types.HttpMethod.POST,
statuses={
201: 'Document(s) have been created or updated',
401: 'The request provided invalid JSON data',
404: 'Requested database not found'
},
query=query,
json_data=json_data,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут вообще поле передачи данных было пропущено

path={'db': db},
response_model=ExecuteViewResponse
)
Expand Down Expand Up @@ -777,7 +777,7 @@ async def db_find(self,
json_data['selector'] = selector

return await self.http_client.make_request(
endpoint='/db/_find',
endpoint='/{db}/_find',
method=types.HttpMethod.POST,
statuses={
200: 'Request completed successfully',
Expand Down
22 changes: 22 additions & 0 deletions async_couch/clients/database/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from dataclasses import dataclass


class ClusterObject:
n: int
# Replicas. The number of copies of every document.
Expand Down Expand Up @@ -30,3 +33,22 @@ class DatabaseProps:
partitioned: bool
# (optional) If present and true, this indicates that the database
# is partitioned.


@dataclass()
class Doc:
id: str
rev: str = None

def dump(self):
return {'id': self.id, 'rev': self.rev}


@dataclass()
class ExtendedDoc:
_id: str
_rev: str = None
_deleted: bool = None
Comment on lines +39 to +51
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот так надо было сделать для этих POST-запросов модели. Еще надо найти готовые или создать ответы для этих же запросов


def dump(self):
return {'_id': self._id, '_rev': self._rev, '_deleted': self._deleted}
19 changes: 19 additions & 0 deletions tests/test_api/test_databases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Callable

from async_couch import CouchClient
from async_couch.clients.database import models as db_models


db_name = 'test_db_01'
Expand Down Expand Up @@ -52,11 +53,29 @@ def test_all_docs(async_run: Callable, client: CouchClient):


def test_design_docs(async_run: Callable, client: CouchClient):
# todo: type of keys is invalid
response = async_run(client.db_design_docs(db_name, keys=[doc_id]))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут неправильный тип данных передавался - список против словаря

assert response.status_code == 200
assert len(response.model.rows) == 1


def __test_bulk_get(async_run: Callable, client: CouchClient):
docs = [db_models.Doc(id=doc_id)]
response = async_run(client.db_bulk_get(db_name, docs=docs))
assert response.status_code == 200


def test_bulk_docs(async_run: Callable, client: CouchClient):
docs = [db_models.ExtendedDoc(_id=doc_id)]
response = async_run(client.db_bulk_docs(db_name, docs=docs))
assert response.status_code == 200


#def test_find(async_run: Callable, client: CouchClient):
#response = async_run(client.db_find(db_name, selector=[doc_id]))
#assert response.status_code == 200


def test_delete(async_run: Callable, client: CouchClient):
response = async_run(client.db_delete(db_name))
assert response.status_code == 200
Expand Down