From ecf568431319b4e81bc077141048d0b7f1e0964d Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 13 Feb 2013 12:45:53 -0200 Subject: Refactor and fix tests. --- tests/__init__.py | 10 +++++++++- tests/test_couch.py | 14 +++++++++++++- tests/test_encrypted.py | 6 ++++++ tests/test_sqlcipher.py | 15 ++++++++++++--- 4 files changed, 40 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/__init__.py b/tests/__init__.py index 6135e648..1a9962a7 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,7 @@ +""" +Tests to make sure Soledad provides U1DB functionality and more. +""" + import u1db from leap.soledad import Soledad from leap.soledad.backends.leap_backend import LeapDocument @@ -10,6 +14,9 @@ from leap.testing.basetest import BaseLeapTest #----------------------------------------------------------------------------- class BaseSoledadTest(BaseLeapTest): + """ + Instantiates GPG and Soledad for usage in tests. + """ def setUp(self): # config info @@ -27,7 +34,8 @@ class BaseSoledadTest(BaseLeapTest): initialize=False) self._soledad._gpg.import_keys(PUBLIC_KEY) self._soledad._gpg.import_keys(PRIVATE_KEY) - self._soledad._initialize() + self._soledad._init_crypto() + self._soledad._init_db() def tearDown(self): self._db1.close() diff --git a/tests/test_couch.py b/tests/test_couch.py index b07d1a98..c02d485b 100644 --- a/tests/test_couch.py +++ b/tests/test_couch.py @@ -38,6 +38,9 @@ class CouchDBWrapper(object): """ def start(self): + """ + Start a CouchDB instance for a test. + """ self.tempdir = tempfile.mkdtemp(suffix='.couch.test') path = os.path.join(os.path.dirname(__file__), @@ -89,6 +92,9 @@ stderr: self.port = int(m.group('port')) def stop(self): + """ + Terminate the CouchDB instance. + """ self.process.terminate() self.process.communicate() os.system("rm -rf %s" % self.tempdir) @@ -100,12 +106,18 @@ class CouchDBTestCase(unittest.TestCase): """ def setUp(self): + """ + Make sure we have a CouchDB instance for a test. + """ self.wrapper = CouchDBWrapper() self.wrapper.start() #self.db = self.wrapper.db super(CouchDBTestCase, self).setUp() def tearDown(self): + """ + Stop CouchDB instance for test. + """ self.wrapper.stop() super(CouchDBTestCase, self).tearDown() @@ -148,7 +160,7 @@ def copy_couch_database_for_test(test, db): new_db._conflicts = copy.deepcopy(db._conflicts) new_db._other_generations = copy.deepcopy(db._other_generations) new_db._indexes = copy.deepcopy(db._indexes) - new_db._set_u1db_data() + new_db._store_u1db_data() return new_db diff --git a/tests/test_encrypted.py b/tests/test_encrypted.py index 9fc81bc3..18894331 100644 --- a/tests/test_encrypted.py +++ b/tests/test_encrypted.py @@ -3,8 +3,14 @@ from leap.soledad.tests import BaseSoledadTest class EncryptedSyncTestCase(BaseSoledadTest): + """ + Tests that guarantee that data will always be encrypted when syncing. + """ def test_get_set_encrypted(self): + """ + Test if document encryption is working. + """ doc1 = LeapDocument(soledad=self._soledad) doc1.content = {'key': 'val'} doc2 = LeapDocument(doc_id=doc1.doc_id, diff --git a/tests/test_sqlcipher.py b/tests/test_sqlcipher.py index 4c0451b3..7b8f6298 100644 --- a/tests/test_sqlcipher.py +++ b/tests/test_sqlcipher.py @@ -450,20 +450,26 @@ class SQLCipherSyncTargetTests(test_sync.DatabaseSyncTargetTests): #----------------------------------------------------------------------------- class SQLCipherEncryptionTest(BaseLeapTest): + """ + Tests to guarantee SQLCipher is indeed encrypting data when storing. + """ - def delete_dbfiles(self): + def _delete_dbfiles(self): for dbfile in [self.DB_FILE]: if os.path.exists(dbfile): os.unlink(dbfile) def setUp(self): self.DB_FILE = self.tempdir + '/test.db' - self.delete_dbfiles() + self._delete_dbfiles() def tearDown(self): - self.delete_dbfiles() + self._delete_dbfiles() def test_try_to_open_encrypted_db_with_sqlite_backend(self): + """ + SQLite backend should not succeed to open SQLCipher databases. + """ db = SQLCipherDatabase(self.DB_FILE, PASSWORD) doc = db.create_doc_from_json(tests.simple_doc) db.close() @@ -483,6 +489,9 @@ class SQLCipherEncryptionTest(BaseLeapTest): 'decrypted content mismatch') def test_try_to_open_raw_db_with_sqlcipher_backend(self): + """ + SQLCipher backend should not succeed to open unencrypted databases. + """ db = SQLitePartialExpandDatabase(self.DB_FILE, document_factory=LeapDocument) db.create_doc_from_json(tests.simple_doc) -- cgit v1.2.3