Merge lp:~thisfred/u1db/create_doc-from-dict into lp:u1db

Proposed by Eric Casteleijn
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 359
Merged at revision: 357
Proposed branch: lp:~thisfred/u1db/create_doc-from-dict
Merge into: lp:u1db
Diff against target: 2648 lines (+447/-393)
21 files modified
README (+1/-1)
html-docs/high-level-api.rst (+10/-10)
html-docs/quickstart.rst (+3/-3)
include/u1db/u1db.h (+2/-2)
src/u1db.c (+2/-2)
u1db/__init__.py (+16/-1)
u1db/backends/__init__.py (+12/-3)
u1db/commandline/client.py (+1/-1)
u1db/remote/http_database.py (+1/-1)
u1db/tests/c_backend_wrapper.pyx (+4/-4)
u1db/tests/commandline/test_client.py (+20/-20)
u1db/tests/test_backends.py (+250/-220)
u1db/tests/test_c_backend.py (+32/-32)
u1db/tests/test_http_app.py (+18/-18)
u1db/tests/test_http_database.py (+2/-2)
u1db/tests/test_open.py (+1/-1)
u1db/tests/test_remote_sync_target.py (+2/-2)
u1db/tests/test_sqlite_backend.py (+7/-7)
u1db/tests/test_sync.py (+61/-61)
u1todo/test_u1todo.py (+1/-1)
u1todo/u1todo.py (+1/-1)
To merge this branch: bzr merge lp:~thisfred/u1db/create_doc-from-dict
Reviewer Review Type Date Requested Status
Lucio Torre (community) Approve
Review via email: mp+115821@code.launchpad.net

Commit message

since doc.content now returns a python dictionary, db.create_doc() should also take one. This means that both are now optional API. The old create_doc() was renamed to create_doc_from_json().

Description of the change

since doc.content now returns a python dictionary, db.create_doc() should also take one. This means that both are now optional API. The old create_doc() was renamed to create_doc_from_json().

To post a comment you must log in.
358. By Eric Casteleijn

unchanged: attach bug

359. By Eric Casteleijn

changed api doc

Revision history for this message
Lucio Torre (lucio.torre) wrote :

thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-05-10 19:11:54 +0000
3+++ README 2012-07-19 20:11:24 +0000
4@@ -12,7 +12,7 @@
5
6 import u1db
7 db = u1db.open(":memory:", create=True)
8- doc = db.create_doc('{"firstname": "Bob", "familyname": "Foo"}')
9+ doc = db.create_doc({"firstname": "Bob", "familyname": "Foo"})
10 print "document id: %s" % doc.doc_id
11 print "document revision: %s" % doc.revision
12
13
14=== modified file 'html-docs/high-level-api.rst'
15--- html-docs/high-level-api.rst 2012-07-16 16:45:45 +0000
16+++ html-docs/high-level-api.rst 2012-07-19 20:11:24 +0000
17@@ -19,14 +19,14 @@
18 Creating and editing documents
19 ------------------------------
20
21-To create a document, use ``create_doc()``. Code examples below are from
22-:ref:`reference-implementation` in Python.
23+To create a document, use ``create_doc()``. Code examples below are
24+from :ref:`reference-implementation` in Python.
25
26 .. testcode ::
27
28 import json, u1db
29 db = u1db.open(":memory:", create=True)
30- doc = db.create_doc(json.dumps({"key": "value"}), doc_id="testdoc")
31+ doc = db.create_doc({"key": "value"}, doc_id="testdoc")
32 print doc.content
33 print doc.doc_id
34
35@@ -44,10 +44,10 @@
36
37 import json, u1db
38 db = u1db.open(":memory:", create=True)
39- doc1 = db.create_doc(json.dumps({"key1": "value1"}), doc_id="doc1")
40+ doc1 = db.create_doc({"key1": "value1"}, doc_id="doc1")
41 # the next line should fail because it's creating a doc that already exists
42 try:
43- doc1fail = db.create_doc(json.dumps({"key1fail": "value1fail"}), doc_id="doc1")
44+ doc1fail = db.create_doc({"key1fail": "value1fail"}, doc_id="doc1")
45 except u1db.errors.RevisionConflict:
46 print "There was a conflict when creating the doc!"
47 print "Now editing the doc with the doc object we got back..."
48@@ -68,7 +68,7 @@
49
50 import json, u1db
51 db = u1db.open(":memory:", create=True)
52- doc = db.create_doc(json.dumps({"key": "value"}))
53+ doc = db.create_doc({"key": "value"})
54 db.delete_doc(doc)
55 print db.get_doc(doc.doc_id)
56 doc = db.get_doc(doc.doc_id, include_deleted=True)
57@@ -88,7 +88,7 @@
58
59 import json, u1db
60 db = u1db.open(":memory:", create=True)
61- doc = db.create_doc(json.dumps({"key": "value"}), doc_id="testdoc")
62+ doc = db.create_doc({"key": "value"}, doc_id="testdoc")
63 doc1 = db.get_doc("testdoc")
64 print doc1.content
65 print doc1.doc_id
66@@ -104,8 +104,8 @@
67
68 import json, u1db
69 db = u1db.open(":memory:", create=True)
70- doc1 = db.create_doc(json.dumps({"key": "value"}), doc_id="testdoc1")
71- doc2 = db.create_doc(json.dumps({"key": "value"}), doc_id="testdoc2")
72+ doc1 = db.create_doc({"key": "value"}, doc_id="testdoc1")
73+ doc2 = db.create_doc({"key": "value"}, doc_id="testdoc2")
74 for doc in db.get_docs(["testdoc2","testdoc1"]):
75 print doc.doc_id
76
77@@ -119,7 +119,7 @@
78 Document functions
79 ^^^^^^^^^^^^^^^^^^
80
81- * create_doc(JSON string, optional_doc_id)
82+ * create_doc(dictionary, optional_doc_id)
83 * put_doc(Document)
84 * get_doc(doc_id)
85 * get_docs(list_of_doc_ids)
86
87=== modified file 'html-docs/quickstart.rst'
88--- html-docs/quickstart.rst 2012-07-16 16:20:53 +0000
89+++ html-docs/quickstart.rst 2012-07-19 20:11:24 +0000
90@@ -29,16 +29,16 @@
91 >>> import u1db, json, tempfile
92 >>> db = u1db.open(":memory:", create=True)
93
94- >>> content = json.dumps({"name": "Alan Hansen"}) # create a document
95+ >>> content = {"name": "Alan Hansen"} # create a document
96 >>> doc = db.create_doc(content)
97 >>> doc.content
98 {'name': 'Alan Hansen'}
99 >>> doc.content = json.dumps({"name": "Alan Hansen", "position": "defence"}) # update the document's content
100 >>> rev = db.put_doc(doc)
101
102- >>> content = json.dumps({"name": "John Barnes", "position": "forward"}) # create more documents
103+ >>> content = {"name": "John Barnes", "position": "forward"} # create more documents
104 >>> doc2 = db.create_doc(content)
105- >>> content = json.dumps({"name": "Ian Rush", "position": "forward"})
106+ >>> content = {"name": "Ian Rush", "position": "forward"}
107 >>> doc2 = db.create_doc(content)
108
109 >>> db.create_index("by-position", "position") # create an index by passing a field name
110
111=== modified file 'include/u1db/u1db.h'
112--- include/u1db/u1db.h 2012-07-11 17:19:42 +0000
113+++ include/u1db/u1db.h 2012-07-19 20:11:24 +0000
114@@ -126,8 +126,8 @@
115 * freed with u1db_free_doc
116 * @return a status code indicating success or failure.
117 */
118-int u1db_create_doc(u1database *db, const char *json, const char *doc_id,
119- u1db_document **doc);
120+int u1db_create_doc_from_json(u1database *db, const char *json,
121+ const char *doc_id, u1db_document **doc);
122
123 /**
124 * Put new document content for the given document identifier.
125
126=== modified file 'src/u1db.c'
127--- src/u1db.c 2012-07-13 22:09:11 +0000
128+++ src/u1db.c 2012-07-19 20:11:24 +0000
129@@ -309,8 +309,8 @@
130 }
131
132 int
133-u1db_create_doc(u1database *db, const char *json, const char *doc_id,
134- u1db_document **doc)
135+u1db_create_doc_from_json(u1database *db, const char *json, const char *doc_id,
136+ u1db_document **doc)
137 {
138 char *local_doc_id = NULL;
139 int status;
140
141=== modified file 'u1db/__init__.py'
142--- u1db/__init__.py 2012-07-19 16:54:26 +0000
143+++ u1db/__init__.py 2012-07-19 20:11:24 +0000
144@@ -136,12 +136,27 @@
145 If the database specifies a maximum document size and the document
146 exceeds it, create will fail and raise a DocumentTooBig exception.
147
148- :param content: The JSON document string
149+ :param content: A Python dictionary.
150 :param doc_id: An optional identifier specifying the document id.
151 :return: Document
152 """
153 raise NotImplementedError(self.create_doc)
154
155+ def create_doc_from_json(self, json, doc_id=None):
156+ """Create a new document.
157+
158+ You can optionally specify the document identifier, but the document
159+ must not already exist. See 'put_doc' if you want to override an
160+ existing document.
161+ If the database specifies a maximum document size and the document
162+ exceeds it, create will fail and raise a DocumentTooBig exception.
163+
164+ :param json: The JSON document string
165+ :param doc_id: An optional identifier specifying the document id.
166+ :return: Document
167+ """
168+ raise NotImplementedError(self.create_doc_from_json)
169+
170 def put_doc(self, doc):
171 """Update a document.
172 If the document currently has conflicts, put will fail.
173
174=== modified file 'u1db/backends/__init__.py'
175--- u1db/backends/__init__.py 2012-07-10 22:27:06 +0000
176+++ u1db/backends/__init__.py 2012-07-19 20:11:24 +0000
177@@ -17,6 +17,7 @@
178 """Abstract classes and common implementations for the backends."""
179
180 import re
181+import simplejson
182 import uuid
183
184 import u1db
185@@ -85,9 +86,17 @@
186 raise NotImplementedError(self._has_conflicts)
187
188 def create_doc(self, content, doc_id=None):
189- if doc_id is None:
190- doc_id = self._allocate_doc_id()
191- doc = self._factory(doc_id, None, content)
192+ json = simplejson.dumps(content)
193+ if doc_id is None:
194+ doc_id = self._allocate_doc_id()
195+ doc = self._factory(doc_id, None, json)
196+ self.put_doc(doc)
197+ return doc
198+
199+ def create_doc_from_json(self, json, doc_id=None):
200+ if doc_id is None:
201+ doc_id = self._allocate_doc_id()
202+ doc = self._factory(doc_id, None, json)
203 self.put_doc(doc)
204 return doc
205
206
207=== modified file 'u1db/commandline/client.py'
208--- u1db/commandline/client.py 2012-06-11 12:37:40 +0000
209+++ u1db/commandline/client.py 2012-07-19 20:11:24 +0000
210@@ -78,7 +78,7 @@
211 if infile is None:
212 infile = self.stdin
213 db = self._open(database, create=False)
214- doc = db.create_doc(infile.read(), doc_id=doc_id)
215+ doc = db.create_doc_from_json(infile.read(), doc_id=doc_id)
216 self.stderr.write('id: %s\nrev: %s\n' % (doc.doc_id, doc.rev))
217
218 client_commands.register(CmdCreate)
219
220=== modified file 'u1db/remote/http_database.py'
221--- u1db/remote/http_database.py 2012-07-13 21:46:01 +0000
222+++ u1db/remote/http_database.py 2012-07-19 20:11:24 +0000
223@@ -119,7 +119,7 @@
224 docs.append(doc)
225 return docs
226
227- def create_doc(self, content, doc_id=None):
228+ def create_doc_from_json(self, content, doc_id=None):
229 if doc_id is None:
230 doc_id = 'D-%s' % (uuid.uuid4().hex,)
231 res, headers = self._request_json('PUT', ['doc', doc_id], {},
232
233=== modified file 'u1db/tests/c_backend_wrapper.pyx'
234--- u1db/tests/c_backend_wrapper.pyx 2012-07-17 15:44:54 +0000
235+++ u1db/tests/c_backend_wrapper.pyx 2012-07-19 20:11:24 +0000
236@@ -70,8 +70,8 @@
237 int u1db_set_replica_uid(u1database *, char *replica_uid)
238 int u1db_set_document_size_limit(u1database *, int limit)
239 int u1db_get_replica_uid(u1database *, const_char_ptr *replica_uid)
240- int u1db_create_doc(u1database *db, char *json, char *doc_id,
241- u1db_document **doc)
242+ int u1db_create_doc_from_json(u1database *db, char *json, char *doc_id,
243+ u1db_document **doc)
244 int u1db_delete_doc(u1database *db, u1db_document *doc)
245 int u1db_get_doc(u1database *db, char *doc_id, int include_deleted,
246 u1db_document **doc)
247@@ -966,7 +966,7 @@
248 finally:
249 u1db__free_table(&tbl)
250
251- def create_doc(self, content, doc_id=None):
252+ def create_doc_from_json(self, json, doc_id=None):
253 cdef u1db_document *doc = NULL
254 cdef char *c_doc_id
255
256@@ -975,7 +975,7 @@
257 else:
258 c_doc_id = doc_id
259 handle_status('Failed to create_doc',
260- u1db_create_doc(self._db, content, c_doc_id, &doc))
261+ u1db_create_doc_from_json(self._db, json, c_doc_id, &doc))
262 pydoc = CDocument()
263 pydoc._doc = doc
264 return pydoc
265
266=== modified file 'u1db/tests/commandline/test_client.py'
267--- u1db/tests/commandline/test_client.py 2012-07-10 22:27:06 +0000
268+++ u1db/tests/commandline/test_client.py 2012-07-19 20:11:24 +0000
269@@ -210,7 +210,7 @@
270 class TestCmdDelete(TestCaseWithDB):
271
272 def test_delete(self):
273- doc = self.db.create_doc(tests.simple_doc)
274+ doc = self.db.create_doc_from_json(tests.simple_doc)
275 cmd = self.make_command(client.CmdDelete)
276 cmd.run(self.db_path, doc.doc_id, doc.rev)
277 doc2 = self.db.get_doc(doc.doc_id, include_deleted=True)
278@@ -221,7 +221,7 @@
279 self.assertEqual('rev: %s\n' % (doc2.rev,), cmd.stderr.getvalue())
280
281 def test_delete_fails_if_nonexistent(self):
282- doc = self.db.create_doc(tests.simple_doc)
283+ doc = self.db.create_doc_from_json(tests.simple_doc)
284 db2_path = self.db_path + '.typo'
285 cmd = self.make_command(client.CmdDelete)
286 # TODO: We should really not be showing a traceback here. But we need
287@@ -242,7 +242,7 @@
288 cmd.run, self.db_path, 'no-doc-id', 'no-rev')
289
290 def test_delete_bad_rev(self):
291- doc = self.db.create_doc(tests.simple_doc)
292+ doc = self.db.create_doc_from_json(tests.simple_doc)
293 cmd = self.make_command(client.CmdDelete)
294 self.assertRaises(errors.RevisionConflict,
295 cmd.run, self.db_path, doc.doc_id, 'not-the-actual-doc-rev:1')
296@@ -253,7 +253,7 @@
297
298 def setUp(self):
299 super(TestCmdGet, self).setUp()
300- self.doc = self.db.create_doc(tests.simple_doc, doc_id='my-test-doc')
301+ self.doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-test-doc')
302
303 def test_get_simple(self):
304 cmd = self.make_command(client.CmdGet)
305@@ -292,14 +292,14 @@
306
307 def setUp(self):
308 super(TestCmdGetDocConflicts, self).setUp()
309- self.doc1 = self.db.create_doc(tests.simple_doc, doc_id='my-doc')
310+ self.doc1 = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-doc')
311 self.doc2 = self.make_document('my-doc', 'other:1', '{}', False)
312 self.db._put_doc_if_newer(
313 self.doc2, save_conflict=True, replica_uid='r', replica_gen=1,
314 replica_trans_id='foo')
315
316 def test_get_doc_conflicts_none(self):
317- self.db.create_doc(tests.simple_doc, doc_id='a-doc')
318+ self.db.create_doc_from_json(tests.simple_doc, doc_id='a-doc')
319 cmd = self.make_command(client.CmdGetDocConflicts)
320 cmd.run(self.db_path, 'a-doc')
321 self.assertEqual([],
322@@ -354,7 +354,7 @@
323
324 def setUp(self):
325 super(TestCmdPut, self).setUp()
326- self.doc = self.db.create_doc(tests.simple_doc, doc_id='my-test-doc')
327+ self.doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-test-doc')
328
329 def test_put_simple(self):
330 cmd = self.make_command(client.CmdPut)
331@@ -416,7 +416,7 @@
332
333 def setUp(self):
334 super(TestCmdResolve, self).setUp()
335- self.doc1 = self.db.create_doc(tests.simple_doc, doc_id='my-doc')
336+ self.doc1 = self.db.create_doc_from_json(tests.simple_doc, doc_id='my-doc')
337 self.doc2 = self.make_document('my-doc', 'other:1', '{}', False)
338 self.db._put_doc_if_newer(
339 self.doc2, save_conflict=True, replica_uid='r', replica_gen=1,
340@@ -477,8 +477,8 @@
341 self.db2 = u1db_open(self.db2_path, create=True)
342 self.addCleanup(self.db2.close)
343 self.db2._set_replica_uid('test2')
344- self.doc = self.db.create_doc(tests.simple_doc, doc_id='test-id')
345- self.doc2 = self.db2.create_doc(tests.nested_doc, doc_id='my-test-id')
346+ self.doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='test-id')
347+ self.doc2 = self.db2.create_doc_from_json(tests.nested_doc, doc_id='my-test-id')
348
349 def test_sync(self):
350 cmd = self.make_command(client.CmdSync)
351@@ -501,8 +501,8 @@
352 self.db2 = self.request_state._create_database('test2.db')
353
354 def test_sync_remote(self):
355- doc1 = self.db.create_doc(tests.simple_doc)
356- doc2 = self.db2.create_doc(tests.nested_doc)
357+ doc1 = self.db.create_doc_from_json(tests.simple_doc)
358+ doc2 = self.db2.create_doc_from_json(tests.nested_doc)
359 db2_url = self.getURL('test2.db')
360 self.assertTrue(db2_url.startswith('http://'))
361 self.assertTrue(db2_url.endswith('/test2.db'))
362@@ -626,7 +626,7 @@
363
364 def test_get_index_keys(self):
365 self.db.create_index("foo", "bar")
366- self.db.create_doc('{"bar": 42}')
367+ self.db.create_doc_from_json('{"bar": 42}')
368 cmd = self.make_command(client.CmdGetIndexKeys)
369 retval = cmd.run(self.db_path, "foo")
370 self.assertEqual(retval, None)
371@@ -635,7 +635,7 @@
372
373 def test_get_index_keys_nonascii(self):
374 self.db.create_index("foo", "bar")
375- self.db.create_doc('{"bar": "\u00a4"}')
376+ self.db.create_doc_from_json('{"bar": "\u00a4"}')
377 cmd = self.make_command(client.CmdGetIndexKeys)
378 retval = cmd.run(self.db_path, "foo")
379 self.assertEqual(retval, None)
380@@ -669,8 +669,8 @@
381
382 def test_get_from_index(self):
383 self.db.create_index("index", "key")
384- doc1 = self.db.create_doc(tests.simple_doc)
385- doc2 = self.db.create_doc(tests.nested_doc)
386+ doc1 = self.db.create_doc_from_json(tests.simple_doc)
387+ doc2 = self.db.create_doc_from_json(tests.nested_doc)
388 cmd = self.make_command(client.CmdGetFromIndex)
389 retval = cmd.run(self.db_path, "index", ["value"])
390 self.assertEqual(retval, None)
391@@ -815,7 +815,7 @@
392 self.assertRegexpMatches(stripped, expected_re)
393
394 def test_get(self):
395- doc = self.db.create_doc(tests.simple_doc, doc_id='test-id')
396+ doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='test-id')
397 ret, stdout, stderr = self.run_main(['get', self.db_path, 'test-id'])
398 self.assertEqual(0, ret)
399 self.assertEqual(tests.simple_doc + "\n", stdout)
400@@ -824,7 +824,7 @@
401 self.assertEqual(1, ret)
402
403 def test_delete(self):
404- doc = self.db.create_doc(tests.simple_doc, doc_id='test-id')
405+ doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='test-id')
406 ret, stdout, stderr = self.run_main(
407 ['delete', self.db_path, 'test-id', doc.rev])
408 doc = self.db.get_doc('test-id', include_deleted=True)
409@@ -838,7 +838,7 @@
410 u1db_open(path, create=False)
411
412 def test_put(self):
413- doc = self.db.create_doc(tests.simple_doc, doc_id='test-id')
414+ doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='test-id')
415 ret, stdout, stderr = self.run_main(
416 ['put', self.db_path, 'test-id', doc.rev],
417 stdin=tests.nested_doc)
418@@ -850,7 +850,7 @@
419 self.assertEqual('rev: %s\n' % (doc.rev,), stderr)
420
421 def test_sync(self):
422- doc = self.db.create_doc(tests.simple_doc, doc_id='test-id')
423+ doc = self.db.create_doc_from_json(tests.simple_doc, doc_id='test-id')
424 self.db2_path = self.working_dir + '/test2.db'
425 self.db2 = u1db_open(self.db2_path, create=True)
426 self.addCleanup(self.db2.close)
427
428=== modified file 'u1db/tests/test_backends.py'
429--- u1db/tests/test_backends.py 2012-07-13 22:09:11 +0000
430+++ u1db/tests/test_backends.py 2012-07-19 20:11:24 +0000
431@@ -99,27 +99,28 @@
432 self.db.close()
433
434 def test_create_doc_allocating_doc_id(self):
435- doc = self.db.create_doc(simple_doc)
436+ doc = self.db.create_doc_from_json(simple_doc)
437 self.assertNotEqual(None, doc.doc_id)
438 self.assertNotEqual(None, doc.rev)
439 self.assertGetDoc(self.db, doc.doc_id, doc.rev, simple_doc, False)
440
441 def test_create_doc_different_ids_same_db(self):
442- doc1 = self.db.create_doc(simple_doc)
443- doc2 = self.db.create_doc(nested_doc)
444+ doc1 = self.db.create_doc_from_json(simple_doc)
445+ doc2 = self.db.create_doc_from_json(nested_doc)
446 self.assertNotEqual(doc1.doc_id, doc2.doc_id)
447
448 def test_create_doc_with_id(self):
449- doc = self.db.create_doc(simple_doc, doc_id='my-id')
450+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my-id')
451 self.assertEqual('my-id', doc.doc_id)
452 self.assertNotEqual(None, doc.rev)
453 self.assertGetDoc(self.db, doc.doc_id, doc.rev, simple_doc, False)
454
455 def test_create_doc_existing_id(self):
456- doc = self.db.create_doc(simple_doc)
457+ doc = self.db.create_doc_from_json(simple_doc)
458 new_content = '{"something": "else"}'
459- self.assertRaises(errors.RevisionConflict, self.db.create_doc,
460- new_content, doc.doc_id)
461+ self.assertRaises(
462+ errors.RevisionConflict, self.db.create_doc_from_json,
463+ new_content, doc.doc_id)
464 self.assertGetDoc(self.db, doc.doc_id, doc.rev, simple_doc, False)
465
466 def test_put_doc_creating_initial(self):
467@@ -133,7 +134,7 @@
468 self.assertRaises(errors.InvalidDocId, self.db.put_doc, doc)
469
470 def test_put_doc_update(self):
471- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
472+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
473 orig_rev = doc.rev
474 doc.set_json('{"updated": "stuff"}')
475 new_rev = self.db.put_doc(doc)
476@@ -144,12 +145,12 @@
477
478 def test_put_non_ascii_key(self):
479 content = simplejson.dumps({u'key\xe5': u'val'})
480- doc = self.db.create_doc(content, doc_id='my_doc')
481+ doc = self.db.create_doc_from_json(content, doc_id='my_doc')
482 self.assertGetDoc(self.db, 'my_doc', doc.rev, content, False)
483
484 def test_put_non_ascii_value(self):
485 content = simplejson.dumps({'key': u'\xe5'})
486- doc = self.db.create_doc(content, doc_id='my_doc')
487+ doc = self.db.create_doc_from_json(content, doc_id='my_doc')
488 self.assertGetDoc(self.db, 'my_doc', doc.rev, content, False)
489
490 def test_put_doc_refuses_no_id(self):
491@@ -173,7 +174,7 @@
492 self.assertRaises(errors.InvalidDocId, self.db.put_doc, doc)
493
494 def test_put_fails_with_bad_old_rev(self):
495- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
496+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
497 old_rev = doc.rev
498 bad_doc = self.make_document(doc.doc_id, 'other:1',
499 '{"something": "else"}')
500@@ -181,11 +182,11 @@
501 self.assertGetDoc(self.db, 'my_doc_id', old_rev, simple_doc, False)
502
503 def test_create_succeeds_after_delete(self):
504- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
505+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
506 self.db.delete_doc(doc)
507 deleted_doc = self.db.get_doc('my_doc_id', include_deleted=True)
508 deleted_vc = vectorclock.VectorClockRev(deleted_doc.rev)
509- new_doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
510+ new_doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
511 self.assertGetDoc(self.db, 'my_doc_id', new_doc.rev, simple_doc, False)
512 new_vc = vectorclock.VectorClockRev(new_doc.rev)
513 self.assertTrue(
514@@ -193,7 +194,7 @@
515 "%s does not supersede %s" % (new_doc.rev, deleted_doc.rev))
516
517 def test_put_succeeds_after_delete(self):
518- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
519+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
520 self.db.delete_doc(doc)
521 deleted_doc = self.db.get_doc('my_doc_id', include_deleted=True)
522 deleted_vc = vectorclock.VectorClockRev(deleted_doc.rev)
523@@ -206,46 +207,46 @@
524 "%s does not supersede %s" % (doc2.rev, deleted_doc.rev))
525
526 def test_get_doc_after_put(self):
527- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
528+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
529 self.assertGetDoc(self.db, 'my_doc_id', doc.rev, simple_doc, False)
530
531 def test_get_doc_nonexisting(self):
532 self.assertIs(None, self.db.get_doc('non-existing'))
533
534 def test_get_doc_deleted(self):
535- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
536+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
537 self.db.delete_doc(doc)
538 self.assertIs(None, self.db.get_doc('my_doc_id'))
539
540 def test_get_doc_include_deleted(self):
541- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
542+ doc = self.db.create_doc_from_json(simple_doc, doc_id='my_doc_id')
543 self.db.delete_doc(doc)
544 self.assertGetDocIncludeDeleted(
545 self.db, doc.doc_id, doc.rev, None, False)
546
547 def test_get_docs(self):
548- doc1 = self.db.create_doc(simple_doc)
549- doc2 = self.db.create_doc(nested_doc)
550+ doc1 = self.db.create_doc_from_json(simple_doc)
551+ doc2 = self.db.create_doc_from_json(nested_doc)
552 self.assertEqual([doc1, doc2],
553 self.db.get_docs([doc1.doc_id, doc2.doc_id]))
554
555 def test_get_docs_deleted(self):
556- doc1 = self.db.create_doc(simple_doc)
557- doc2 = self.db.create_doc(nested_doc)
558+ doc1 = self.db.create_doc_from_json(simple_doc)
559+ doc2 = self.db.create_doc_from_json(nested_doc)
560 self.db.delete_doc(doc1)
561 self.assertEqual([doc2], self.db.get_docs([doc1.doc_id, doc2.doc_id]))
562
563 def test_get_docs_include_deleted(self):
564- doc1 = self.db.create_doc(simple_doc)
565- doc2 = self.db.create_doc(nested_doc)
566+ doc1 = self.db.create_doc_from_json(simple_doc)
567+ doc2 = self.db.create_doc_from_json(nested_doc)
568 self.db.delete_doc(doc1)
569 self.assertEqual(
570 [doc1, doc2],
571 self.db.get_docs([doc1.doc_id, doc2.doc_id], include_deleted=True))
572
573 def test_get_docs_request_ordered(self):
574- doc1 = self.db.create_doc(simple_doc)
575- doc2 = self.db.create_doc(nested_doc)
576+ doc1 = self.db.create_doc_from_json(simple_doc)
577+ doc2 = self.db.create_doc_from_json(nested_doc)
578 self.assertEqual([doc1, doc2],
579 self.db.get_docs([doc1.doc_id, doc2.doc_id]))
580 self.assertEqual([doc2, doc1],
581@@ -255,15 +256,15 @@
582 self.assertEqual([], self.db.get_docs([]))
583
584 def test_handles_nested_content(self):
585- doc = self.db.create_doc(nested_doc)
586+ doc = self.db.create_doc_from_json(nested_doc)
587 self.assertGetDoc(self.db, doc.doc_id, doc.rev, nested_doc, False)
588
589 def test_handles_doc_with_null(self):
590- doc = self.db.create_doc('{"key": null}')
591+ doc = self.db.create_doc_from_json('{"key": null}')
592 self.assertGetDoc(self.db, doc.doc_id, doc.rev, '{"key": null}', False)
593
594 def test_delete_doc(self):
595- doc = self.db.create_doc(simple_doc)
596+ doc = self.db.create_doc_from_json(simple_doc)
597 self.assertGetDoc(self.db, doc.doc_id, doc.rev, simple_doc, False)
598 orig_rev = doc.rev
599 self.db.delete_doc(doc)
600@@ -277,7 +278,7 @@
601 self.assertRaises(errors.DocumentDoesNotExist, self.db.delete_doc, doc)
602
603 def test_delete_doc_already_deleted(self):
604- doc = self.db.create_doc(simple_doc)
605+ doc = self.db.create_doc_from_json(simple_doc)
606 self.db.delete_doc(doc)
607 self.assertRaises(errors.DocumentAlreadyDeleted,
608 self.db.delete_doc, doc)
609@@ -285,19 +286,19 @@
610 self.db, doc.doc_id, doc.rev, None, False)
611
612 def test_delete_doc_bad_rev(self):
613- doc1 = self.db.create_doc(simple_doc)
614+ doc1 = self.db.create_doc_from_json(simple_doc)
615 self.assertGetDoc(self.db, doc1.doc_id, doc1.rev, simple_doc, False)
616 doc2 = self.make_document(doc1.doc_id, 'other:1', simple_doc)
617 self.assertRaises(errors.RevisionConflict, self.db.delete_doc, doc2)
618 self.assertGetDoc(self.db, doc1.doc_id, doc1.rev, simple_doc, False)
619
620 def test_delete_doc_sets_content_to_None(self):
621- doc = self.db.create_doc(simple_doc)
622+ doc = self.db.create_doc_from_json(simple_doc)
623 self.db.delete_doc(doc)
624 self.assertIs(None, doc.get_json())
625
626 def test_delete_doc_rev_supersedes(self):
627- doc = self.db.create_doc(simple_doc)
628+ doc = self.db.create_doc_from_json(simple_doc)
629 doc.set_json(nested_doc)
630 self.db.put_doc(doc)
631 doc.set_json('{"fishy": "content"}')
632@@ -310,7 +311,7 @@
633 "%s does not supersede %s" % (doc.rev, old_rev))
634
635 def test_delete_then_put(self):
636- doc = self.db.create_doc(simple_doc)
637+ doc = self.db.create_doc_from_json(simple_doc)
638 self.db.delete_doc(doc)
639 self.assertGetDocIncludeDeleted(
640 self.db, doc.doc_id, doc.rev, None, False)
641@@ -331,7 +332,7 @@
642 def test_create_doc_refuses_oversized_documents(self):
643 self.db.set_document_size_limit(1)
644 self.assertRaises(
645- errors.DocumentTooBig, self.db.create_doc, simple_doc,
646+ errors.DocumentTooBig, self.db.create_doc_from_json, simple_doc,
647 doc_id='my_doc_id')
648
649 def test_set_document_size_limit_zero(self):
650@@ -348,9 +349,9 @@
651 scenarios = tests.LOCAL_DATABASES_SCENARIOS + tests.C_DATABASE_SCENARIOS
652
653 def test_create_doc_different_ids_diff_db(self):
654- doc1 = self.db.create_doc(simple_doc)
655+ doc1 = self.db.create_doc_from_json(simple_doc)
656 db2 = self.create_database('other-uid')
657- doc2 = db2.create_doc(simple_doc)
658+ doc2 = db2.create_doc_from_json(simple_doc)
659 self.assertNotEqual(doc1.doc_id, doc2.doc_id)
660
661 def test_put_doc_refuses_slashes_picky(self):
662@@ -361,28 +362,28 @@
663 self.assertEqual([], self.db.get_all_docs()[1])
664
665 def test_get_all_docs(self):
666- doc1 = self.db.create_doc(simple_doc)
667- doc2 = self.db.create_doc(nested_doc)
668+ doc1 = self.db.create_doc_from_json(simple_doc)
669+ doc2 = self.db.create_doc_from_json(nested_doc)
670 self.assertEqual(
671 sorted([doc1, doc2]), sorted(self.db.get_all_docs()[1]))
672
673 def test_get_all_docs_exclude_deleted(self):
674- doc1 = self.db.create_doc(simple_doc)
675- doc2 = self.db.create_doc(nested_doc)
676+ doc1 = self.db.create_doc_from_json(simple_doc)
677+ doc2 = self.db.create_doc_from_json(nested_doc)
678 self.db.delete_doc(doc2)
679 self.assertEqual([doc1], self.db.get_all_docs()[1])
680
681 def test_get_all_docs_include_deleted(self):
682- doc1 = self.db.create_doc(simple_doc)
683- doc2 = self.db.create_doc(nested_doc)
684+ doc1 = self.db.create_doc_from_json(simple_doc)
685+ doc2 = self.db.create_doc_from_json(nested_doc)
686 self.db.delete_doc(doc2)
687 self.assertEqual(
688 sorted([doc1, doc2]),
689 sorted(self.db.get_all_docs(include_deleted=True)[1]))
690
691 def test_get_all_docs_generation(self):
692- self.db.create_doc(simple_doc)
693- self.db.create_doc(nested_doc)
694+ self.db.create_doc_from_json(simple_doc)
695+ self.db.create_doc_from_json(nested_doc)
696 self.assertEqual(2, self.db.get_all_docs()[0])
697
698 def test_simple_put_doc_if_newer(self):
699@@ -394,7 +395,7 @@
700 self.assertGetDoc(self.db, 'my-doc-id', 'test:1', simple_doc, False)
701
702 def test_simple_put_doc_if_newer_deleted(self):
703- self.db.create_doc('{}', doc_id='my-doc-id')
704+ self.db.create_doc_from_json('{}', doc_id='my-doc-id')
705 doc = self.make_document('my-doc-id', 'test:2', None)
706 state_at_gen = self.db._put_doc_if_newer(
707 doc, save_conflict=False, replica_uid='r', replica_gen=1,
708@@ -405,7 +406,7 @@
709
710 def test_put_doc_if_newer_already_superseded(self):
711 orig_doc = '{"new": "doc"}'
712- doc1 = self.db.create_doc(orig_doc)
713+ doc1 = self.db.create_doc_from_json(orig_doc)
714 doc1_rev1 = doc1.rev
715 doc1.set_json(simple_doc)
716 self.db.put_doc(doc1)
717@@ -419,7 +420,7 @@
718 self.assertGetDoc(self.db, doc1.doc_id, doc1_rev2, simple_doc, False)
719
720 def test_put_doc_if_newer_autoresolve(self):
721- doc1 = self.db.create_doc(simple_doc)
722+ doc1 = self.db.create_doc_from_json(simple_doc)
723 rev = doc1.rev
724 doc = self.make_document(doc1.doc_id, "whatever:1", doc1.get_json())
725 state, _ = self.db._put_doc_if_newer(
726@@ -433,14 +434,14 @@
727
728 def test_put_doc_if_newer_already_converged(self):
729 orig_doc = '{"new": "doc"}'
730- doc1 = self.db.create_doc(orig_doc)
731+ doc1 = self.db.create_doc_from_json(orig_doc)
732 state_at_gen = self.db._put_doc_if_newer(
733 doc1, save_conflict=False, replica_uid='r', replica_gen=1,
734 replica_trans_id='foo')
735 self.assertEqual(('converged', 1), state_at_gen)
736
737 def test_put_doc_if_newer_conflicted(self):
738- doc1 = self.db.create_doc(simple_doc)
739+ doc1 = self.db.create_doc_from_json(simple_doc)
740 # Nothing is inserted, the document id is returned as would-conflict
741 alt_doc = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
742 state, _ = self.db._put_doc_if_newer(
743@@ -460,7 +461,7 @@
744
745 def test_put_doc_if_newer_same_generation_same_txid(self):
746 self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
747- doc = self.db.create_doc(simple_doc)
748+ doc = self.db.create_doc_from_json(simple_doc)
749 self.make_document(doc.doc_id, 'other:1', simple_doc)
750 state, _ = self.db._put_doc_if_newer(
751 doc, save_conflict=False, replica_uid='other', replica_gen=1,
752@@ -477,7 +478,7 @@
753
754 def test_put_doc_if_newer_old_generation_older_doc(self):
755 orig_doc = '{"new": "doc"}'
756- doc = self.db.create_doc(orig_doc)
757+ doc = self.db.create_doc_from_json(orig_doc)
758 doc_rev1 = doc.rev
759 doc.set_json(simple_doc)
760 self.db.put_doc(doc)
761@@ -497,7 +498,7 @@
762 replica_uid='other', replica_gen=1, replica_trans_id='T-sad')
763
764 def test_put_doc_if_newer_replica_uid(self):
765- doc1 = self.db.create_doc(simple_doc)
766+ doc1 = self.db.create_doc_from_json(simple_doc)
767 self.db._set_replica_gen_and_trans_id('other', 1, 'T-sid')
768 doc2 = self.make_document(doc1.doc_id, doc1.rev + '|other:1',
769 nested_doc)
770@@ -535,7 +536,7 @@
771 self.db._get_replica_gen_and_trans_id('other-db'))
772
773 def test_put_updates_transaction_log(self):
774- doc = self.db.create_doc(simple_doc)
775+ doc = self.db.create_doc_from_json(simple_doc)
776 self.assertTransactionLog([doc.doc_id], self.db)
777 doc.set_json('{"something": "else"}')
778 self.db.put_doc(doc)
779@@ -545,7 +546,7 @@
780 self.db.whats_changed())
781
782 def test_delete_updates_transaction_log(self):
783- doc = self.db.create_doc(simple_doc)
784+ doc = self.db.create_doc_from_json(simple_doc)
785 db_gen, _, _ = self.db.whats_changed()
786 self.db.delete_doc(doc)
787 last_trans_id = self.getLastTransId(self.db)
788@@ -556,7 +557,7 @@
789 self.assertEqual((0, '', []), self.db.whats_changed())
790
791 def test_whats_changed_returns_one_id_for_multiple_changes(self):
792- doc = self.db.create_doc(simple_doc)
793+ doc = self.db.create_doc_from_json(simple_doc)
794 doc.set_json('{"new": "contents"}')
795 self.db.put_doc(doc)
796 last_trans_id = self.getLastTransId(self.db)
797@@ -565,8 +566,8 @@
798 self.assertEqual((2, last_trans_id, []), self.db.whats_changed(2))
799
800 def test_whats_changed_returns_last_edits_ascending(self):
801- doc = self.db.create_doc(simple_doc)
802- doc1 = self.db.create_doc(simple_doc)
803+ doc = self.db.create_doc_from_json(simple_doc)
804+ doc1 = self.db.create_doc_from_json(simple_doc)
805 doc.set_json('{"new": "contents"}')
806 self.db.delete_doc(doc1)
807 delete_trans_id = self.getLastTransId(self.db)
808@@ -578,9 +579,9 @@
809 self.db.whats_changed())
810
811 def test_whats_changed_doesnt_include_old_gen(self):
812- self.db.create_doc(simple_doc)
813- self.db.create_doc(simple_doc)
814- doc2 = self.db.create_doc(simple_doc)
815+ self.db.create_doc_from_json(simple_doc)
816+ self.db.create_doc_from_json(simple_doc)
817+ doc2 = self.db.create_doc_from_json(simple_doc)
818 last_trans_id = self.getLastTransId(self.db)
819 self.assertEqual((3, last_trans_id, [(doc2.doc_id, 3, last_trans_id)]),
820 self.db.whats_changed(2))
821@@ -591,19 +592,19 @@
822 scenarios = tests.LOCAL_DATABASES_SCENARIOS + tests.C_DATABASE_SCENARIOS
823
824 def test_validate_gen_and_trans_id(self):
825- self.db.create_doc(simple_doc)
826+ self.db.create_doc_from_json(simple_doc)
827 gen, trans_id = self.db._get_generation_info()
828 self.db.validate_gen_and_trans_id(gen, trans_id)
829
830 def test_validate_gen_and_trans_id_invalid_txid(self):
831- self.db.create_doc(simple_doc)
832+ self.db.create_doc_from_json(simple_doc)
833 gen, _ = self.db._get_generation_info()
834 self.assertRaises(
835 errors.InvalidTransactionId,
836 self.db.validate_gen_and_trans_id, gen, 'wrong')
837
838 def test_validate_gen_and_trans_id_invalid_gen(self):
839- self.db.create_doc(simple_doc)
840+ self.db.create_doc_from_json(simple_doc)
841 gen, trans_id = self.db._get_generation_info()
842 self.assertRaises(
843 errors.InvalidGeneration,
844@@ -635,7 +636,7 @@
845 scenarios = tests.LOCAL_DATABASES_SCENARIOS + tests.C_DATABASE_SCENARIOS
846
847 def test_get_docs_conflicted(self):
848- doc1 = self.db.create_doc(simple_doc)
849+ doc1 = self.db.create_doc_from_json(simple_doc)
850 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
851 self.db._put_doc_if_newer(
852 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
853@@ -643,8 +644,8 @@
854 self.assertEqual([doc2], self.db.get_docs([doc1.doc_id]))
855
856 def test_get_docs_conflicts_ignored(self):
857- doc1 = self.db.create_doc(simple_doc)
858- doc2 = self.db.create_doc(nested_doc)
859+ doc1 = self.db.create_doc_from_json(simple_doc)
860+ doc2 = self.db.create_doc_from_json(nested_doc)
861 alt_doc = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
862 self.db._put_doc_if_newer(
863 alt_doc, save_conflict=True, replica_uid='r', replica_gen=1,
864@@ -656,7 +657,7 @@
865 check_for_conflicts=False))
866
867 def test_get_doc_conflicts(self):
868- doc = self.db.create_doc(simple_doc)
869+ doc = self.db.create_doc_from_json(simple_doc)
870 alt_doc = self.make_document(doc.doc_id, 'alternate:1', nested_doc)
871 self.db._put_doc_if_newer(
872 alt_doc, save_conflict=True, replica_uid='r', replica_gen=1,
873@@ -665,14 +666,14 @@
874 self.db.get_doc_conflicts(doc.doc_id))
875
876 def test_get_doc_conflicts_unconflicted(self):
877- doc = self.db.create_doc(simple_doc)
878+ doc = self.db.create_doc_from_json(simple_doc)
879 self.assertEqual([], self.db.get_doc_conflicts(doc.doc_id))
880
881 def test_get_doc_conflicts_no_such_id(self):
882 self.assertEqual([], self.db.get_doc_conflicts('doc-id'))
883
884 def test_resolve_doc(self):
885- doc = self.db.create_doc(simple_doc)
886+ doc = self.db.create_doc_from_json(simple_doc)
887 alt_doc = self.make_document(doc.doc_id, 'alternate:1', nested_doc)
888 self.db._put_doc_if_newer(
889 alt_doc, save_conflict=True, replica_uid='r', replica_gen=1,
890@@ -687,7 +688,7 @@
891 self.assertGetDocConflicts(self.db, doc.doc_id, [])
892
893 def test_resolve_doc_picks_biggest_vcr(self):
894- doc1 = self.db.create_doc(simple_doc)
895+ doc1 = self.db.create_doc_from_json(simple_doc)
896 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
897 self.db._put_doc_if_newer(
898 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
899@@ -708,7 +709,7 @@
900 self.assertTrue(vcr_new.is_newer(vcr_2))
901
902 def test_resolve_doc_partial_not_winning(self):
903- doc1 = self.db.create_doc(simple_doc)
904+ doc1 = self.db.create_doc_from_json(simple_doc)
905 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
906 self.db._put_doc_if_newer(
907 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
908@@ -733,7 +734,7 @@
909 (doc1.rev, simple_doc)])
910
911 def test_resolve_doc_partial_winning(self):
912- doc1 = self.db.create_doc(simple_doc)
913+ doc1 = self.db.create_doc_from_json(simple_doc)
914 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
915 self.db._put_doc_if_newer(
916 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
917@@ -754,7 +755,7 @@
918 (doc2.rev, nested_doc)])
919
920 def test_resolve_doc_with_delete_conflict(self):
921- doc1 = self.db.create_doc(simple_doc)
922+ doc1 = self.db.create_doc_from_json(simple_doc)
923 self.db.delete_doc(doc1)
924 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
925 self.db._put_doc_if_newer(
926@@ -768,7 +769,7 @@
927 self.assertGetDoc(self.db, doc2.doc_id, doc2.rev, nested_doc, False)
928
929 def test_resolve_doc_with_delete_to_delete(self):
930- doc1 = self.db.create_doc(simple_doc)
931+ doc1 = self.db.create_doc_from_json(simple_doc)
932 self.db.delete_doc(doc1)
933 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
934 self.db._put_doc_if_newer(
935@@ -783,7 +784,7 @@
936 self.db, doc1.doc_id, doc1.rev, None, False)
937
938 def test_put_doc_if_newer_save_conflicted(self):
939- doc1 = self.db.create_doc(simple_doc)
940+ doc1 = self.db.create_doc_from_json(simple_doc)
941 # Document is inserted as a conflict
942 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
943 state, _ = self.db._put_doc_if_newer(
944@@ -794,7 +795,7 @@
945 self.assertGetDoc(self.db, doc1.doc_id, doc2.rev, nested_doc, True)
946
947 def test_force_doc_conflict_supersedes_properly(self):
948- doc1 = self.db.create_doc(simple_doc)
949+ doc1 = self.db.create_doc_from_json(simple_doc)
950 doc2 = self.make_document(doc1.doc_id, 'alternate:1', '{"b": 1}')
951 self.db._put_doc_if_newer(
952 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
953@@ -813,7 +814,7 @@
954 (doc1.rev, simple_doc)])
955
956 def test_put_doc_if_newer_save_conflict_was_deleted(self):
957- doc1 = self.db.create_doc(simple_doc)
958+ doc1 = self.db.create_doc_from_json(simple_doc)
959 self.db.delete_doc(doc1)
960 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
961 self.db._put_doc_if_newer(
962@@ -826,7 +827,7 @@
963 [('alternate:1', nested_doc), (doc1.rev, None)])
964
965 def test_put_doc_if_newer_propagates_full_resolution(self):
966- doc1 = self.db.create_doc(simple_doc)
967+ doc1 = self.db.create_doc_from_json(simple_doc)
968 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
969 self.db._put_doc_if_newer(
970 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
971@@ -847,7 +848,7 @@
972 self.assertFalse(doc3.has_conflicts)
973
974 def test_put_doc_if_newer_propagates_partial_resolution(self):
975- doc1 = self.db.create_doc(simple_doc)
976+ doc1 = self.db.create_doc_from_json(simple_doc)
977 doc2 = self.make_document(doc1.doc_id, 'altalt:1', '{}')
978 self.db._put_doc_if_newer(
979 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
980@@ -876,7 +877,7 @@
981 [('alternate:2|test:1', '{"good": 1}'), ('altalt:1', '{}')])
982
983 def test_put_doc_if_newer_replica_uid(self):
984- doc1 = self.db.create_doc(simple_doc)
985+ doc1 = self.db.create_doc_from_json(simple_doc)
986 self.db._set_replica_gen_and_trans_id('other', 1, 'T-id')
987 doc2 = self.make_document(doc1.doc_id, doc1.rev + '|other:1',
988 nested_doc)
989@@ -896,7 +897,7 @@
990 def test_put_doc_if_newer_autoresolve_2(self):
991 # this is an ordering variant of _3, but that already works
992 # adding the test explicitly to catch the regression easily
993- doc_a1 = self.db.create_doc(simple_doc)
994+ doc_a1 = self.db.create_doc_from_json(simple_doc)
995 doc_a2 = self.make_document(doc_a1.doc_id, 'test:2', "{}")
996 doc_a1b1 = self.make_document(doc_a1.doc_id, 'test:1|other:1',
997 '{"a":"42"}')
998@@ -916,7 +917,7 @@
999 self.assertFalse(self.db.get_doc(doc_a1.doc_id).has_conflicts)
1000
1001 def test_put_doc_if_newer_autoresolve_3(self):
1002- doc_a1 = self.db.create_doc(simple_doc)
1003+ doc_a1 = self.db.create_doc_from_json(simple_doc)
1004 doc_a1b1 = self.make_document(doc_a1.doc_id, 'test:1|other:1', "{}")
1005 doc_a2 = self.make_document(doc_a1.doc_id, 'test:2', '{"a":"42"}')
1006 doc_a3 = self.make_document(doc_a1.doc_id, 'test:3', "{}")
1007@@ -941,7 +942,7 @@
1008 self.assertTrue(rev.is_newer(rev_a1b1))
1009
1010 def test_put_doc_if_newer_autoresolve_4(self):
1011- doc_a1 = self.db.create_doc(simple_doc)
1012+ doc_a1 = self.db.create_doc_from_json(simple_doc)
1013 doc_a1b1 = self.make_document(doc_a1.doc_id, 'test:1|other:1', None)
1014 doc_a2 = self.make_document(doc_a1.doc_id, 'test:2', '{"a":"42"}')
1015 doc_a3 = self.make_document(doc_a1.doc_id, 'test:3', None)
1016@@ -966,7 +967,7 @@
1017 self.assertTrue(rev.is_newer(rev_a1b1))
1018
1019 def test_put_refuses_to_update_conflicted(self):
1020- doc1 = self.db.create_doc(simple_doc)
1021+ doc1 = self.db.create_doc_from_json(simple_doc)
1022 content2 = '{"key": "altval"}'
1023 doc2 = self.make_document(doc1.doc_id, 'altrev:1', content2)
1024 self.db._put_doc_if_newer(
1025@@ -978,7 +979,7 @@
1026 self.assertRaises(errors.ConflictedDoc, self.db.put_doc, doc2)
1027
1028 def test_delete_refuses_for_conflicted(self):
1029- doc1 = self.db.create_doc(simple_doc)
1030+ doc1 = self.db.create_doc_from_json(simple_doc)
1031 doc2 = self.make_document(doc1.doc_id, 'altrev:1', nested_doc)
1032 self.db._put_doc_if_newer(
1033 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
1034@@ -997,7 +998,8 @@
1035 self.db.list_indexes())
1036
1037 def test_create_index_on_non_ascii_field_name(self):
1038- doc = self.db.create_doc(simplejson.dumps({u'\xe5': 'value'}))
1039+ doc = self.db.create_doc_from_json(
1040+ simplejson.dumps({u'\xe5': 'value'}))
1041 self.db.create_index('test-idx', u'\xe5')
1042 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1043
1044@@ -1007,17 +1009,19 @@
1045 [('test-idx', [u'\xe5'])], self.db.list_indexes())
1046
1047 def test_create_index_evaluates_it(self):
1048- doc = self.db.create_doc(simple_doc)
1049+ doc = self.db.create_doc_from_json(simple_doc)
1050 self.db.create_index('test-idx', 'key')
1051 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1052
1053 def test_wildcard_matches_unicode_value(self):
1054- doc = self.db.create_doc(simplejson.dumps({"key": u"valu\xe5"}))
1055+ doc = self.db.create_doc_from_json(simplejson.dumps(
1056+ {"key": u"valu\xe5"}))
1057 self.db.create_index('test-idx', 'key')
1058 self.assertEqual([doc], self.db.get_from_index('test-idx', '*'))
1059
1060 def test_retrieve_unicode_value_from_index(self):
1061- doc = self.db.create_doc(simplejson.dumps({"key": u"valu\xe5"}))
1062+ doc = self.db.create_doc_from_json(simplejson.dumps(
1063+ {"key": u"valu\xe5"}))
1064 self.db.create_index('test-idx', 'key')
1065 self.assertEqual(
1066 [doc], self.db.get_from_index('test-idx', u"valu\xe5"))
1067@@ -1034,8 +1038,8 @@
1068 self.assertEqual([('test-idx', ['key'])], self.db.list_indexes())
1069
1070 def test_create_index_after_deleting_document(self):
1071- doc = self.db.create_doc(simple_doc)
1072- doc2 = self.db.create_doc(simple_doc)
1073+ doc = self.db.create_doc_from_json(simple_doc)
1074+ doc2 = self.db.create_doc_from_json(simple_doc)
1075 self.db.delete_doc(doc2)
1076 self.db.create_index('test-idx', 'key')
1077 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1078@@ -1048,112 +1052,118 @@
1079
1080 def test_create_adds_to_index(self):
1081 self.db.create_index('test-idx', 'key')
1082- doc = self.db.create_doc(simple_doc)
1083+ doc = self.db.create_doc_from_json(simple_doc)
1084 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1085
1086 def test_get_from_index_unmatched(self):
1087- self.db.create_doc(simple_doc)
1088+ self.db.create_doc_from_json(simple_doc)
1089 self.db.create_index('test-idx', 'key')
1090 self.assertEqual([], self.db.get_from_index('test-idx', 'novalue'))
1091
1092 def test_create_index_multiple_exact_matches(self):
1093- doc = self.db.create_doc(simple_doc)
1094- doc2 = self.db.create_doc(simple_doc)
1095+ doc = self.db.create_doc_from_json(simple_doc)
1096+ doc2 = self.db.create_doc_from_json(simple_doc)
1097 self.db.create_index('test-idx', 'key')
1098 self.assertEqual(
1099 sorted([doc, doc2]),
1100 sorted(self.db.get_from_index('test-idx', 'value')))
1101
1102 def test_get_from_index(self):
1103- doc = self.db.create_doc(simple_doc)
1104+ doc = self.db.create_doc_from_json(simple_doc)
1105 self.db.create_index('test-idx', 'key')
1106 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1107
1108 def test_get_from_index_multi(self):
1109 content = '{"key": "value", "key2": "value2"}'
1110- doc = self.db.create_doc(content)
1111+ doc = self.db.create_doc_from_json(content)
1112 self.db.create_index('test-idx', 'key', 'key2')
1113 self.assertEqual(
1114 [doc], self.db.get_from_index('test-idx', 'value', 'value2'))
1115
1116 def test_get_from_index_multi_ordered(self):
1117- doc1 = self.db.create_doc('{"key": "value3", "key2": "value4"}')
1118- doc2 = self.db.create_doc('{"key": "value2", "key2": "value3"}')
1119- doc3 = self.db.create_doc('{"key": "value2", "key2": "value2"}')
1120- doc4 = self.db.create_doc('{"key": "value1", "key2": "value1"}')
1121+ doc1 = self.db.create_doc_from_json(
1122+ '{"key": "value3", "key2": "value4"}')
1123+ doc2 = self.db.create_doc_from_json(
1124+ '{"key": "value2", "key2": "value3"}')
1125+ doc3 = self.db.create_doc_from_json(
1126+ '{"key": "value2", "key2": "value2"}')
1127+ doc4 = self.db.create_doc_from_json(
1128+ '{"key": "value1", "key2": "value1"}')
1129 self.db.create_index('test-idx', 'key', 'key2')
1130 self.assertEqual(
1131 [doc4, doc3, doc2, doc1],
1132 self.db.get_from_index('test-idx', 'v*', '*'))
1133
1134 def test_get_range_from_index_start_end(self):
1135- doc1 = self.db.create_doc('{"key": "value3"}')
1136- doc2 = self.db.create_doc('{"key": "value2"}')
1137- self.db.create_doc('{"key": "value4"}')
1138- self.db.create_doc('{"key": "value1"}')
1139+ doc1 = self.db.create_doc_from_json('{"key": "value3"}')
1140+ doc2 = self.db.create_doc_from_json('{"key": "value2"}')
1141+ self.db.create_doc_from_json('{"key": "value4"}')
1142+ self.db.create_doc_from_json('{"key": "value1"}')
1143 self.db.create_index('test-idx', 'key')
1144 self.assertEqual(
1145 [doc2, doc1],
1146 self.db.get_range_from_index('test-idx', 'value2', 'value3'))
1147
1148 def test_get_range_from_index_start(self):
1149- doc1 = self.db.create_doc('{"key": "value3"}')
1150- doc2 = self.db.create_doc('{"key": "value2"}')
1151- doc3 = self.db.create_doc('{"key": "value4"}')
1152- self.db.create_doc('{"key": "value1"}')
1153+ doc1 = self.db.create_doc_from_json('{"key": "value3"}')
1154+ doc2 = self.db.create_doc_from_json('{"key": "value2"}')
1155+ doc3 = self.db.create_doc_from_json('{"key": "value4"}')
1156+ self.db.create_doc_from_json('{"key": "value1"}')
1157 self.db.create_index('test-idx', 'key')
1158 self.assertEqual(
1159 [doc2, doc1, doc3],
1160 self.db.get_range_from_index('test-idx', 'value2'))
1161
1162 def test_get_range_from_index_end(self):
1163- self.db.create_doc('{"key": "value3"}')
1164- doc2 = self.db.create_doc('{"key": "value2"}')
1165- self.db.create_doc('{"key": "value4"}')
1166- doc4 = self.db.create_doc('{"key": "value1"}')
1167+ self.db.create_doc_from_json('{"key": "value3"}')
1168+ doc2 = self.db.create_doc_from_json('{"key": "value2"}')
1169+ self.db.create_doc_from_json('{"key": "value4"}')
1170+ doc4 = self.db.create_doc_from_json('{"key": "value1"}')
1171 self.db.create_index('test-idx', 'key')
1172 self.assertEqual(
1173 [doc4, doc2],
1174 self.db.get_range_from_index('test-idx', None, 'value2'))
1175
1176 def test_get_wildcard_range_from_index_start(self):
1177- doc1 = self.db.create_doc('{"key": "value4"}')
1178- doc2 = self.db.create_doc('{"key": "value23"}')
1179- doc3 = self.db.create_doc('{"key": "value2"}')
1180- doc4 = self.db.create_doc('{"key": "value22"}')
1181- self.db.create_doc('{"key": "value1"}')
1182+ doc1 = self.db.create_doc_from_json('{"key": "value4"}')
1183+ doc2 = self.db.create_doc_from_json('{"key": "value23"}')
1184+ doc3 = self.db.create_doc_from_json('{"key": "value2"}')
1185+ doc4 = self.db.create_doc_from_json('{"key": "value22"}')
1186+ self.db.create_doc_from_json('{"key": "value1"}')
1187 self.db.create_index('test-idx', 'key')
1188 self.assertEqual(
1189 [doc3, doc4, doc2, doc1],
1190 self.db.get_range_from_index('test-idx', 'value2*'))
1191
1192 def test_get_wildcard_range_from_index_end(self):
1193- self.db.create_doc('{"key": "value4"}')
1194- doc2 = self.db.create_doc('{"key": "value23"}')
1195- doc3 = self.db.create_doc('{"key": "value2"}')
1196- doc4 = self.db.create_doc('{"key": "value22"}')
1197- doc5 = self.db.create_doc('{"key": "value1"}')
1198+ self.db.create_doc_from_json('{"key": "value4"}')
1199+ doc2 = self.db.create_doc_from_json('{"key": "value23"}')
1200+ doc3 = self.db.create_doc_from_json('{"key": "value2"}')
1201+ doc4 = self.db.create_doc_from_json('{"key": "value22"}')
1202+ doc5 = self.db.create_doc_from_json('{"key": "value1"}')
1203 self.db.create_index('test-idx', 'key')
1204 self.assertEqual(
1205 [doc5, doc3, doc4, doc2],
1206 self.db.get_range_from_index('test-idx', None, 'value2*'))
1207
1208 def test_get_wildcard_range_from_index_start_end(self):
1209- self.db.create_doc('{"key": "a"}')
1210- self.db.create_doc('{"key": "boo3"}')
1211- doc3 = self.db.create_doc('{"key": "catalyst"}')
1212- doc4 = self.db.create_doc('{"key": "whaever"}')
1213- self.db.create_doc('{"key": "zerg"}')
1214+ self.db.create_doc_from_json('{"key": "a"}')
1215+ self.db.create_doc_from_json('{"key": "boo3"}')
1216+ doc3 = self.db.create_doc_from_json('{"key": "catalyst"}')
1217+ doc4 = self.db.create_doc_from_json('{"key": "whaever"}')
1218+ self.db.create_doc_from_json('{"key": "zerg"}')
1219 self.db.create_index('test-idx', 'key')
1220 self.assertEqual(
1221 [doc3, doc4],
1222 self.db.get_range_from_index('test-idx', 'cat*', 'zap*'))
1223
1224 def test_get_range_from_index_multi_column_start_end(self):
1225- self.db.create_doc('{"key": "value3", "key2": "value4"}')
1226- doc2 = self.db.create_doc('{"key": "value2", "key2": "value3"}')
1227- doc3 = self.db.create_doc('{"key": "value2", "key2": "value2"}')
1228- self.db.create_doc('{"key": "value1", "key2": "value1"}')
1229+ self.db.create_doc_from_json('{"key": "value3", "key2": "value4"}')
1230+ doc2 = self.db.create_doc_from_json(
1231+ '{"key": "value2", "key2": "value3"}')
1232+ doc3 = self.db.create_doc_from_json(
1233+ '{"key": "value2", "key2": "value2"}')
1234+ self.db.create_doc_from_json('{"key": "value1", "key2": "value1"}')
1235 self.db.create_index('test-idx', 'key', 'key2')
1236 self.assertEqual(
1237 [doc3, doc2],
1238@@ -1161,20 +1171,25 @@
1239 'test-idx', ('value2', 'value2'), ('value2', 'value3')))
1240
1241 def test_get_range_from_index_multi_column_start(self):
1242- doc1 = self.db.create_doc('{"key": "value3", "key2": "value4"}')
1243- doc2 = self.db.create_doc('{"key": "value2", "key2": "value3"}')
1244- self.db.create_doc('{"key": "value2", "key2": "value2"}')
1245- self.db.create_doc('{"key": "value1", "key2": "value1"}')
1246+ doc1 = self.db.create_doc_from_json(
1247+ '{"key": "value3", "key2": "value4"}')
1248+ doc2 = self.db.create_doc_from_json(
1249+ '{"key": "value2", "key2": "value3"}')
1250+ self.db.create_doc_from_json('{"key": "value2", "key2": "value2"}')
1251+ self.db.create_doc_from_json('{"key": "value1", "key2": "value1"}')
1252 self.db.create_index('test-idx', 'key', 'key2')
1253 self.assertEqual(
1254 [doc2, doc1],
1255 self.db.get_range_from_index('test-idx', ('value2', 'value3')))
1256
1257 def test_get_range_from_index_multi_column_end(self):
1258- self.db.create_doc('{"key": "value3", "key2": "value4"}')
1259- doc2 = self.db.create_doc('{"key": "value2", "key2": "value3"}')
1260- doc3 = self.db.create_doc('{"key": "value2", "key2": "value2"}')
1261- doc4 = self.db.create_doc('{"key": "value1", "key2": "value1"}')
1262+ self.db.create_doc_from_json('{"key": "value3", "key2": "value4"}')
1263+ doc2 = self.db.create_doc_from_json(
1264+ '{"key": "value2", "key2": "value3"}')
1265+ doc3 = self.db.create_doc_from_json(
1266+ '{"key": "value2", "key2": "value2"}')
1267+ doc4 = self.db.create_doc_from_json(
1268+ '{"key": "value1", "key2": "value1"}')
1269 self.db.create_index('test-idx', 'key', 'key2')
1270 self.assertEqual(
1271 [doc4, doc3, doc2],
1272@@ -1182,20 +1197,26 @@
1273 'test-idx', None, ('value2', 'value3')))
1274
1275 def test_get_wildcard_range_from_index_multi_column_start(self):
1276- doc1 = self.db.create_doc('{"key": "value3", "key2": "value4"}')
1277- doc2 = self.db.create_doc('{"key": "value2", "key2": "value23"}')
1278- doc3 = self.db.create_doc('{"key": "value2", "key2": "value2"}')
1279- self.db.create_doc('{"key": "value1", "key2": "value1"}')
1280+ doc1 = self.db.create_doc_from_json(
1281+ '{"key": "value3", "key2": "value4"}')
1282+ doc2 = self.db.create_doc_from_json(
1283+ '{"key": "value2", "key2": "value23"}')
1284+ doc3 = self.db.create_doc_from_json(
1285+ '{"key": "value2", "key2": "value2"}')
1286+ self.db.create_doc_from_json('{"key": "value1", "key2": "value1"}')
1287 self.db.create_index('test-idx', 'key', 'key2')
1288 self.assertEqual(
1289 [doc3, doc2, doc1],
1290 self.db.get_range_from_index('test-idx', ('value2', 'value2*')))
1291
1292 def test_get_wildcard_range_from_index_multi_column_end(self):
1293- self.db.create_doc('{"key": "value3", "key2": "value4"}')
1294- doc2 = self.db.create_doc('{"key": "value2", "key2": "value23"}')
1295- doc3 = self.db.create_doc('{"key": "value2", "key2": "value2"}')
1296- doc4 = self.db.create_doc('{"key": "value1", "key2": "value1"}')
1297+ self.db.create_doc_from_json('{"key": "value3", "key2": "value4"}')
1298+ doc2 = self.db.create_doc_from_json(
1299+ '{"key": "value2", "key2": "value23"}')
1300+ doc3 = self.db.create_doc_from_json(
1301+ '{"key": "value2", "key2": "value2"}')
1302+ doc4 = self.db.create_doc_from_json(
1303+ '{"key": "value1", "key2": "value1"}')
1304 self.db.create_index('test-idx', 'key', 'key2')
1305 self.assertEqual(
1306 [doc4, doc3, doc2],
1307@@ -1203,20 +1224,25 @@
1308 'test-idx', None, ('value2', 'value2*')))
1309
1310 def test_get_glob_range_from_index_multi_column_start(self):
1311- doc1 = self.db.create_doc('{"key": "value3", "key2": "value4"}')
1312- doc2 = self.db.create_doc('{"key": "value2", "key2": "value23"}')
1313- self.db.create_doc('{"key": "value1", "key2": "value2"}')
1314- self.db.create_doc('{"key": "value1", "key2": "value1"}')
1315+ doc1 = self.db.create_doc_from_json(
1316+ '{"key": "value3", "key2": "value4"}')
1317+ doc2 = self.db.create_doc_from_json(
1318+ '{"key": "value2", "key2": "value23"}')
1319+ self.db.create_doc_from_json('{"key": "value1", "key2": "value2"}')
1320+ self.db.create_doc_from_json('{"key": "value1", "key2": "value1"}')
1321 self.db.create_index('test-idx', 'key', 'key2')
1322 self.assertEqual(
1323 [doc2, doc1],
1324 self.db.get_range_from_index('test-idx', ('value2', '*')))
1325
1326 def test_get_glob_range_from_index_multi_column_end(self):
1327- self.db.create_doc('{"key": "value3", "key2": "value4"}')
1328- doc2 = self.db.create_doc('{"key": "value2", "key2": "value23"}')
1329- doc3 = self.db.create_doc('{"key": "value1", "key2": "value2"}')
1330- doc4 = self.db.create_doc('{"key": "value1", "key2": "value1"}')
1331+ self.db.create_doc_from_json('{"key": "value3", "key2": "value4"}')
1332+ doc2 = self.db.create_doc_from_json(
1333+ '{"key": "value2", "key2": "value23"}')
1334+ doc3 = self.db.create_doc_from_json(
1335+ '{"key": "value1", "key2": "value2"}')
1336+ doc4 = self.db.create_doc_from_json(
1337+ '{"key": "value1", "key2": "value1"}')
1338 self.db.create_index('test-idx', 'key', 'key2')
1339 self.assertEqual(
1340 [doc4, doc3, doc2],
1341@@ -1260,7 +1286,7 @@
1342 self.assertEqual([], self.db.get_index_keys('test-idx'))
1343
1344 def test_put_updates_index(self):
1345- doc = self.db.create_doc(simple_doc)
1346+ doc = self.db.create_doc_from_json(simple_doc)
1347 self.db.create_index('test-idx', 'key')
1348 new_content = '{"key": "altval"}'
1349 doc.set_json(new_content)
1350@@ -1269,8 +1295,8 @@
1351 self.assertEqual([doc], self.db.get_from_index('test-idx', 'altval'))
1352
1353 def test_delete_updates_index(self):
1354- doc = self.db.create_doc(simple_doc)
1355- doc2 = self.db.create_doc(simple_doc)
1356+ doc = self.db.create_doc_from_json(simple_doc)
1357+ doc2 = self.db.create_doc_from_json(simple_doc)
1358 self.db.create_index('test-idx', 'key')
1359 self.assertEqual(
1360 sorted([doc, doc2]),
1361@@ -1303,12 +1329,12 @@
1362
1363 def test_get_all_from_index(self):
1364 self.db.create_index('test-idx', 'key')
1365- doc1 = self.db.create_doc(simple_doc)
1366- doc2 = self.db.create_doc(nested_doc)
1367+ doc1 = self.db.create_doc_from_json(simple_doc)
1368+ doc2 = self.db.create_doc_from_json(nested_doc)
1369 # This one should not be in the index
1370- self.db.create_doc('{"no": "key"}')
1371+ self.db.create_doc_from_json('{"no": "key"}')
1372 diff_value_doc = '{"key": "diff value"}'
1373- doc4 = self.db.create_doc(diff_value_doc)
1374+ doc4 = self.db.create_doc_from_json(diff_value_doc)
1375 # This is essentially a 'prefix' match, but we match every entry.
1376 self.assertEqual(
1377 sorted([doc1, doc2, doc4]),
1378@@ -1316,16 +1342,16 @@
1379
1380 def test_get_all_from_index_ordered(self):
1381 self.db.create_index('test-idx', 'key')
1382- doc1 = self.db.create_doc('{"key": "value x"}')
1383- doc2 = self.db.create_doc('{"key": "value b"}')
1384- doc3 = self.db.create_doc('{"key": "value a"}')
1385- doc4 = self.db.create_doc('{"key": "value m"}')
1386+ doc1 = self.db.create_doc_from_json('{"key": "value x"}')
1387+ doc2 = self.db.create_doc_from_json('{"key": "value b"}')
1388+ doc3 = self.db.create_doc_from_json('{"key": "value a"}')
1389+ doc4 = self.db.create_doc_from_json('{"key": "value m"}')
1390 # This is essentially a 'prefix' match, but we match every entry.
1391 self.assertEqual(
1392 [doc3, doc2, doc4, doc1], self.db.get_from_index('test-idx', '*'))
1393
1394 def test_put_updates_when_adding_key(self):
1395- doc = self.db.create_doc("{}")
1396+ doc = self.db.create_doc_from_json("{}")
1397 self.db.create_index('test-idx', 'key')
1398 self.assertEqual([], self.db.get_from_index('test-idx', '*'))
1399 doc.set_json(simple_doc)
1400@@ -1334,9 +1360,9 @@
1401
1402 def test_get_from_index_empty_string(self):
1403 self.db.create_index('test-idx', 'key')
1404- doc1 = self.db.create_doc(simple_doc)
1405+ doc1 = self.db.create_doc_from_json(simple_doc)
1406 content2 = '{"key": ""}'
1407- doc2 = self.db.create_doc(content2)
1408+ doc2 = self.db.create_doc_from_json(content2)
1409 self.assertEqual([doc2], self.db.get_from_index('test-idx', ''))
1410 # Empty string matches the wildcard.
1411 self.assertEqual(
1412@@ -1345,8 +1371,8 @@
1413
1414 def test_get_from_index_not_null(self):
1415 self.db.create_index('test-idx', 'key')
1416- doc1 = self.db.create_doc(simple_doc)
1417- self.db.create_doc('{"key": null}')
1418+ doc1 = self.db.create_doc_from_json(simple_doc)
1419+ self.db.create_doc_from_json('{"key": null}')
1420 self.assertEqual([doc1], self.db.get_from_index('test-idx', '*'))
1421
1422 def test_get_partial_from_index(self):
1423@@ -1355,10 +1381,10 @@
1424 content3 = '{"k1": "v1", "k2": "y2"}'
1425 # doc4 has a different k1 value, so it doesn't match the prefix.
1426 content4 = '{"k1": "NN", "k2": "v2"}'
1427- doc1 = self.db.create_doc(content1)
1428- doc2 = self.db.create_doc(content2)
1429- doc3 = self.db.create_doc(content3)
1430- self.db.create_doc(content4)
1431+ doc1 = self.db.create_doc_from_json(content1)
1432+ doc2 = self.db.create_doc_from_json(content2)
1433+ doc3 = self.db.create_doc_from_json(content3)
1434+ self.db.create_doc_from_json(content4)
1435 self.db.create_index('test-idx', 'k1', 'k2')
1436 self.assertEqual(
1437 sorted([doc1, doc2, doc3]),
1438@@ -1372,32 +1398,32 @@
1439 # doc4 has a different k2 prefix value, so it doesn't match
1440 content4 = '{"k1": "v1", "k2": "ZZ"}'
1441 self.db.create_index('test-idx', 'k1', 'k2')
1442- doc1 = self.db.create_doc(content1)
1443- doc2 = self.db.create_doc(content2)
1444- doc3 = self.db.create_doc(content3)
1445- self.db.create_doc(content4)
1446+ doc1 = self.db.create_doc_from_json(content1)
1447+ doc2 = self.db.create_doc_from_json(content2)
1448+ doc3 = self.db.create_doc_from_json(content3)
1449+ self.db.create_doc_from_json(content4)
1450 self.assertEqual(
1451 sorted([doc1, doc2, doc3]),
1452 sorted(self.db.get_from_index('test-idx', "v1", "v*")))
1453
1454 def test_nested_index(self):
1455- doc = self.db.create_doc(nested_doc)
1456+ doc = self.db.create_doc_from_json(nested_doc)
1457 self.db.create_index('test-idx', 'sub.doc')
1458 self.assertEqual(
1459 [doc], self.db.get_from_index('test-idx', 'underneath'))
1460- doc2 = self.db.create_doc(nested_doc)
1461+ doc2 = self.db.create_doc_from_json(nested_doc)
1462 self.assertEqual(
1463 sorted([doc, doc2]),
1464 sorted(self.db.get_from_index('test-idx', 'underneath')))
1465
1466 def test_nested_nonexistent(self):
1467- self.db.create_doc(nested_doc)
1468+ self.db.create_doc_from_json(nested_doc)
1469 # sub exists, but sub.foo does not:
1470 self.db.create_index('test-idx', 'sub.foo')
1471 self.assertEqual([], self.db.get_from_index('test-idx', '*'))
1472
1473 def test_nested_nonexistent2(self):
1474- self.db.create_doc(nested_doc)
1475+ self.db.create_doc_from_json(nested_doc)
1476 # sub exists, but sub.foo does not:
1477 self.db.create_index('test-idx', 'sub.foo.bar.baz.qux.fnord')
1478 self.assertEqual([], self.db.get_from_index('test-idx', '*'))
1479@@ -1405,20 +1431,20 @@
1480 def test_index_list1(self):
1481 self.db.create_index("index", "name")
1482 content = '{"name": ["foo", "bar"]}'
1483- doc = self.db.create_doc(content)
1484+ doc = self.db.create_doc_from_json(content)
1485 rows = self.db.get_from_index("index", "bar")
1486 self.assertEqual([doc], rows)
1487
1488 def test_index_list2(self):
1489 self.db.create_index("index", "name")
1490 content = '{"name": ["foo", "bar"]}'
1491- doc = self.db.create_doc(content)
1492+ doc = self.db.create_doc_from_json(content)
1493 rows = self.db.get_from_index("index", "foo")
1494 self.assertEqual([doc], rows)
1495
1496 def test_get_from_index_case_sensitive(self):
1497 self.db.create_index('test-idx', 'key')
1498- doc1 = self.db.create_doc(simple_doc)
1499+ doc1 = self.db.create_doc_from_json(simple_doc)
1500 self.assertEqual([], self.db.get_from_index('test-idx', 'V*'))
1501 self.assertEqual([doc1], self.db.get_from_index('test-idx', 'v*'))
1502
1503@@ -1439,9 +1465,9 @@
1504 content1 = '{"key": "va%lue"}'
1505 content2 = '{"key": "value"}'
1506 content3 = '{"key": "va_lue"}'
1507- doc1 = self.db.create_doc(content1)
1508- self.db.create_doc(content2)
1509- doc3 = self.db.create_doc(content3)
1510+ doc1 = self.db.create_doc_from_json(content1)
1511+ self.db.create_doc_from_json(content2)
1512+ doc3 = self.db.create_doc_from_json(content3)
1513 # The '%' in the search should be treated literally, not as a sql
1514 # globbing character.
1515 self.assertEqual([doc1], self.db.get_from_index('test-idx', 'va%*'))
1516@@ -1451,21 +1477,21 @@
1517 def test_get_from_index_with_lower(self):
1518 self.db.create_index("index", "lower(name)")
1519 content = '{"name": "Foo"}'
1520- doc = self.db.create_doc(content)
1521+ doc = self.db.create_doc_from_json(content)
1522 rows = self.db.get_from_index("index", "foo")
1523 self.assertEqual([doc], rows)
1524
1525 def test_get_from_index_with_lower_matches_same_case(self):
1526 self.db.create_index("index", "lower(name)")
1527 content = '{"name": "foo"}'
1528- doc = self.db.create_doc(content)
1529+ doc = self.db.create_doc_from_json(content)
1530 rows = self.db.get_from_index("index", "foo")
1531 self.assertEqual([doc], rows)
1532
1533 def test_index_lower_doesnt_match_different_case(self):
1534 self.db.create_index("index", "lower(name)")
1535 content = '{"name": "Foo"}'
1536- self.db.create_doc(content)
1537+ self.db.create_doc_from_json(content)
1538 rows = self.db.get_from_index("index", "Foo")
1539 self.assertEqual([], rows)
1540
1541@@ -1473,93 +1499,93 @@
1542 self.db.create_index("index", "lower(name)")
1543 self.db.create_index("other_index", "name")
1544 content = '{"name": "Foo"}'
1545- self.db.create_doc(content)
1546+ self.db.create_doc_from_json(content)
1547 rows = self.db.get_from_index("index", "Foo")
1548 self.assertEqual(0, len(rows))
1549
1550 def test_index_split_words_match_first(self):
1551 self.db.create_index("index", "split_words(name)")
1552 content = '{"name": "foo bar"}'
1553- doc = self.db.create_doc(content)
1554+ doc = self.db.create_doc_from_json(content)
1555 rows = self.db.get_from_index("index", "foo")
1556 self.assertEqual([doc], rows)
1557
1558 def test_index_split_words_match_second(self):
1559 self.db.create_index("index", "split_words(name)")
1560 content = '{"name": "foo bar"}'
1561- doc = self.db.create_doc(content)
1562+ doc = self.db.create_doc_from_json(content)
1563 rows = self.db.get_from_index("index", "bar")
1564 self.assertEqual([doc], rows)
1565
1566 def test_index_split_words_match_both(self):
1567 self.db.create_index("index", "split_words(name)")
1568 content = '{"name": "foo foo"}'
1569- doc = self.db.create_doc(content)
1570+ doc = self.db.create_doc_from_json(content)
1571 rows = self.db.get_from_index("index", "foo")
1572 self.assertEqual([doc], rows)
1573
1574 def test_index_split_words_double_space(self):
1575 self.db.create_index("index", "split_words(name)")
1576 content = '{"name": "foo bar"}'
1577- doc = self.db.create_doc(content)
1578+ doc = self.db.create_doc_from_json(content)
1579 rows = self.db.get_from_index("index", "bar")
1580 self.assertEqual([doc], rows)
1581
1582 def test_index_split_words_leading_space(self):
1583 self.db.create_index("index", "split_words(name)")
1584 content = '{"name": " foo bar"}'
1585- doc = self.db.create_doc(content)
1586+ doc = self.db.create_doc_from_json(content)
1587 rows = self.db.get_from_index("index", "foo")
1588 self.assertEqual([doc], rows)
1589
1590 def test_index_split_words_trailing_space(self):
1591 self.db.create_index("index", "split_words(name)")
1592 content = '{"name": "foo bar "}'
1593- doc = self.db.create_doc(content)
1594+ doc = self.db.create_doc_from_json(content)
1595 rows = self.db.get_from_index("index", "bar")
1596 self.assertEqual([doc], rows)
1597
1598 def test_get_from_index_with_number(self):
1599 self.db.create_index("index", "number(foo, 5)")
1600 content = '{"foo": 12}'
1601- doc = self.db.create_doc(content)
1602+ doc = self.db.create_doc_from_json(content)
1603 rows = self.db.get_from_index("index", "00012")
1604 self.assertEqual([doc], rows)
1605
1606 def test_get_from_index_with_number_bigger_than_padding(self):
1607 self.db.create_index("index", "number(foo, 5)")
1608 content = '{"foo": 123456}'
1609- doc = self.db.create_doc(content)
1610+ doc = self.db.create_doc_from_json(content)
1611 rows = self.db.get_from_index("index", "123456")
1612 self.assertEqual([doc], rows)
1613
1614 def test_number_mapping_ignores_non_numbers(self):
1615 self.db.create_index("index", "number(foo, 5)")
1616 content = '{"foo": 56}'
1617- doc1 = self.db.create_doc(content)
1618+ doc1 = self.db.create_doc_from_json(content)
1619 content = '{"foo": "this is not a maigret painting"}'
1620- self.db.create_doc(content)
1621+ self.db.create_doc_from_json(content)
1622 rows = self.db.get_from_index("index", "*")
1623 self.assertEqual([doc1], rows)
1624
1625 def test_get_from_index_with_bool(self):
1626 self.db.create_index("index", "bool(foo)")
1627 content = '{"foo": true}'
1628- doc = self.db.create_doc(content)
1629+ doc = self.db.create_doc_from_json(content)
1630 rows = self.db.get_from_index("index", "1")
1631 self.assertEqual([doc], rows)
1632
1633 def test_get_from_index_with_bool_false(self):
1634 self.db.create_index("index", "bool(foo)")
1635 content = '{"foo": false}'
1636- doc = self.db.create_doc(content)
1637+ doc = self.db.create_doc_from_json(content)
1638 rows = self.db.get_from_index("index", "0")
1639 self.assertEqual([doc], rows)
1640
1641 def test_get_from_index_with_non_bool(self):
1642 self.db.create_index("index", "bool(foo)")
1643 content = '{"foo": 42}'
1644- self.db.create_doc(content)
1645+ self.db.create_doc_from_json(content)
1646 rows = self.db.get_from_index("index", "*")
1647 self.assertEqual([], rows)
1648
1649@@ -1568,9 +1594,9 @@
1650 content1 = '{"key": "value1"}'
1651 content2 = '{"key": "value2"}'
1652 content3 = '{"key": "value2"}'
1653- self.db.create_doc(content1)
1654- self.db.create_doc(content2)
1655- self.db.create_doc(content3)
1656+ self.db.create_doc_from_json(content1)
1657+ self.db.create_doc_from_json(content2)
1658+ self.db.create_doc_from_json(content3)
1659 self.assertEqual(
1660 [('value1',), ('value2',)],
1661 sorted(self.db.get_index_keys('test-idx')))
1662@@ -1581,10 +1607,10 @@
1663 content2 = '{"key1": "value2", "key2": "val2-2"}'
1664 content3 = '{"key1": "value2", "key2": "val2-2"}'
1665 content4 = '{"key1": "value2", "key2": "val3"}'
1666- self.db.create_doc(content1)
1667- self.db.create_doc(content2)
1668- self.db.create_doc(content3)
1669- self.db.create_doc(content4)
1670+ self.db.create_doc_from_json(content1)
1671+ self.db.create_doc_from_json(content2)
1672+ self.db.create_doc_from_json(content3)
1673+ self.db.create_doc_from_json(content4)
1674 self.assertEqual([
1675 ('value1', 'val2-1'),
1676 ('value2', 'val2-2'),
1677@@ -1594,13 +1620,17 @@
1678
1679 class PythonBackendTests(tests.DatabaseBaseTests):
1680
1681+ def setUp(self):
1682+ super(PythonBackendTests, self).setUp()
1683+ self.simple_doc = simplejson.loads(simple_doc)
1684+
1685 def test_create_doc_with_factory(self):
1686 self.db.set_document_factory(TestAlternativeDocument)
1687- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
1688+ doc = self.db.create_doc(self.simple_doc, doc_id='my_doc_id')
1689 self.assertTrue(isinstance(doc, TestAlternativeDocument))
1690
1691 def test_get_doc_after_put_with_factory(self):
1692- doc = self.db.create_doc(simple_doc, doc_id='my_doc_id')
1693+ doc = self.db.create_doc(self.simple_doc, doc_id='my_doc_id')
1694 self.db.set_document_factory(TestAlternativeDocument)
1695 result = self.db.get_doc('my_doc_id')
1696 self.assertTrue(isinstance(result, TestAlternativeDocument))
1697@@ -1615,13 +1645,13 @@
1698
1699 def test_get_all_docs_with_factory(self):
1700 self.db.set_document_factory(TestAlternativeDocument)
1701- self.db.create_doc(simple_doc)
1702+ self.db.create_doc(self.simple_doc)
1703 self.assertTrue(isinstance(
1704 self.db.get_all_docs()[1][0], TestAlternativeDocument))
1705
1706 def test_get_docs_conflicted_with_factory(self):
1707 self.db.set_document_factory(TestAlternativeDocument)
1708- doc1 = self.db.create_doc(simple_doc)
1709+ doc1 = self.db.create_doc(self.simple_doc)
1710 doc2 = self.make_document(doc1.doc_id, 'alternate:1', nested_doc)
1711 self.db._put_doc_if_newer(
1712 doc2, save_conflict=True, replica_uid='r', replica_gen=1,
1713@@ -1632,7 +1662,7 @@
1714
1715 def test_get_from_index_with_factory(self):
1716 self.db.set_document_factory(TestAlternativeDocument)
1717- self.db.create_doc(simple_doc)
1718+ self.db.create_doc(self.simple_doc)
1719 self.db.create_index('test-idx', 'key')
1720 self.assertTrue(
1721 isinstance(
1722@@ -1640,7 +1670,7 @@
1723 TestAlternativeDocument))
1724
1725 def test_sync_exchange_updates_indexes(self):
1726- doc = self.db.create_doc(simple_doc)
1727+ doc = self.db.create_doc(self.simple_doc)
1728 self.db.create_index('test-idx', 'key')
1729 new_content = '{"key": "altval"}'
1730 other_rev = 'test:1|z:2'
1731
1732=== modified file 'u1db/tests/test_c_backend.py'
1733--- u1db/tests/test_c_backend.py 2012-07-06 20:48:40 +0000
1734+++ u1db/tests/test_c_backend.py 2012-07-19 20:11:24 +0000
1735@@ -70,13 +70,13 @@
1736 def test__get_generation(self):
1737 db = c_backend_wrapper.CDatabase(':memory:')
1738 self.assertEqual(0, db._get_generation())
1739- db.create_doc(tests.simple_doc)
1740+ db.create_doc_from_json(tests.simple_doc)
1741 self.assertEqual(1, db._get_generation())
1742
1743 def test__get_generation_info(self):
1744 db = c_backend_wrapper.CDatabase(':memory:')
1745 self.assertEqual((0, ''), db._get_generation_info())
1746- db.create_doc(tests.simple_doc)
1747+ db.create_doc_from_json(tests.simple_doc)
1748 info = db._get_generation_info()
1749 self.assertEqual(1, info[0])
1750 self.assertTrue(info[1].startswith('T-'))
1751@@ -107,14 +107,14 @@
1752 # We manually poke data into the DB, so that we test just the "get_doc"
1753 # code, rather than also testing the index management code.
1754 self.db = c_backend_wrapper.CDatabase(':memory:')
1755- doc = self.db.create_doc(tests.simple_doc)
1756+ doc = self.db.create_doc_from_json(tests.simple_doc)
1757 self.db.create_index_list("key-idx", ["key"])
1758 docs = self.db.get_from_index('key-idx', 'value')
1759 self.assertEqual([doc], docs)
1760
1761 def test_create_index_list_on_non_ascii_field_name(self):
1762 self.db = c_backend_wrapper.CDatabase(':memory:')
1763- doc = self.db.create_doc(simplejson.dumps({u'\xe5': 'value'}))
1764+ doc = self.db.create_doc_from_json(simplejson.dumps({u'\xe5': 'value'}))
1765 self.db.create_index_list('test-idx', [u'\xe5'])
1766 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1767
1768@@ -126,13 +126,13 @@
1769
1770 def test_create_index_evaluates_it(self):
1771 self.db = c_backend_wrapper.CDatabase(':memory:')
1772- doc = self.db.create_doc(tests.simple_doc)
1773+ doc = self.db.create_doc_from_json(tests.simple_doc)
1774 self.db.create_index_list('test-idx', ['key'])
1775 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1776
1777 def test_wildcard_matches_unicode_value(self):
1778 self.db = c_backend_wrapper.CDatabase(':memory:')
1779- doc = self.db.create_doc(simplejson.dumps({"key": u"valu\xe5"}))
1780+ doc = self.db.create_doc_from_json(simplejson.dumps({"key": u"valu\xe5"}))
1781 self.db.create_index_list('test-idx', ['key'])
1782 self.assertEqual([doc], self.db.get_from_index('test-idx', '*'))
1783
1784@@ -151,8 +151,8 @@
1785
1786 def test_create_index_after_deleting_document(self):
1787 self.db = c_backend_wrapper.CDatabase(':memory:')
1788- doc = self.db.create_doc(tests.simple_doc)
1789- doc2 = self.db.create_doc(tests.simple_doc)
1790+ doc = self.db.create_doc_from_json(tests.simple_doc)
1791+ doc2 = self.db.create_doc_from_json(tests.simple_doc)
1792 self.db.delete_doc(doc2)
1793 self.db.create_index_list('test-idx', ['key'])
1794 self.assertEqual([doc], self.db.get_from_index('test-idx', 'value'))
1795@@ -161,7 +161,7 @@
1796 # We manually poke data into the DB, so that we test just the "get_doc"
1797 # code, rather than also testing the index management code.
1798 self.db = c_backend_wrapper.CDatabase(':memory:')
1799- doc = self.db.create_doc(tests.simple_doc)
1800+ doc = self.db.create_doc_from_json(tests.simple_doc)
1801 self.db.create_index("key-idx", "key")
1802 docs = self.db.get_from_index('key-idx', 'value')
1803 self.assertEqual([doc], docs)
1804@@ -170,7 +170,7 @@
1805 # We manually poke data into the DB, so that we test just the "get_doc"
1806 # code, rather than also testing the index management code.
1807 self.db = c_backend_wrapper.CDatabase(':memory:')
1808- doc = self.db.create_doc(tests.simple_doc)
1809+ doc = self.db.create_doc_from_json(tests.simple_doc)
1810 self.db.create_index("key-idx", "key")
1811 docs = self.db.get_from_index_list('key-idx', ['value'])
1812 self.assertEqual([doc], docs)
1813@@ -178,7 +178,7 @@
1814 def test_get_from_index_list_multi(self):
1815 self.db = c_backend_wrapper.CDatabase(':memory:')
1816 content = '{"key": "value", "key2": "value2"}'
1817- doc = self.db.create_doc(content)
1818+ doc = self.db.create_doc_from_json(content)
1819 self.db.create_index('test-idx', 'key', 'key2')
1820 self.assertEqual(
1821 [doc],
1822@@ -186,10 +186,10 @@
1823
1824 def test_get_from_index_list_multi_ordered(self):
1825 self.db = c_backend_wrapper.CDatabase(':memory:')
1826- doc1 = self.db.create_doc('{"key": "value3", "key2": "value4"}')
1827- doc2 = self.db.create_doc('{"key": "value2", "key2": "value3"}')
1828- doc3 = self.db.create_doc('{"key": "value2", "key2": "value2"}')
1829- doc4 = self.db.create_doc('{"key": "value1", "key2": "value1"}')
1830+ doc1 = self.db.create_doc_from_json('{"key": "value3", "key2": "value4"}')
1831+ doc2 = self.db.create_doc_from_json('{"key": "value2", "key2": "value3"}')
1832+ doc3 = self.db.create_doc_from_json('{"key": "value2", "key2": "value2"}')
1833+ doc4 = self.db.create_doc_from_json('{"key": "value1", "key2": "value1"}')
1834 self.db.create_index('test-idx', 'key', 'key2')
1835 self.assertEqual(
1836 [doc4, doc3, doc2, doc1],
1837@@ -197,14 +197,14 @@
1838
1839 def test_get_from_index_2(self):
1840 self.db = c_backend_wrapper.CDatabase(':memory:')
1841- doc = self.db.create_doc(tests.nested_doc)
1842+ doc = self.db.create_doc_from_json(tests.nested_doc)
1843 self.db.create_index("multi-idx", "key", "sub.doc")
1844 docs = self.db.get_from_index('multi-idx', 'value', 'underneath')
1845 self.assertEqual([doc], docs)
1846
1847 def test_get_index_keys(self):
1848 self.db = c_backend_wrapper.CDatabase(':memory:')
1849- self.db.create_doc(tests.simple_doc)
1850+ self.db.create_doc_from_json(tests.simple_doc)
1851 self.db.create_index("key-idx", "key")
1852 keys = self.db.get_index_keys('key-idx')
1853 self.assertEqual([("value",)], keys)
1854@@ -303,7 +303,7 @@
1855 self.assertEqual(['doc-id'], exc.get_seen_ids())
1856
1857 def test_sync_exchange_conflicted_doc(self):
1858- doc = self.db.create_doc(tests.simple_doc)
1859+ doc = self.db.create_doc_from_json(tests.simple_doc)
1860 exc = self.st._get_sync_exchange("source-uid", 5)
1861 doc2 = c_backend_wrapper.make_document(doc.doc_id, 'replica:1',
1862 tests.nested_doc)
1863@@ -315,7 +315,7 @@
1864 self.assertEqual([], exc.get_seen_ids())
1865
1866 def test_sync_exchange_find_doc_ids(self):
1867- doc = self.db.create_doc(tests.simple_doc)
1868+ doc = self.db.create_doc_from_json(tests.simple_doc)
1869 exc = self.st._get_sync_exchange("source-uid", 0)
1870 self.assertEqual(0, exc.target_gen)
1871 exc.find_doc_ids_to_return()
1872@@ -326,8 +326,8 @@
1873 self.assertEqual(1, exc.target_gen)
1874
1875 def test_sync_exchange_find_doc_ids_not_including_recently_inserted(self):
1876- doc1 = self.db.create_doc(tests.simple_doc)
1877- doc2 = self.db.create_doc(tests.nested_doc)
1878+ doc1 = self.db.create_doc_from_json(tests.simple_doc)
1879+ doc2 = self.db.create_doc_from_json(tests.nested_doc)
1880 exc = self.st._get_sync_exchange("source-uid", 0)
1881 doc3 = c_backend_wrapper.make_document(doc1.doc_id,
1882 doc1.rev + "|zreplica:2", tests.simple_doc)
1883@@ -343,16 +343,16 @@
1884 def return_doc_cb(doc, gen, trans_id):
1885 returned.append((doc, gen, trans_id))
1886
1887- doc1 = self.db.create_doc(tests.simple_doc)
1888+ doc1 = self.db.create_doc_from_json(tests.simple_doc)
1889 exc = self.st._get_sync_exchange("source-uid", 0)
1890 exc.find_doc_ids_to_return()
1891 exc.return_docs(return_doc_cb)
1892 self.assertEqual((doc1, 1), returned[0][:-1])
1893
1894 def test_sync_exchange_doc_ids(self):
1895- doc1 = self.db.create_doc(tests.simple_doc, doc_id='doc-1')
1896+ doc1 = self.db.create_doc_from_json(tests.simple_doc, doc_id='doc-1')
1897 db2 = c_backend_wrapper.CDatabase(':memory:')
1898- doc2 = db2.create_doc(tests.nested_doc, doc_id='doc-2')
1899+ doc2 = db2.create_doc_from_json(tests.nested_doc, doc_id='doc-2')
1900 returned = []
1901
1902 def return_doc_cb(doc, gen, trans_id):
1903@@ -419,11 +419,11 @@
1904
1905 def test_trivial_sync(self):
1906 mem_db = self.request_state._create_database('test.db')
1907- mem_doc = mem_db.create_doc(tests.nested_doc)
1908+ mem_doc = mem_db.create_doc_from_json(tests.nested_doc)
1909 url = self.getURL('test.db')
1910 target = c_backend_wrapper.create_http_sync_target(url)
1911 db = c_backend_wrapper.CDatabase(':memory:')
1912- doc = db.create_doc(tests.simple_doc)
1913+ doc = db.create_doc_from_json(tests.simple_doc)
1914 c_backend_wrapper.sync_db_to_target(db, target)
1915 self.assertGetDoc(mem_db, doc.doc_id, doc.rev, doc.get_json(), False)
1916 self.assertGetDoc(db, mem_doc.doc_id, mem_doc.rev, mem_doc.get_json(),
1917@@ -431,7 +431,7 @@
1918
1919 def test_unavailable(self):
1920 mem_db = self.request_state._create_database('test.db')
1921- mem_db.create_doc(tests.nested_doc)
1922+ mem_db.create_doc_from_json(tests.nested_doc)
1923 tries = []
1924
1925 def wrapper(instance, *args, **kwargs):
1926@@ -442,7 +442,7 @@
1927 url = self.getURL('test.db')
1928 target = c_backend_wrapper.create_http_sync_target(url)
1929 db = c_backend_wrapper.CDatabase(':memory:')
1930- db.create_doc(tests.simple_doc)
1931+ db.create_doc_from_json(tests.simple_doc)
1932 self.assertRaises(
1933 errors.Unavailable, c_backend_wrapper.sync_db_to_target, db,
1934 target)
1935@@ -450,7 +450,7 @@
1936
1937 def test_unavailable_then_available(self):
1938 mem_db = self.request_state._create_database('test.db')
1939- mem_doc = mem_db.create_doc(tests.nested_doc)
1940+ mem_doc = mem_db.create_doc_from_json(tests.nested_doc)
1941 orig_whatschanged = mem_db.whats_changed
1942 tries = []
1943
1944@@ -464,7 +464,7 @@
1945 url = self.getURL('test.db')
1946 target = c_backend_wrapper.create_http_sync_target(url)
1947 db = c_backend_wrapper.CDatabase(':memory:')
1948- doc = db.create_doc(tests.simple_doc)
1949+ doc = db.create_doc_from_json(tests.simple_doc)
1950 c_backend_wrapper.sync_db_to_target(db, target)
1951 self.assertEqual(1, len(tries))
1952 self.assertGetDoc(mem_db, doc.doc_id, doc.rev, doc.get_json(), False)
1953@@ -484,13 +484,13 @@
1954
1955 def test_trivial_sync(self):
1956 mem_db = self.request_state._create_database('test.db')
1957- mem_doc = mem_db.create_doc(tests.nested_doc)
1958+ mem_doc = mem_db.create_doc_from_json(tests.nested_doc)
1959 url = self.getURL('~/test.db')
1960 target = c_backend_wrapper.create_oauth_http_sync_target(url,
1961 tests.consumer1.key, tests.consumer1.secret,
1962 tests.token1.key, tests.token1.secret)
1963 db = c_backend_wrapper.CDatabase(':memory:')
1964- doc = db.create_doc(tests.simple_doc)
1965+ doc = db.create_doc_from_json(tests.simple_doc)
1966 c_backend_wrapper.sync_db_to_target(db, target)
1967 self.assertGetDoc(mem_db, doc.doc_id, doc.rev, doc.get_json(), False)
1968 self.assertGetDoc(db, mem_doc.doc_id, mem_doc.rev, mem_doc.get_json(),
1969
1970=== modified file 'u1db/tests/test_http_app.py'
1971--- u1db/tests/test_http_app.py 2012-07-12 17:21:15 +0000
1972+++ u1db/tests/test_http_app.py 2012-07-19 20:11:24 +0000
1973@@ -604,7 +604,7 @@
1974 self.assertEqual({'rev': doc.rev}, simplejson.loads(resp.body))
1975
1976 def test_put_doc(self):
1977- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
1978+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
1979 resp = self.app.put('/db0/doc/doc1?old_rev=%s' % doc.rev,
1980 params='{"x": 2}',
1981 headers={'content-type': 'application/json'})
1982@@ -616,7 +616,7 @@
1983
1984 def test_put_doc_too_large(self):
1985 self.http_app.max_request_size = 15000
1986- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
1987+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
1988 resp = self.app.put('/db0/doc/doc1?old_rev=%s' % doc.rev,
1989 params='{"%s": 2}' % ('z' * 16000),
1990 headers={'content-type': 'application/json'},
1991@@ -624,7 +624,7 @@
1992 self.assertEqual(400, resp.status)
1993
1994 def test_delete_doc(self):
1995- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
1996+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
1997 resp = self.app.delete('/db0/doc/doc1?old_rev=%s' % doc.rev)
1998 doc = self.db0.get_doc('doc1', include_deleted=True)
1999 self.assertEqual(None, doc.content)
2000@@ -633,7 +633,7 @@
2001 self.assertEqual({'rev': doc.rev}, simplejson.loads(resp.body))
2002
2003 def test_get_doc(self):
2004- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2005+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2006 resp = self.app.get('/db0/doc/%s' % doc.doc_id)
2007 self.assertEqual(200, resp.status)
2008 self.assertEqual('application/json', resp.header('content-type'))
2009@@ -651,7 +651,7 @@
2010 self.assertEqual('false', resp.header('x-u1db-has-conflicts'))
2011
2012 def test_get_doc_deleted(self):
2013- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2014+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2015 self.db0.delete_doc(doc)
2016 resp = self.app.get('/db0/doc/doc1', expect_errors=True)
2017 self.assertEqual(404, resp.status)
2018@@ -661,7 +661,7 @@
2019 simplejson.loads(resp.body))
2020
2021 def test_get_doc_deleted_explicit_exclude(self):
2022- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2023+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2024 self.db0.delete_doc(doc)
2025 resp = self.app.get(
2026 '/db0/doc/doc1?include_deleted=false', expect_errors=True)
2027@@ -672,7 +672,7 @@
2028 simplejson.loads(resp.body))
2029
2030 def test_get_deleted_doc(self):
2031- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2032+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2033 self.db0.delete_doc(doc)
2034 resp = self.app.get(
2035 '/db0/doc/doc1?include_deleted=true', expect_errors=True)
2036@@ -691,8 +691,8 @@
2037 simplejson.loads(resp.body))
2038
2039 def test_get_docs(self):
2040- doc1 = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2041- doc2 = self.db0.create_doc('{"x": 1}', doc_id='doc2')
2042+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2043+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
2044 ids = ','.join([doc1.doc_id, doc2.doc_id])
2045 resp = self.app.get('/db0/docs?doc_ids=%s' % ids)
2046 self.assertEqual(200, resp.status)
2047@@ -706,8 +706,8 @@
2048 self.assertEqual(expected, simplejson.loads(resp.body))
2049
2050 def test_get_docs_percent(self):
2051- doc1 = self.db0.create_doc('{"x": 1}', doc_id='doc%1')
2052- doc2 = self.db0.create_doc('{"x": 1}', doc_id='doc2')
2053+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc%1')
2054+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
2055 ids = ','.join([doc1.doc_id, doc2.doc_id])
2056 resp = self.app.get('/db0/docs?doc_ids=%s' % ids)
2057 self.assertEqual(200, resp.status)
2058@@ -721,8 +721,8 @@
2059 self.assertEqual(expected, simplejson.loads(resp.body))
2060
2061 def test_get_docs_deleted(self):
2062- doc1 = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2063- doc2 = self.db0.create_doc('{"x": 1}', doc_id='doc2')
2064+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2065+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
2066 self.db0.delete_doc(doc2)
2067 ids = ','.join([doc1.doc_id, doc2.doc_id])
2068 resp = self.app.get('/db0/docs?doc_ids=%s' % ids)
2069@@ -735,8 +735,8 @@
2070 self.assertEqual(expected, simplejson.loads(resp.body))
2071
2072 def test_get_docs_include_deleted(self):
2073- doc1 = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2074- doc2 = self.db0.create_doc('{"x": 1}', doc_id='doc2')
2075+ doc1 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2076+ doc2 = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc2')
2077 self.db0.delete_doc(doc2)
2078 ids = ','.join([doc1.doc_id, doc2.doc_id])
2079 resp = self.app.get('/db0/docs?doc_ids=%s&include_deleted=true' % ids)
2080@@ -841,8 +841,8 @@
2081 self.assertEqual(400, resp.status)
2082
2083 def test_sync_exchange_receive(self):
2084- doc = self.db0.create_doc('{"value": "there"}')
2085- doc2 = self.db0.create_doc('{"value": "there2"}')
2086+ doc = self.db0.create_doc_from_json('{"value": "there"}')
2087+ doc2 = self.db0.create_doc_from_json('{"value": "there2"}')
2088 args = dict(last_known_generation=0)
2089 body = "[\r\n%s\r\n]" % simplejson.dumps(args)
2090 resp = self.app.post('/db0/sync-from/replica',
2091@@ -920,7 +920,7 @@
2092 self.http_app.request_begin = begin
2093 self.http_app.request_done = done
2094
2095- doc = self.db0.create_doc('{"x": 1}', doc_id='doc1')
2096+ doc = self.db0.create_doc_from_json('{"x": 1}', doc_id='doc1')
2097 self.app.get('/db0/doc/%s' % doc.doc_id)
2098
2099 self.assertEqual(['begin', 'done'], calls)
2100
2101=== modified file 'u1db/tests/test_http_database.py'
2102--- u1db/tests/test_http_database.py 2012-05-24 21:09:21 +0000
2103+++ u1db/tests/test_http_database.py 2012-07-19 20:11:24 +0000
2104@@ -147,7 +147,7 @@
2105
2106 def test_create_doc_with_id(self):
2107 self.response_val = {'rev': 'doc-rev'}, {}
2108- new_doc = self.db.create_doc('{"v": 1}', doc_id='doc-id')
2109+ new_doc = self.db.create_doc_from_json('{"v": 1}', doc_id='doc-id')
2110 self.assertEqual('doc-rev', new_doc.rev)
2111 self.assertEqual('doc-id', new_doc.doc_id)
2112 self.assertEqual('{"v": 1}', new_doc.get_json())
2113@@ -156,7 +156,7 @@
2114
2115 def test_create_doc_without_id(self):
2116 self.response_val = {'rev': 'doc-rev-2'}, {}
2117- new_doc = self.db.create_doc('{"v": 3}')
2118+ new_doc = self.db.create_doc_from_json('{"v": 3}')
2119 self.assertEqual('D-', new_doc.doc_id[:2])
2120 self.assertEqual('doc-rev-2', new_doc.rev)
2121 self.assertEqual('{"v": 3}', new_doc.get_json())
2122
2123=== modified file 'u1db/tests/test_open.py'
2124--- u1db/tests/test_open.py 2012-05-30 16:28:17 +0000
2125+++ u1db/tests/test_open.py 2012-07-19 20:11:24 +0000
2126@@ -54,7 +54,7 @@
2127 def test_open_existing(self):
2128 db = sqlite_backend.SQLitePartialExpandDatabase(self.db_path)
2129 self.addCleanup(db.close)
2130- doc = db.create_doc(tests.simple_doc)
2131+ doc = db.create_doc_from_json(tests.simple_doc)
2132 # Even though create=True, we shouldn't wipe the db
2133 db2 = u1db_open(self.db_path, create=True)
2134 self.addCleanup(db2.close)
2135
2136=== modified file 'u1db/tests/test_remote_sync_target.py'
2137--- u1db/tests/test_remote_sync_target.py 2012-07-06 20:48:40 +0000
2138+++ u1db/tests/test_remote_sync_target.py 2012-07-19 20:11:24 +0000
2139@@ -267,7 +267,7 @@
2140 self.patch(self.server.RequestHandlerClass, 'get_stderr',
2141 blackhole_getstderr)
2142 db = self.request_state._create_database('test')
2143- doc = db.create_doc('{"value": "there"}')
2144+ doc = db.create_doc_from_json('{"value": "there"}')
2145
2146 def bomb_get_docs(doc_ids, check_for_conflicts=None,
2147 include_deleted=False):
2148@@ -294,7 +294,7 @@
2149 def test_sync_exchange_receive(self):
2150 self.startServer()
2151 db = self.request_state._create_database('test')
2152- doc = db.create_doc('{"value": "there"}')
2153+ doc = db.create_doc_from_json('{"value": "there"}')
2154 remote_target = self.getSyncTarget('test')
2155 other_changes = []
2156
2157
2158=== modified file 'u1db/tests/test_sqlite_backend.py'
2159--- u1db/tests/test_sqlite_backend.py 2012-07-06 20:48:40 +0000
2160+++ u1db/tests/test_sqlite_backend.py 2012-07-19 20:11:24 +0000
2161@@ -187,7 +187,7 @@
2162 self.db.list_indexes())
2163
2164 def test_no_indexes_no_document_fields(self):
2165- self.db.create_doc(
2166+ self.db.create_doc_from_json(
2167 '{"key1": "val1", "key2": "val2"}')
2168 c = self.db._get_sqlite_handle().cursor()
2169 c.execute("SELECT doc_id, field_name, value FROM document_fields"
2170@@ -195,8 +195,8 @@
2171 self.assertEqual([], c.fetchall())
2172
2173 def test_create_extracts_fields(self):
2174- doc1 = self.db.create_doc('{"key1": "val1", "key2": "val2"}')
2175- doc2 = self.db.create_doc('{"key1": "valx", "key2": "valy"}')
2176+ doc1 = self.db.create_doc_from_json('{"key1": "val1", "key2": "val2"}')
2177+ doc2 = self.db.create_doc_from_json('{"key1": "valx", "key2": "valy"}')
2178 c = self.db._get_sqlite_handle().cursor()
2179 c.execute("SELECT doc_id, field_name, value FROM document_fields"
2180 " ORDER BY doc_id, field_name, value")
2181@@ -213,7 +213,7 @@
2182
2183 def test_put_updates_fields(self):
2184 self.db.create_index('test', 'key1', 'key2')
2185- doc1 = self.db.create_doc(
2186+ doc1 = self.db.create_doc_from_json(
2187 '{"key1": "val1", "key2": "val2"}')
2188 doc1.content = {"key1": "val1", "key2": "valy"}
2189 self.db.put_doc(doc1)
2190@@ -226,7 +226,7 @@
2191
2192 def test_put_updates_nested_fields(self):
2193 self.db.create_index('test', 'key', 'sub.doc')
2194- doc1 = self.db.create_doc(nested_doc)
2195+ doc1 = self.db.create_doc_from_json(nested_doc)
2196 c = self.db._get_sqlite_handle().cursor()
2197 c.execute("SELECT doc_id, field_name, value FROM document_fields"
2198 " ORDER BY doc_id, field_name, value")
2199@@ -380,7 +380,7 @@
2200
2201 def test_indexed_fields_expanded(self):
2202 self.db.create_index('idx1', 'key1')
2203- doc1 = self.db.create_doc('{"key1": "val1", "key2": "val2"}')
2204+ doc1 = self.db.create_doc_from_json('{"key1": "val1", "key2": "val2"}')
2205 self.assertEqual(set(['key1']), self.db._get_indexed_fields())
2206 c = self.db._get_sqlite_handle().cursor()
2207 c.execute("SELECT doc_id, field_name, value FROM document_fields"
2208@@ -388,7 +388,7 @@
2209 self.assertEqual([(doc1.doc_id, 'key1', 'val1')], c.fetchall())
2210
2211 def test_create_index_updates_fields(self):
2212- doc1 = self.db.create_doc('{"key1": "val1", "key2": "val2"}')
2213+ doc1 = self.db.create_doc_from_json('{"key1": "val1", "key2": "val2"}')
2214 self.db.create_index('idx1', 'key1')
2215 self.assertEqual(set(['key1']), self.db._get_indexed_fields())
2216 c = self.db._get_sqlite_handle().cursor()
2217
2218=== modified file 'u1db/tests/test_sync.py'
2219--- u1db/tests/test_sync.py 2012-07-13 19:35:51 +0000
2220+++ u1db/tests/test_sync.py 2012-07-19 20:11:24 +0000
2221@@ -152,7 +152,7 @@
2222 def test_create_doc_updates_sync_info(self):
2223 self.assertEqual(
2224 ('test', 0, '', 0, ''), self.st.get_sync_info('other'))
2225- self.db.create_doc(simple_doc)
2226+ self.db.create_doc_from_json(simple_doc)
2227 self.assertEqual(1, self.st.get_sync_info('other')[1])
2228
2229 def test_record_sync_info(self):
2230@@ -175,7 +175,7 @@
2231 self.assertEqual(10, self.st.get_sync_info('replica')[3])
2232
2233 def test_sync_exchange_deleted(self):
2234- doc = self.db.create_doc('{}')
2235+ doc = self.db.create_doc_from_json('{}')
2236 edit_rev = 'replica:1|' + doc.rev
2237 docs_by_gen = [
2238 (self.make_document(doc.doc_id, edit_rev, None), 10, 'T-sid')]
2239@@ -207,7 +207,7 @@
2240 self.assertEqual(11, self.st.get_sync_info('replica')[3])
2241
2242 def test_sync_exchange_refuses_conflicts(self):
2243- doc = self.db.create_doc(simple_doc)
2244+ doc = self.db.create_doc_from_json(simple_doc)
2245 self.assertTransactionLog([doc.doc_id], self.db)
2246 new_doc = '{"key": "altval"}'
2247 docs_by_gen = [
2248@@ -225,7 +225,7 @@
2249 {'last_gen': 1, 'docs': [(doc.doc_id, doc.rev)]})
2250
2251 def test_sync_exchange_ignores_convergence(self):
2252- doc = self.db.create_doc(simple_doc)
2253+ doc = self.db.create_doc_from_json(simple_doc)
2254 self.assertTransactionLog([doc.doc_id], self.db)
2255 gen, txid = self.db._get_generation_info()
2256 docs_by_gen = [
2257@@ -237,7 +237,7 @@
2258 self.assertEqual(([], 1), (self.other_changes, new_gen))
2259
2260 def test_sync_exchange_returns_new_docs(self):
2261- doc = self.db.create_doc(simple_doc)
2262+ doc = self.db.create_doc_from_json(simple_doc)
2263 self.assertTransactionLog([doc.doc_id], self.db)
2264 new_gen, _ = self.st.sync_exchange(
2265 [], 'other-replica', last_known_generation=0,
2266@@ -251,7 +251,7 @@
2267 {'last_gen': 1, 'docs': [(doc.doc_id, doc.rev)]})
2268
2269 def test_sync_exchange_returns_deleted_docs(self):
2270- doc = self.db.create_doc(simple_doc)
2271+ doc = self.db.create_doc_from_json(simple_doc)
2272 self.db.delete_doc(doc)
2273 self.assertTransactionLog([doc.doc_id, doc.doc_id], self.db)
2274 new_gen, _ = self.st.sync_exchange(
2275@@ -266,8 +266,8 @@
2276 {'last_gen': 2, 'docs': [(doc.doc_id, doc.rev)]})
2277
2278 def test_sync_exchange_returns_many_new_docs(self):
2279- doc = self.db.create_doc(simple_doc)
2280- doc2 = self.db.create_doc(nested_doc)
2281+ doc = self.db.create_doc_from_json(simple_doc)
2282+ doc2 = self.db.create_doc_from_json(nested_doc)
2283 self.assertTransactionLog([doc.doc_id, doc2.doc_id], self.db)
2284 new_gen, _ = self.st.sync_exchange(
2285 [], 'other-replica', last_known_generation=0,
2286@@ -285,7 +285,7 @@
2287 [(doc.doc_id, doc.rev), (doc2.doc_id, doc2.rev)]})
2288
2289 def test_sync_exchange_getting_newer_docs(self):
2290- doc = self.db.create_doc(simple_doc)
2291+ doc = self.db.create_doc_from_json(simple_doc)
2292 self.assertTransactionLog([doc.doc_id], self.db)
2293 new_doc = '{"key": "altval"}'
2294 docs_by_gen = [
2295@@ -309,7 +309,7 @@
2296 expected.append((doc.doc_id, conc_rev, cont, 3))
2297
2298 self.set_trace_hook(before_whatschanged_cb)
2299- doc = self.db.create_doc(simple_doc)
2300+ doc = self.db.create_doc_from_json(simple_doc)
2301 self.assertTransactionLog([doc.doc_id], self.db)
2302 new_doc = '{"key": "altval"}'
2303 docs_by_gen = [
2304@@ -326,10 +326,10 @@
2305 def after_whatschanged_cb(state):
2306 if state != 'after whats_changed':
2307 return
2308- self.db.create_doc('{"new": "doc"}')
2309+ self.db.create_doc_from_json('{"new": "doc"}')
2310
2311 self.set_trace_hook(after_whatschanged_cb)
2312- doc = self.db.create_doc(simple_doc)
2313+ doc = self.db.create_doc_from_json(simple_doc)
2314 self.assertTransactionLog([doc.doc_id], self.db)
2315 new_doc = '{"key": "altval"}'
2316 docs_by_gen = [
2317@@ -341,7 +341,7 @@
2318 self.assertEqual(([], 2), (self.other_changes, new_gen))
2319
2320 def test_sync_exchange_converged_handling(self):
2321- doc = self.db.create_doc(simple_doc)
2322+ doc = self.db.create_doc_from_json(simple_doc)
2323 docs_by_gen = [
2324 (self.make_document('new', 'other:1', '{}'), 4, 'T-foo'),
2325 (self.make_document(doc.doc_id, doc.rev, doc.get_json()), 5,
2326@@ -360,7 +360,7 @@
2327 # suppress traceback printing in the wsgiref server
2328 self.patch(simple_server.ServerHandler,
2329 'log_exception', lambda h, exc_info: None)
2330- doc = self.db.create_doc(simple_doc)
2331+ doc = self.db.create_doc_from_json(simple_doc)
2332 self.assertTransactionLog([doc.doc_id], self.db)
2333 self.assertRaises(
2334 (errors.U1DBError, errors.BrokenSyncStream),
2335@@ -373,7 +373,7 @@
2336 if sync_exchange_doc_ids is None:
2337 self.skipTest("sync_exchange_doc_ids not implemented")
2338 db2 = self.create_database('test2')
2339- doc = db2.create_doc(simple_doc)
2340+ doc = db2.create_doc_from_json(simple_doc)
2341 new_gen, trans_id = sync_exchange_doc_ids(
2342 db2, [(doc.doc_id, 10, 'T-sid')], 0, None,
2343 return_doc_cb=self.receive_doc)
2344@@ -513,9 +513,9 @@
2345 'return': {'docs': [], 'last_gen': 0}})
2346
2347 def test_sync_autoresolves(self):
2348- doc1 = self.db1.create_doc(simple_doc, doc_id='doc')
2349+ doc1 = self.db1.create_doc_from_json(simple_doc, doc_id='doc')
2350 rev1 = doc1.rev
2351- doc2 = self.db2.create_doc(simple_doc, doc_id='doc')
2352+ doc2 = self.db2.create_doc_from_json(simple_doc, doc_id='doc')
2353 rev2 = doc2.rev
2354 self.sync(self.db1, self.db2)
2355 doc = self.db1.get_doc('doc')
2356@@ -548,7 +548,7 @@
2357 # a3b2 a1b2 (autoresolved)
2358 # `------->
2359 # a3b2 a3b2
2360- self.db1.create_doc(simple_doc, doc_id='doc')
2361+ self.db1.create_doc_from_json(simple_doc, doc_id='doc')
2362 self.sync(self.db1, self.db2)
2363 for db, content in [(self.db1, '{}'), (self.db2, '{"hi": 42}')]:
2364 doc = db.get_doc('doc')
2365@@ -600,7 +600,7 @@
2366 # a1b1+a2 a1b2 (a1b2 has same content as a2)
2367 # <-------'
2368 # a3b2 a3b2 (autoresolved and propagated)
2369- self.db1.create_doc(simple_doc, doc_id='doc')
2370+ self.db1.create_doc_from_json(simple_doc, doc_id='doc')
2371 self.sync(self.db1, self.db2)
2372 for db, content in [(self.db1, '{}'), (self.db2, '{"hi": 42}')]:
2373 doc = db.get_doc('doc')
2374@@ -656,7 +656,7 @@
2375 # `------->
2376 # a2b2c1 a2b2c1 a2c1
2377 self.db3 = self.create_database('test3')
2378- self.db1.create_doc(simple_doc, doc_id='doc')
2379+ self.db1.create_doc_from_json(simple_doc, doc_id='doc')
2380 self.sync(self.db1, self.db2)
2381 self.sync(self.db2, self.db3)
2382 for db, content in [(self.db2, '{"hi": 42}'),
2383@@ -703,7 +703,7 @@
2384 self.assertEqual(self.db1.get_doc('doc'), self.db2.get_doc('doc'))
2385
2386 def test_sync_puts_changes(self):
2387- doc = self.db1.create_doc(simple_doc)
2388+ doc = self.db1.create_doc_from_json(simple_doc)
2389 self.assertEqual(1, self.sync(self.db1, self.db2))
2390 self.assertGetDoc(self.db2, doc.doc_id, doc.rev, simple_doc, False)
2391 self.assertEqual(1, self.db1._get_replica_gen_and_trans_id('test2')[0])
2392@@ -715,7 +715,7 @@
2393 'return': {'docs': [], 'last_gen': 1}})
2394
2395 def test_sync_pulls_changes(self):
2396- doc = self.db2.create_doc(simple_doc)
2397+ doc = self.db2.create_doc_from_json(simple_doc)
2398 self.db1.create_index('test-idx', 'key')
2399 self.assertEqual(0, self.sync(self.db1, self.db2))
2400 self.assertGetDoc(self.db1, doc.doc_id, doc.rev, simple_doc, False)
2401@@ -728,7 +728,7 @@
2402 self.assertEqual([doc], self.db1.get_from_index('test-idx', 'value'))
2403
2404 def test_sync_pulling_doesnt_update_other_if_changed(self):
2405- doc = self.db2.create_doc(simple_doc)
2406+ doc = self.db2.create_doc_from_json(simple_doc)
2407 # After the local side has sent its list of docs, before we start
2408 # receiving the "targets" response, we update the local database with a
2409 # new record.
2410@@ -738,7 +738,7 @@
2411 def before_get_docs(state):
2412 if state != 'before get_docs':
2413 return
2414- self.db1.create_doc(simple_doc)
2415+ self.db1.create_doc_from_json(simple_doc)
2416
2417 self.assertEqual(0, self.sync(self.db1, self.db2,
2418 trace_hook=before_get_docs))
2419@@ -754,7 +754,7 @@
2420 (0, ''), self.db2._get_replica_gen_and_trans_id('test1'))
2421
2422 def test_sync_doesnt_update_other_if_nothing_pulled(self):
2423- self.db1.create_doc(simple_doc)
2424+ self.db1.create_doc_from_json(simple_doc)
2425
2426 def no_record_sync_info(state):
2427 if state != 'record_sync_info':
2428@@ -767,7 +767,7 @@
2429 self.db2._get_replica_gen_and_trans_id(self.db1._replica_uid)[0])
2430
2431 def test_sync_ignores_convergence(self):
2432- doc = self.db1.create_doc(simple_doc)
2433+ doc = self.db1.create_doc_from_json(simple_doc)
2434 self.db3 = self.create_database('test3')
2435 self.assertEqual(1, self.sync(self.db1, self.db3))
2436 self.assertEqual(0, self.sync(self.db2, self.db3))
2437@@ -779,7 +779,7 @@
2438 'return': {'docs': [], 'last_gen': 1}})
2439
2440 def test_sync_ignores_superseded(self):
2441- doc = self.db1.create_doc(simple_doc)
2442+ doc = self.db1.create_doc_from_json(simple_doc)
2443 doc_rev1 = doc.rev
2444 self.db3 = self.create_database('test3')
2445 self.sync(self.db1, self.db3)
2446@@ -798,12 +798,12 @@
2447 self.assertGetDoc(self.db1, doc.doc_id, doc_rev2, new_content, False)
2448
2449 def test_sync_sees_remote_conflicted(self):
2450- doc1 = self.db1.create_doc(simple_doc)
2451+ doc1 = self.db1.create_doc_from_json(simple_doc)
2452 doc_id = doc1.doc_id
2453 doc1_rev = doc1.rev
2454 self.db1.create_index('test-idx', 'key')
2455 new_doc = '{"key": "altval"}'
2456- doc2 = self.db2.create_doc(new_doc, doc_id=doc_id)
2457+ doc2 = self.db2.create_doc_from_json(new_doc, doc_id=doc_id)
2458 doc2_rev = doc2.rev
2459 self.assertTransactionLog([doc1.doc_id], self.db1)
2460 self.sync(self.db1, self.db2)
2461@@ -820,7 +820,7 @@
2462 self.assertEqual([], self.db1.get_from_index('test-idx', 'value'))
2463
2464 def test_sync_sees_remote_delete_conflicted(self):
2465- doc1 = self.db1.create_doc(simple_doc)
2466+ doc1 = self.db1.create_doc_from_json(simple_doc)
2467 doc_id = doc1.doc_id
2468 self.db1.create_index('test-idx', 'key')
2469 self.sync(self.db1, self.db2)
2470@@ -844,7 +844,7 @@
2471 self.assertEqual([], self.db1.get_from_index('test-idx', 'value'))
2472
2473 def test_sync_local_race_conflicted(self):
2474- doc = self.db1.create_doc(simple_doc)
2475+ doc = self.db1.create_doc_from_json(simple_doc)
2476 doc_id = doc.doc_id
2477 doc1_rev = doc.rev
2478 self.db1.create_index('test-idx', 'key')
2479@@ -871,7 +871,7 @@
2480 self.assertEqual([], self.db1.get_from_index('test-idx', 'localval'))
2481
2482 def test_sync_propagates_deletes(self):
2483- doc1 = self.db1.create_doc(simple_doc)
2484+ doc1 = self.db1.create_doc_from_json(simple_doc)
2485 doc_id = doc1.doc_id
2486 self.db1.create_index('test-idx', 'key')
2487 self.sync(self.db1, self.db2)
2488@@ -902,7 +902,7 @@
2489 self.db3, doc_id, deleted_rev, None, False)
2490
2491 def test_sync_propagates_resolution(self):
2492- doc1 = self.db1.create_doc('{"a": 1}', doc_id='the-doc')
2493+ doc1 = self.db1.create_doc_from_json('{"a": 1}', doc_id='the-doc')
2494 db3 = self.create_database('test3')
2495 self.sync(self.db2, self.db1)
2496 self.assertEqual(
2497@@ -940,9 +940,9 @@
2498
2499 def test_sync_supersedes_conflicts(self):
2500 db3 = self.create_database('test3')
2501- doc1 = self.db1.create_doc('{"a": 1}', doc_id='the-doc')
2502- self.db2.create_doc('{"b": 1}', doc_id='the-doc')
2503- db3.create_doc('{"c": 1}', doc_id='the-doc')
2504+ doc1 = self.db1.create_doc_from_json('{"a": 1}', doc_id='the-doc')
2505+ self.db2.create_doc_from_json('{"b": 1}', doc_id='the-doc')
2506+ db3.create_doc_from_json('{"c": 1}', doc_id='the-doc')
2507 self.sync(db3, self.db1)
2508 self.assertEqual(
2509 self.db1._get_generation_info(),
2510@@ -965,7 +965,7 @@
2511 self.assertEqual(3, len(db3.get_doc_conflicts('the-doc')))
2512
2513 def test_sync_stops_after_get_sync_info(self):
2514- self.db1.create_doc(tests.simple_doc)
2515+ self.db1.create_doc_from_json(tests.simple_doc)
2516 self.sync(self.db1, self.db2)
2517
2518 def put_hook(state):
2519@@ -974,60 +974,60 @@
2520 self.sync(self.db1, self.db2, trace_hook=put_hook)
2521
2522 def test_sync_detects_rollback_in_source(self):
2523- self.db1.create_doc(tests.simple_doc, doc_id='doc1')
2524+ self.db1.create_doc_from_json(tests.simple_doc, doc_id='doc1')
2525 self.sync(self.db1, self.db2)
2526 db1_copy = self.copy_database(self.db1)
2527- self.db1.create_doc(tests.simple_doc, doc_id='doc2')
2528+ self.db1.create_doc_from_json(tests.simple_doc, doc_id='doc2')
2529 self.sync(self.db1, self.db2)
2530 self.assertRaises(
2531 errors.InvalidGeneration, self.sync, db1_copy, self.db2)
2532
2533 def test_sync_detects_rollback_in_target(self):
2534- self.db1.create_doc(tests.simple_doc, doc_id="divergent")
2535+ self.db1.create_doc_from_json(tests.simple_doc, doc_id="divergent")
2536 self.sync(self.db1, self.db2)
2537 db2_copy = self.copy_database(self.db2)
2538- self.db2.create_doc(tests.simple_doc, doc_id='doc2')
2539+ self.db2.create_doc_from_json(tests.simple_doc, doc_id='doc2')
2540 self.sync(self.db1, self.db2)
2541 self.assertRaises(
2542 errors.InvalidGeneration, self.sync, self.db1, db2_copy)
2543
2544 def test_sync_detects_diverged_source(self):
2545 db3 = self.copy_database(self.db1)
2546- self.db1.create_doc(tests.simple_doc, doc_id="divergent")
2547- db3.create_doc(tests.simple_doc, doc_id="divergent")
2548+ self.db1.create_doc_from_json(tests.simple_doc, doc_id="divergent")
2549+ db3.create_doc_from_json(tests.simple_doc, doc_id="divergent")
2550 self.sync(self.db1, self.db2)
2551 self.assertRaises(
2552 errors.InvalidTransactionId, self.sync, db3, self.db2)
2553
2554 def test_sync_detects_diverged_target(self):
2555 db3 = self.copy_database(self.db2)
2556- db3.create_doc(tests.nested_doc, doc_id="divergent")
2557- self.db1.create_doc(tests.simple_doc, doc_id="divergent")
2558+ db3.create_doc_from_json(tests.nested_doc, doc_id="divergent")
2559+ self.db1.create_doc_from_json(tests.simple_doc, doc_id="divergent")
2560 self.sync(self.db1, self.db2)
2561 self.assertRaises(
2562 errors.InvalidTransactionId, self.sync, self.db1, db3)
2563
2564 def test_sync_detects_rollback_and_divergence_in_source(self):
2565- self.db1.create_doc(tests.simple_doc, doc_id='doc1')
2566+ self.db1.create_doc_from_json(tests.simple_doc, doc_id='doc1')
2567 self.sync(self.db1, self.db2)
2568 db1_copy = self.copy_database(self.db1)
2569- self.db1.create_doc(tests.simple_doc, doc_id='doc2')
2570- self.db1.create_doc(tests.simple_doc, doc_id='doc3')
2571+ self.db1.create_doc_from_json(tests.simple_doc, doc_id='doc2')
2572+ self.db1.create_doc_from_json(tests.simple_doc, doc_id='doc3')
2573 self.sync(self.db1, self.db2)
2574- db1_copy.create_doc(tests.simple_doc, doc_id='doc2')
2575- db1_copy.create_doc(tests.simple_doc, doc_id='doc3')
2576+ db1_copy.create_doc_from_json(tests.simple_doc, doc_id='doc2')
2577+ db1_copy.create_doc_from_json(tests.simple_doc, doc_id='doc3')
2578 self.assertRaises(
2579 errors.InvalidTransactionId, self.sync, db1_copy, self.db2)
2580
2581 def test_sync_detects_rollback_and_divergence_in_target(self):
2582- self.db1.create_doc(tests.simple_doc, doc_id="divergent")
2583+ self.db1.create_doc_from_json(tests.simple_doc, doc_id="divergent")
2584 self.sync(self.db1, self.db2)
2585 db2_copy = self.copy_database(self.db2)
2586- self.db2.create_doc(tests.simple_doc, doc_id='doc2')
2587- self.db2.create_doc(tests.simple_doc, doc_id='doc3')
2588+ self.db2.create_doc_from_json(tests.simple_doc, doc_id='doc2')
2589+ self.db2.create_doc_from_json(tests.simple_doc, doc_id='doc3')
2590 self.sync(self.db1, self.db2)
2591- db2_copy.create_doc(tests.simple_doc, doc_id='doc2')
2592- db2_copy.create_doc(tests.simple_doc, doc_id='doc3')
2593+ db2_copy.create_doc_from_json(tests.simple_doc, doc_id='doc2')
2594+ db2_copy.create_doc_from_json(tests.simple_doc, doc_id='doc3')
2595 self.assertRaises(
2596 errors.InvalidTransactionId, self.sync, self.db1, db2_copy)
2597
2598@@ -1044,8 +1044,8 @@
2599 self.db2 = self.request_state._create_database('test2.db')
2600
2601 def test_db_sync(self):
2602- doc1 = self.db.create_doc(tests.simple_doc)
2603- doc2 = self.db2.create_doc(tests.nested_doc)
2604+ doc1 = self.db.create_doc_from_json(tests.simple_doc)
2605+ doc2 = self.db2.create_doc_from_json(tests.nested_doc)
2606 db2_url = self.getURL('test2.db')
2607 self.db.sync(db2_url)
2608 self.assertGetDoc(self.db2, doc1.doc_id, doc1.rev, tests.simple_doc,
2609@@ -1066,10 +1066,10 @@
2610 self.db2 = self.request_state._create_database('test2')
2611
2612 def test_sync_tracks_generations_incrementally(self):
2613- doc11 = self.db1.create_doc('{"a": 1}')
2614- doc12 = self.db1.create_doc('{"a": 2}')
2615- doc21 = self.db2.create_doc('{"b": 1}')
2616- doc22 = self.db2.create_doc('{"b": 2}')
2617+ doc11 = self.db1.create_doc_from_json('{"a": 1}')
2618+ doc12 = self.db1.create_doc_from_json('{"a": 2}')
2619+ doc21 = self.db2.create_doc_from_json('{"b": 1}')
2620+ doc22 = self.db2.create_doc_from_json('{"b": 2}')
2621 #sanity
2622 self.assertEqual(2, len(self.db1._get_transaction_log()))
2623 self.assertEqual(2, len(self.db2._get_transaction_log()))
2624
2625=== modified file 'u1todo/test_u1todo.py'
2626--- u1todo/test_u1todo.py 2012-05-30 21:46:48 +0000
2627+++ u1todo/test_u1todo.py 2012-07-19 20:11:24 +0000
2628@@ -183,7 +183,7 @@
2629 def setUp(self):
2630 super(TaskTestCase, self).setUp()
2631 self.db = inmemory.InMemoryDatabase("u1todo")
2632- self.document = self.db.create_doc(EMPTY_TASK)
2633+ self.document = self.db.create_doc_from_json(EMPTY_TASK)
2634
2635 def test_task(self):
2636 """Initializing a task."""
2637
2638=== modified file 'u1todo/u1todo.py'
2639--- u1todo/u1todo.py 2012-07-03 17:54:40 +0000
2640+++ u1todo/u1todo.py 2012-07-19 20:11:24 +0000
2641@@ -144,7 +144,7 @@
2642 # Store the document in the database. Since we did not set a document
2643 # id, the database will store it as a new document, and generate
2644 # a valid id.
2645- document = self.db.create_doc(content=content)
2646+ document = self.db.create_doc_from_json(content)
2647 # Wrap the document in a Task object.
2648 return Task(document)
2649

Subscribers

People subscribed via source and target branches