Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MDocument
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yury
MDocument
Commits
588ac57b
Commit
588ac57b
authored
Jul 25, 2020
by
Yury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
document: add to_json convert method
parent
cfe23d5f
Pipeline
#339
failed with stages
in 3 minutes and 54 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
mdocument/document.py
mdocument/document.py
+9
-2
tests/document_test.py
tests/document_test.py
+20
-0
No files found.
mdocument/document.py
View file @
588ac57b
...
...
@@ -270,10 +270,10 @@ class Document(metaclass=MetaDocument):
@
classmethod
@
check_setup
async
def
many
(
cls
,
**
kwargs
)
->
list
:
async
def
many
(
cls
,
**
kwargs
)
->
DocumentArray
:
"""Finds multiple documents based on kwargs."""
result_list
=
[]
result_list
=
DocumentArray
()
cursor
=
cls
.
collection
.
find
(
kwargs
)
async
for
doc
in
cursor
:
result_list
.
append
(
cls
(
**
doc
))
...
...
@@ -344,3 +344,10 @@ class Document(metaclass=MetaDocument):
return
result
return
func_wrapper
def
to_json
(
self
):
_id
=
self
.
_id
result
=
{
"_id"
:
str
(
self
.
_document_
.
__data__
.
pop
(
"_id"
))}
result
.
update
(
self
.
_document_
.
__data__
)
self
.
_document_
[
"_id"
]
=
_id
return
result
tests/document_test.py
View file @
588ac57b
...
...
@@ -352,3 +352,23 @@ async def test_create_indexes(client):
}
indexes
=
await
Video
.
collection
.
index_information
()
assert
indexes
.
get
(
"user_1_value_1"
)
==
user_1_value_1
@
pytest
.
mark
.
asyncio
async
def
test_to_json
(
client
):
test_client
=
client
class
Video
(
Document
):
client
=
test_client
collection
=
"videos"
database
=
"mdocument"
video
=
await
Video
.
create
(
name
=
"movie"
,
awards
=
3
,
bytes
=
b
"123"
)
assert
video
.
to_json
()
==
{
"_id"
:
str
(
video
.
_id
),
"name"
:
"movie"
,
"awards"
:
3
,
"bytes"
:
b
"123"
,
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment