diff options
author | Ruben Pollan <meskio@sindominio.net> | 2015-09-18 14:13:52 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2015-09-18 14:13:52 +0200 |
commit | c9d1677e335838a8631a04cf8971ea864a1e8e67 (patch) | |
tree | 5c411028d4a5624a2e61ce6f92f7768bd5c78f50 /common | |
parent | d38d0aa5836080cfaad90df430ab4a4d14822856 (diff) | |
parent | 5b0e854096f35655037f4da07031741087155a7d (diff) |
Merge branch 'pixelated:bug/ensure_ddocs_independency' into develop
Diffstat (limited to 'common')
-rw-r--r-- | common/src/leap/soledad/common/couch.py | 11 | ||||
-rw-r--r-- | common/src/leap/soledad/common/tests/test_couch.py | 18 |
2 files changed, 20 insertions, 9 deletions
diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py index 82b5aca8..1c762036 100644 --- a/common/src/leap/soledad/common/couch.py +++ b/common/src/leap/soledad/common/couch.py @@ -485,13 +485,10 @@ class CouchDatabase(CommonBackend): Ensure that the design documents used by the backend exist on the couch database. """ - # we check for existence of one of the files, and put all of them if - # that one does not exist - try: - self._database['_design/docs'] - return - except ResourceNotFound: - for ddoc_name in ['docs', 'syncs', 'transactions']: + for ddoc_name in ['docs', 'syncs', 'transactions']: + try: + self._database.info(ddoc_name) + except ResourceNotFound: ddoc = json.loads( binascii.a2b_base64( getattr(ddocs, ddoc_name))) diff --git a/common/src/leap/soledad/common/tests/test_couch.py b/common/src/leap/soledad/common/tests/test_couch.py index 845f1602..a08ffd16 100644 --- a/common/src/leap/soledad/common/tests/test_couch.py +++ b/common/src/leap/soledad/common/tests/test_couch.py @@ -1320,8 +1320,9 @@ class CouchDatabaseExceptionsTests(CouchDBTestCase): def setUp(self): CouchDBTestCase.setUp(self) - def create_db(self, ensure=True): - dbname = ('test-%s' % uuid4().hex) + def create_db(self, ensure=True, dbname=None): + if not dbname: + dbname = ('test-%s' % uuid4().hex) self.db = couch.CouchDatabase.open_database( urljoin('http://127.0.0.1:%d' % self.couch_port, dbname), create=True, @@ -1492,3 +1493,16 @@ class CouchDatabaseExceptionsTests(CouchDBTestCase): self.assertRaises( errors.MissingDesignDocDeletedError, self.db._do_set_replica_gen_and_trans_id, 1, 2, 3) + + def test_ensure_ddoc_independently(self): + """ + Test that a missing ddocs other than _design/docs will be ensured + even if _design/docs is there. + """ + self.create_db(ensure=True) + del self.db._database['_design/transactions'] + self.assertRaises( + errors.MissingDesignDocDeletedError, + self.db._get_transaction_log) + self.create_db(ensure=True, dbname=self.db._dbname) + self.db._get_transaction_log() |