|
| 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