summaryrefslogtreecommitdiff
path: root/common/src/leap/soledad/common/tests/test_server.py
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/leap/soledad/common/tests/test_server.py')
-rw-r--r--common/src/leap/soledad/common/tests/test_server.py70
1 files changed, 43 insertions, 27 deletions
diff --git a/common/src/leap/soledad/common/tests/test_server.py b/common/src/leap/soledad/common/tests/test_server.py
index f8d2a64f..1c5a7407 100644
--- a/common/src/leap/soledad/common/tests/test_server.py
+++ b/common/src/leap/soledad/common/tests/test_server.py
@@ -27,6 +27,7 @@ import mock
import time
import binascii
+from urlparse import urljoin
from leap.common.testing.basetest import BaseLeapTest
from leap.soledad.common.couch import (
@@ -56,7 +57,8 @@ from leap.soledad.server.auth import URLToAuthorization
def _couch_ensure_database(self, dbname):
db = CouchDatabase.open_database(
self._couch_url + '/' + dbname,
- create=True)
+ create=True,
+ ensure_ddocs=True)
return db, db._replica_uid
CouchServerState.ensure_database = _couch_ensure_database
@@ -352,11 +354,10 @@ class EncryptedSyncTestCase(
self.assertEqual([], doclist)
doc1 = sol1.create_doc(json.loads(simple_doc))
# ensure remote db exists before syncing
- db = CouchDatabase(
- self._couch_url,
- # the name of the user database is "user-<uuid>".
- 'user-user-uuid',
- )
+ db = CouchDatabase.open_database(
+ urljoin(self._couch_url, 'user-user-uuid'),
+ create=True,
+ ensure_ddocs=True)
# sync with server
sol1._server_url = self.getURL()
sol1.sync()
@@ -390,6 +391,9 @@ class EncryptedSyncTestCase(
# assert incoming doc is equal to the first sent doc
self.assertEqual(doc1, doc2)
db.delete_database()
+ db.close()
+ sol1.close()
+ sol2.close()
def test_encrypted_sym_sync_with_unicode_passphrase(self):
"""
@@ -408,11 +412,10 @@ class EncryptedSyncTestCase(
self.assertEqual([], doclist)
doc1 = sol1.create_doc(json.loads(simple_doc))
# ensure remote db exists before syncing
- db = CouchDatabase(
- self._couch_url,
- # the name of the user database is "user-<uuid>".
- 'user-user-uuid',
- )
+ db = CouchDatabase.open_database(
+ urljoin(self._couch_url, 'user-user-uuid'),
+ create=True,
+ ensure_ddocs=True)
# sync with server
sol1._server_url = self.getURL()
sol1.sync()
@@ -450,6 +453,9 @@ class EncryptedSyncTestCase(
# assert incoming doc is equal to the first sent doc
self.assertEqual(doc1, doc2)
db.delete_database()
+ db.close()
+ sol1.close()
+ sol2.close()
def test_sync_very_large_files(self):
"""
@@ -468,11 +474,10 @@ class EncryptedSyncTestCase(
content = binascii.hexlify(os.urandom(length/2)) # len() == length
doc1 = sol1.create_doc({'data': content})
# ensure remote db exists before syncing
- db = CouchDatabase(
- self._couch_url,
- # the name of the user database is "user-<uuid>".
- 'user-user-uuid',
- )
+ db = CouchDatabase.open_database(
+ urljoin(self._couch_url, 'user-user-uuid'),
+ create=True,
+ ensure_ddocs=True)
# sync with server
sol1._server_url = self.getURL()
sol1.sync()
@@ -493,6 +498,9 @@ class EncryptedSyncTestCase(
self.assertEqual(doc1, doc2)
# delete remote database
db.delete_database()
+ db.close()
+ sol1.close()
+ sol2.close()
def test_sync_many_small_files(self):
@@ -512,11 +520,10 @@ class EncryptedSyncTestCase(
for i in range(0, number_of_docs):
sol1.create_doc(json.loads(simple_doc))
# ensure remote db exists before syncing
- db = CouchDatabase(
- self._couch_url,
- # the name of the user database is "user-<uuid>".
- 'user-user-uuid',
- )
+ db = CouchDatabase.open_database(
+ urljoin(self._couch_url, 'user-user-uuid'),
+ create=True,
+ ensure_ddocs=True)
# sync with server
sol1._server_url = self.getURL()
sol1.sync()
@@ -537,6 +544,9 @@ class EncryptedSyncTestCase(
self.assertEqual(sol1.get_doc(doc.doc_id), doc)
# delete remote database
db.delete_database()
+ db.close()
+ sol1.close()
+ sol2.close()
class LockResourceTestCase(
CouchDBTestCase, TestCaseWithServer):
@@ -558,8 +568,14 @@ class LockResourceTestCase(
self.tempdir = tempfile.mkdtemp(prefix="leap_tests-")
self._couch_url = 'http://localhost:' + str(self.wrapper.port)
# create the databases
- CouchDatabase(self._couch_url, 'shared')
- CouchDatabase(self._couch_url, 'tokens')
+ CouchDatabase.open_database(
+ urljoin(self._couch_url, 'shared'),
+ create=True,
+ ensure_ddocs=True)
+ CouchDatabase.open_database(
+ urljoin(self._couch_url, 'tokens'),
+ create=True,
+ ensure_ddocs=True)
self._state = CouchServerState(
self._couch_url, 'shared', 'tokens')
@@ -567,10 +583,10 @@ class LockResourceTestCase(
CouchDBTestCase.tearDown(self)
TestCaseWithServer.tearDown(self)
# delete remote database
- db = CouchDatabase(
- self._couch_url,
- 'shared',
- )
+ db = CouchDatabase.open_database(
+ urljoin(self._couch_url, 'shared'),
+ create=True,
+ ensure_ddocs=True)
db.delete_database()
def test__try_obtain_filesystem_lock(self):