diff options
author | Ruben Pollan <meskio@sindominio.net> | 2015-09-11 11:45:17 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2015-09-15 14:13:24 +0200 |
commit | 8384b006f575ac0b769f9f6e9ce6b2c623ec9fa1 (patch) | |
tree | 6e2c2366f3b5a87fba270e6f75d48bfc4da3677c /src/leap/mx/couchdbhelper.py | |
parent | 5f2f8a65aba2672ae6661052af2f735ba17ad7a5 (diff) |
[test] add test infrastructure
Some refactor on the couchdb usage was needed to be able to mock
couchdb.
- Resolves: #7435
Diffstat (limited to 'src/leap/mx/couchdbhelper.py')
-rw-r--r-- | src/leap/mx/couchdbhelper.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/leap/mx/couchdbhelper.py b/src/leap/mx/couchdbhelper.py index 1752b4e..b26a0d8 100644 --- a/src/leap/mx/couchdbhelper.py +++ b/src/leap/mx/couchdbhelper.py @@ -23,7 +23,9 @@ maps, user UUIDs, and GPG keyIDs. from paisley import client +from twisted.internet import defer from twisted.python import log +from leap.soledad.common.couch import CouchDatabase class ConnectedCouchDB(client.CouchDB): @@ -50,6 +52,10 @@ class ConnectedCouchDB(client.CouchDB): :param str password: (optional) The password for authorization. :type password: str """ + self.mail_couch_url = "http://%s:%s@%s:%s" % (username, + password, + host, + port) client.CouchDB.__init__(self, host, port=port, @@ -131,3 +137,31 @@ class ConnectedCouchDB(client.CouchDB): d.addCallbacks(_get_pubkey_cbk, log.err) return d + + def put_doc(self, uuid, doc): + """ + Update a document. + + If the document currently has conflicts, put will fail. + If the database specifies a maximum document size and the document + exceeds it, put will fail and raise a DocumentTooBig exception. + + :param uuid: The uuid of a user + :type uuid: str + :param doc: A Document with new content. + :type doc: leap.soledad.common.couch.CouchDocument + + :return: A deferred which fires with the new revision identifier for + the document if the Document object has being updated, or + which fails with CouchDBError if there was any error. + """ + # TODO: that should be implemented with paisley + try: + db = CouchDatabase(self._mail_couch_url, "user-%s" % (uuid,)) + return defer.succeed(db.put_doc(doc)) + except Exception as e: + return defer.fail(CouchDBError(e.message)) + + +class CouchDBError(Exception): + pass |