33from marklogic import Client
44from marklogic .documents import Document
55
6-
7- @pytest .fixture (autouse = True )
8- def prepare_test_database (admin_client : Client ):
9- """
10- Deletes any documents created by other tests to ensure a 'clean' database before a
11- test runs. Does not delete documents in the 'test-data' collection which is intended
12- to contain all the documents loaded by the test-app. A user with the 'admin' role
13- is used so that temporal documents can be deleted.
14- """
15- query = "cts:uris((), (), cts:not-query(cts:collection-query('test-data'))) \
16- ! xdmp:document-delete(.)"
17- response = admin_client .post (
18- "v1/eval" ,
19- headers = {"Content-type" : "application/x-www-form-urlencoded" },
20- data = {"xquery" : query },
21- )
22- assert 200 == response .status_code
6+ DEFAULT_PERMS = {"python-tester" : ["read" , "update" ]}
237
248
259def test_write_json (client : Client ):
2610 # Verifies that JSON can be either a dict or a string.
2711 response = client .documents .write (
2812 [
29- Document ("/temp/doc1.json" , {"doc" : 1 }),
30- Document ("/temp/doc2.json" , '{"doc": 2}' ),
13+ Document ("/temp/doc1.json" , {"doc" : 1 }, permissions = DEFAULT_PERMS ),
14+ Document ("/temp/doc2.json" , '{"doc": 2}' , permissions = DEFAULT_PERMS ),
3115 ]
3216 )
3317
@@ -48,8 +32,8 @@ def test_return_xml(client: Client):
4832 the Content-type to multipart/mixed.
4933 """
5034 docs = [
51- Document ("/temp/doc1.json" , {"doc" : 1 }),
52- Document ("/temp/doc2.json" , {"doc" : 2 }),
35+ Document ("/temp/doc1.json" , {"doc" : 1 }, permissions = DEFAULT_PERMS ),
36+ Document ("/temp/doc2.json" , {"doc" : 2 }, permissions = DEFAULT_PERMS ),
5337 ]
5438 response = client .documents .write (docs , headers = {"Accept" : "application/xml" })
5539
@@ -60,8 +44,8 @@ def test_return_xml(client: Client):
6044def test_write_json_and_xml (client : Client ):
6145 response = client .documents .write (
6246 [
63- Document ("/temp/doc1.json" , {"doc" : 1 }),
64- Document ("/temp/doc2.xml" , "<doc>2</doc>" ),
47+ Document ("/temp/doc1.json" , {"doc" : 1 }, permissions = DEFAULT_PERMS ),
48+ Document ("/temp/doc2.xml" , "<doc>2</doc>" , permissions = DEFAULT_PERMS ),
6549 ]
6650 )
6751 assert 200 == response .status_code
@@ -79,8 +63,18 @@ def test_content_types(client: Client):
7963 """
8064 response = client .documents .write (
8165 [
82- Document ("/temp/doc1" , {"doc" : 1 }, content_type = "application/json" ),
83- Document ("/temp/doc2" , "<doc>2</doc>" , content_type = "application/xml" ),
66+ Document (
67+ "/temp/doc1" ,
68+ {"doc" : 1 },
69+ content_type = "application/json" ,
70+ permissions = DEFAULT_PERMS ,
71+ ),
72+ Document (
73+ "/temp/doc2" ,
74+ "<doc>2</doc>" ,
75+ content_type = "application/xml" ,
76+ permissions = DEFAULT_PERMS ,
77+ ),
8478 ]
8579 )
8680 assert 200 == response .status_code
@@ -92,16 +86,27 @@ def test_content_types(client: Client):
9286
9387
9488def test_single_doc (client ):
95- response = client .documents .write ([Document ("/temp/doc1.json" , {"doc" : 1 })])
89+ response = client .documents .write (
90+ [Document ("/temp/doc1.json" , {"doc" : 1 }, permissions = DEFAULT_PERMS )]
91+ )
9692 assert 200 == response .status_code
9793
9894 doc1 = client .get ("v1/documents?uri=/temp/doc1.json" ).json ()
9995 assert 1 == doc1 ["doc" ]
10096
10197
98+ @pytest .mark .skip ("Will get this working when supporting batch-level metadata" )
10299def test_server_generated_uri (client ):
103100 response = client .documents .write (
104- [Document (None , {"doc" : "serveruri" }, extension = ".json" , directory = "/temp/" )]
101+ [
102+ Document (
103+ None ,
104+ {"doc" : "serveruri" },
105+ extension = ".json" ,
106+ directory = "/temp/" ,
107+ permissions = DEFAULT_PERMS ,
108+ )
109+ ]
105110 )
106111 assert 200 == response .status_code
107112
@@ -116,7 +121,14 @@ def test_server_generated_uri(client):
116121
117122def test_repair_xml (client ):
118123 response = client .documents .write (
119- [Document ("/temp/doc1.xml" , "<doc>needs <b>closing tag</doc>" , repair = "full" )]
124+ [
125+ Document (
126+ "/temp/doc1.xml" ,
127+ "<doc>needs <b>closing tag</doc>" ,
128+ repair = "full" ,
129+ permissions = DEFAULT_PERMS ,
130+ )
131+ ]
120132 )
121133 assert 200 == response .status_code
122134
@@ -128,14 +140,25 @@ def test_repair_xml(client):
128140def test_extract_binary (client ):
129141 content = "MarkLogic and Python" .encode ("ascii" )
130142 response = client .documents .write (
131- [Document ("/temp/doc1.bin" , content , extract = "properties" )]
143+ [
144+ Document (
145+ "/temp/doc1.bin" ,
146+ content ,
147+ extract = "properties" ,
148+ permissions = DEFAULT_PERMS ,
149+ )
150+ ]
132151 )
133152 assert 200 == response .status_code
134153
135154
136155def test_optimistic_locking (client ):
137156 response = client .documents .write (
138- [Document ("/temp/doc1.json" , {"content" : "original" })]
157+ [
158+ Document (
159+ "/temp/doc1.json" , {"content" : "original" }, permissions = DEFAULT_PERMS
160+ )
161+ ]
139162 )
140163 assert 200 == response .status_code
141164
@@ -144,7 +167,14 @@ def test_optimistic_locking(client):
144167
145168 # Update the document, passing in the current version_id based on the ETag.
146169 response = client .documents .write (
147- [Document ("/temp/doc1.json" , {"content" : "updated!" }, version_id = etag )]
170+ [
171+ Document (
172+ "/temp/doc1.json" ,
173+ {"content" : "updated!" },
174+ version_id = etag ,
175+ permissions = DEFAULT_PERMS ,
176+ )
177+ ]
148178 )
149179 assert 200 == response .status_code
150180
@@ -154,7 +184,14 @@ def test_optimistic_locking(client):
154184
155185 # Next update should fail since the ETag is no longer the current version.
156186 response = client .documents .write (
157- [Document ("/temp/doc1.json" , {"this" : "should fail" }, version_id = etag )]
187+ [
188+ Document (
189+ "/temp/doc1.json" ,
190+ {"this" : "should fail" },
191+ version_id = etag ,
192+ permissions = DEFAULT_PERMS ,
193+ )
194+ ]
158195 )
159196 assert 412 == response .status_code , "412 is returned when the versionId is invalid."
160197 assert response .text .__contains__ ("RESTAPI-CONTENTWRONGVERSION" )
@@ -170,7 +207,14 @@ def test_temporal_doc(client):
170207 }
171208
172209 response = client .documents .write (
173- [Document ("/temp/doc1.json" , content , temporal_document = "custom1" )],
210+ [
211+ Document (
212+ "/temp/doc1.json" ,
213+ content ,
214+ temporal_document = "custom1" ,
215+ permissions = DEFAULT_PERMS ,
216+ )
217+ ],
174218 params = {"temporal-collection" : "temporal-collection" },
175219 )
176220 assert 200 == response .status_code
@@ -180,3 +224,7 @@ def test_temporal_doc(client):
180224 data = client .get ("/v1/search?collection=custom1&format=json" ).json ()
181225 assert 1 == data ["total" ]
182226 assert "/temp/doc1.json" == data ["results" ][0 ]["uri" ]
227+
228+
229+ def test_metadata_no_content (client : Client ):
230+ print ("TODO!" )
0 commit comments