summaryrefslogtreecommitdiff
path: root/scripts/migration/0.8.2/tests/conftest.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2016-07-29 10:01:46 -0300
committerdrebs <drebs@leap.se>2016-08-01 21:09:04 -0300
commitbc28ea6e652418791dcf63fadcc81db9c50e2d45 (patch)
tree8ee54c15dc636c4ab347b5387ea3da268ebf7259 /scripts/migration/0.8.2/tests/conftest.py
parent72ee56e3863729b148cf8cc16e4004dc7b52acdd (diff)
[pkg] add couch schema migration script
Diffstat (limited to 'scripts/migration/0.8.2/tests/conftest.py')
-rw-r--r--scripts/migration/0.8.2/tests/conftest.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/migration/0.8.2/tests/conftest.py b/scripts/migration/0.8.2/tests/conftest.py
new file mode 100644
index 00000000..92d1e17e
--- /dev/null
+++ b/scripts/migration/0.8.2/tests/conftest.py
@@ -0,0 +1,46 @@
+# conftest.py
+
+"""
+Provide a couch database with content stored in old schema.
+"""
+
+import couchdb
+import pytest
+import uuid
+
+
+COUCH_URL = 'http://127.0.0.1:5984'
+
+transaction_map = """
+function(doc) {
+ if (doc.u1db_transactions)
+ doc.u1db_transactions.forEach(function(t) {
+ emit(t[0], // use timestamp as key so the results are ordered
+ t[1]); // value is the transaction_id
+ });
+}
+"""
+
+initial_docs = [
+ {'_id': 'u1db_config', 'replica_uid': 'an-uid'},
+ {'_id': 'u1db_sync_A', 'generation': 0, 'replica_uid': 'A',
+ 'transaction_id': ''},
+ {'_id': 'u1db_sync_B', 'generation': 2, 'replica_uid': 'B',
+ 'transaction_id': 'X'},
+ {'_id': 'doc1', 'u1db_transactions': [(1, 'trans-1'), (3, 'trans-3')]},
+ {'_id': 'doc2', 'u1db_transactions': [(2, 'trans-2'), (4, 'trans-4')]},
+ {'_id': '_design/docs'},
+ {'_id': '_design/syncs'},
+ {'_id': '_design/transactions', 'views': {'log': {'map': transaction_map}}}
+]
+
+
+@pytest.fixture(scope='function')
+def db(request):
+ server = couchdb.Server(COUCH_URL)
+ dbname = "user-" + uuid.uuid4().hex
+ db = server.create(dbname)
+ for doc in initial_docs:
+ db.save(doc)
+ request.addfinalizer(lambda: server.delete(dbname))
+ return db