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