-
Notifications
You must be signed in to change notification settings - Fork 3
test #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
test #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
@@ -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], | ||
| 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 | ||
|
|
@@ -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] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
|
|
@@ -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], | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут вообще поле передачи данных было пропущено |
||
| path={'db': db}, | ||
| response_model=ExecuteViewResponse | ||
| ) | ||
|
|
@@ -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', | ||
|
|
||
| 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. | ||
|
|
@@ -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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
| 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' | ||
|
|
@@ -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])) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужно внимательно смотреть, какие из параметров являются обязательными