summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_couch.py83
-rw-r--r--tests/test_logs.py28
2 files changed, 91 insertions, 20 deletions
diff --git a/tests/test_couch.py b/tests/test_couch.py
index 6a2c7dab..3f6c45f6 100644
--- a/tests/test_couch.py
+++ b/tests/test_couch.py
@@ -1,4 +1,8 @@
-"""Test ObjectStore backend bits."""
+"""Test ObjectStore backend bits.
+
+For these tests to run, a couch server has to be running on (default) port
+5984.
+"""
import sys
import copy
@@ -6,8 +10,20 @@ import testtools
import testscenarios
from leap.soledad.backends import couch
from leap.soledad.tests import u1db_tests as tests
-from leap.soledad.tests.u1db_tests.test_backends import AllDatabaseTests
+from leap.soledad.tests.u1db_tests.test_backends import (
+ TestAlternativeDocument,
+ AllDatabaseTests,
+ LocalDatabaseTests,
+ LocalDatabaseValidateGenNTransIdTests,
+ LocalDatabaseValidateSourceGenTests,
+ LocalDatabaseWithConflictsTests,
+ DatabaseIndexTests,
+)
+
+#-----------------------------------------------------------------------------
+# The following tests come from `u1db.tests.test_common_backends`.
+#-----------------------------------------------------------------------------
class TestCouchBackendImpl(tests.TestCase):
@@ -19,6 +35,11 @@ class TestCouchBackendImpl(tests.TestCase):
int(doc_id1[len('D-'):], 16)
self.assertNotEqual(doc_id1, db._allocate_doc_id())
+
+#-----------------------------------------------------------------------------
+# The following tests come from `u1db.tests.test_backends`.
+#-----------------------------------------------------------------------------
+
def make_couch_database_for_test(test, replica_uid, path='test'):
return couch.CouchDatabase('http://localhost:5984', 'u1db_tests',
replica_uid=replica_uid)
@@ -34,28 +55,66 @@ def copy_couch_database_for_test(test, db):
new_db._ensure_u1db_data()
return new_db
-def make_couch_app(test):
- pass
-
-class CouchTests(AllDatabaseTests):
-
- scenarios = [
+COUCH_SCENARIOS = [
('couch', {'make_database_for_test': make_couch_database_for_test,
'copy_database_for_test': copy_couch_database_for_test,
'make_document_for_test': tests.make_document_for_test,}),
]
+
+class CouchTests(AllDatabaseTests):
+
+ scenarios = COUCH_SCENARIOS
+
def tearDown(self):
self.db.delete_database()
super(CouchTests, self).tearDown()
- #make_database_for_test = make_couch_database_for_test
- #copy_database_for_test = copy_couch_database_for_test
+class CouchDatabaseTests(LocalDatabaseTests):
+
+ scenarios = COUCH_SCENARIOS
+
+ def tearDown(self):
+ self.db.delete_database()
+ super(CouchDatabaseTests, self).tearDown()
+
-# def runTest(self):
-# pass
+#class CouchValidateGenNTransIdTests(LocalDatabaseValidateGenNTransIdTests):
+#
+# scenarios = COUCH_SCENARIOS
+#
+# def tearDown(self):
+# self.db.delete_database()
+# super(CouchTests, self).tearDown()
+#
+#
+#class CouchValidateSourceGenTests(LocalDatabaseValidateSourceGenTests):
+#
+# scenarios = COUCH_SCENARIOS
+#
+# def tearDown(self):
+# self.db.delete_database()
+# super(CouchTests, self).tearDown()
+#
+#
+#class CouchWithConflictsTests(LocalDatabaseWithConflictsTests):
+#
+# scenarios = COUCH_SCENARIOS
+#
+# def tearDown(self):
+# self.db.delete_database()
+# super(CouchTests, self).tearDown()
+#
+#
+#class CouchIndexTests(DatabaseIndexTests):
+#
+# scenarios = COUCH_SCENARIOS
+#
+# def tearDown(self):
+# self.db.delete_database()
+# super(CouchTests, self).tearDown()
#
load_tests = tests.load_with_scenarios
diff --git a/tests/test_logs.py b/tests/test_logs.py
index 072ac1a5..7fbb1cb7 100644
--- a/tests/test_logs.py
+++ b/tests/test_logs.py
@@ -1,5 +1,5 @@
import unittest2 as unittest
-from leap.soledad.util import TransactionLog, SyncLog
+from leap.soledad.util import TransactionLog, SyncLog, ConflictLog
class LogTestCase(unittest.TestCase):
@@ -49,25 +49,37 @@ class LogTestCase(unittest.TestCase):
def test_whats_changed(self):
data = [
- (2, "doc_3", "tran_3"),
- (3, "doc_2", "tran_2"),
- (1, "doc_1", "tran_1")
- ]
+ (1, "doc_1", "tran_1"),
+ (2, "doc_2", "tran_2"),
+ (3, "doc_3", "tran_3")
+ ]
log = TransactionLog()
log.log = data
self.assertEqual(
log.whats_changed(3),
- (3, "tran_2", []),
+ (3, "tran_3", []),
'error getting whats changed.')
self.assertEqual(
log.whats_changed(2),
- (3, "tran_2", [("doc_2",3,"tran_2")]),
+ (3, "tran_3", [("doc_3",3,"tran_3")]),
'error getting whats changed.')
self.assertEqual(
log.whats_changed(1),
- (3, "tran_2", [("doc_3",2,"tran_3"),("doc_2",3,"tran_2")]),
+ (3, "tran_3", [("doc_2",2,"tran_2"),("doc_3",3,"tran_3")]),
'error getting whats changed.')
+ def test_conflict_log(self):
+ data = [('1', 'my:1', 'irrelevant'),
+ ('2', 'my:1', 'irrelevant'),
+ ('3', 'my:1', 'irrelevant')]
+ log = ConflictLog()
+ log.log = data
+ log.delete_conflicts([('1','my:1'),('2','my:1')])
+ self.assertEqual(
+ log.log,
+ [('3', 'my:1', 'irrelevant')],
+ 'error deleting conflicts.')
+
if __name__ == '__main__':
unittest.main()