Skip to content

Commit 1dd2910

Browse files
authored
Merge pull request #3 from marklogic/feature/test-get-documents
Added simple tests for getting many documents back at once
2 parents d4c5f07 + 3cc1f6f commit 1dd2910

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*=test-data
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"hello": "world"
3+
}

test-app/src/main/ml-data/doc2.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<hello>world</hello>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*=rest-reader,read,rest-writer,update

tests/test_get_documents.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from requests_toolbelt.multipart.decoder import MultipartDecoder
2+
3+
4+
def test_get_docs(test_session):
5+
"""
6+
Possible future client interface:
7+
array_of_documents = client.documents.get(uri=[], metadata=True)
8+
9+
Where each Document in the array would have fields of:
10+
uri/content/collections/permissions/quality/properties/metadata_values.
11+
"""
12+
response = test_session.get(
13+
"http://localhost:8030/v1/documents",
14+
params={
15+
"uri": ["/doc1.json", "/doc2.xml"],
16+
"category": ["content", "metadata"],
17+
"format": "json", # Applies only to metadata
18+
},
19+
headers={"Accept": "multipart/mixed"},
20+
)
21+
22+
# Could provide a class for converting a multipart/mixed response into an array
23+
# of documents too:
24+
# from marklogic import DocumentDecoder
25+
# array_of_documents = DocumentDecoder.from_response(response)
26+
27+
decoder = MultipartDecoder.from_response(response)
28+
for part in decoder.parts:
29+
print(part.headers)
30+
print(part.text)
31+
32+
33+
def test_search_docs(test_session):
34+
response = test_session.get(
35+
"http://localhost:8030/v1/search",
36+
params={
37+
"collection": "test-data",
38+
"category": ["content", "metadata"],
39+
"format": "json", # Applies only to metadata
40+
},
41+
headers={"Accept": "multipart/mixed"}, # Indicates we want documents back.
42+
)
43+
44+
for part in MultipartDecoder.from_response(response).parts:
45+
print(part.headers)
46+
print(part.text)

0 commit comments

Comments
 (0)