summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-01-10 15:58:00 -0200
committerdrebs <drebs@leap.se>2013-01-10 16:21:05 -0200
commit7194324acca0f0ba2cb05718ad524ae313b2ba35 (patch)
tree3fb7e90cd5613e9cef7e4ef1c67f529d6a56e0d0 /src/leap
parentc317af1da8060f66576c817ea7073e9c73f43916 (diff)
LeapDocument and LeapSyncTarget pass u1db tests.
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/soledad/tests/test_leap_backend.py141
1 files changed, 140 insertions, 1 deletions
diff --git a/src/leap/soledad/tests/test_leap_backend.py b/src/leap/soledad/tests/test_leap_backend.py
index 5f58c832..72106aef 100644
--- a/src/leap/soledad/tests/test_leap_backend.py
+++ b/src/leap/soledad/tests/test_leap_backend.py
@@ -21,6 +21,15 @@ from leap.soledad.tests.u1db_tests.test_http_database import (
from leap.soledad.tests.u1db_tests.test_http_client import (
TestHTTPClientBase,
)
+from leap.soledad.tests.u1db_tests.test_document import (
+ TestDocument,
+ TestPyDocument,
+)
+from leap.soledad.tests.u1db_tests.test_remote_sync_target import (
+ TestHTTPSyncTargetBasics,
+ TestParsingSyncStream,
+)
+
#-----------------------------------------------------------------------------
@@ -78,7 +87,7 @@ class LeapTests(AllDatabaseTests):
#-----------------------------------------------------------------------------
-# The following tests come from `u1db.tests.test_http_database`.
+# The following tests come from `u1db.tests.test_leap_backend`.
#-----------------------------------------------------------------------------
class TestLeapDatabaseSimpleOperations(TestHTTPDatabaseSimpleOperations):
@@ -171,4 +180,134 @@ class TestLeapClientBase(TestHTTPClientBase):
pass
+#-----------------------------------------------------------------------------
+# The following tests come from `u1db.tests.test_document`.
+#-----------------------------------------------------------------------------
+
+def make_document_for_test(test, doc_id, rev, content, has_conflicts=False):
+ return leap_backend.LeapDocument(
+ doc_id, rev, content, has_conflicts=has_conflicts)
+
+
+class TestLeapDocument(TestDocument):
+
+ scenarios = ([(
+ 'leap', {'make_document_for_test': make_document_for_test})])
+
+
+class TestLeapPyDocument(TestPyDocument):
+
+ scenarios = ([(
+ 'leap', {'make_document_for_test': make_document_for_test})])
+
+
+#-----------------------------------------------------------------------------
+# The following tests come from `u1db.tests.test_sync_target`.
+#-----------------------------------------------------------------------------
+
+class TestLeapSyncTargetBasics(TestHTTPSyncTargetBasics):
+
+ def test_parse_url(self):
+ remote_target = leap_backend.LeapSyncTarget('http://127.0.0.1:12345/')
+ self.assertEqual('http', remote_target._url.scheme)
+ self.assertEqual('127.0.0.1', remote_target._url.hostname)
+ self.assertEqual(12345, remote_target._url.port)
+ self.assertEqual('/', remote_target._url.path)
+
+class TestLeapParsingSyncStream(TestParsingSyncStream):
+
+ def test_wrong_start(self):
+ tgt = leap_backend.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "{}\r\n]", None)
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "\r\n{}\r\n]", None)
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "", None)
+
+ def test_wrong_end(self):
+ tgt = leap_backend.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "[\r\n{}", None)
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "[\r\n", None)
+
+ def test_missing_comma(self):
+ tgt = leap_backend.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream,
+ '[\r\n{}\r\n{"id": "i", "rev": "r", '
+ '"content": "c", "gen": 3}\r\n]', None)
+
+ def test_no_entries(self):
+ tgt = leap_backend.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "[\r\n]", None)
+
+ def test_extra_comma(self):
+ tgt = leap_backend.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "[\r\n{},\r\n]", None)
+
+ self.assertRaises(leap_backend.NoSoledadInstance,
+ tgt._parse_sync_stream,
+ '[\r\n{},\r\n{"id": "i", "rev": "r", '
+ '"content": "{}", "gen": 3, "trans_id": "T-sid"}'
+ ',\r\n]',
+ lambda doc, gen, trans_id: None)
+
+ def test_error_in_stream(self):
+ tgt = leap_backend.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.Unavailable,
+ tgt._parse_sync_stream,
+ '[\r\n{"new_generation": 0},'
+ '\r\n{"error": "unavailable"}\r\n', None)
+
+ self.assertRaises(errors.Unavailable,
+ tgt._parse_sync_stream,
+ '[\r\n{"error": "unavailable"}\r\n', None)
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream,
+ '[\r\n{"error": "?"}\r\n', None)
+
+
+def leap_sync_target(test, path):
+ return leap_backend.LeapSyncTarget(test.getURL(path))
+
+
+def make_oauth_http_app(state):
+ app = http_app.HTTPApp(state)
+ application = oauth_middleware.OAuthMiddleware(app, None, prefix='/~/')
+ application.get_oauth_data_store = lambda: tests.testingOAuthStore
+ return application
+
+
+def oauth_leap_sync_target(test, path):
+ st = leap_sync_target(test, '~/' + path)
+ st.set_oauth_credentials(tests.consumer1.key, tests.consumer1.secret,
+ tests.token1.key, tests.token1.secret)
+ return st
+
+
+class TestRemoteSyncTargets(tests.TestCaseWithServer):
+
+ scenarios = [
+ ('http', {'make_app_with_state': make_http_app,
+ 'make_document_for_test': tests.make_document_for_test,
+ 'sync_target': leap_sync_target}),
+ ('oauth_http', {'make_app_with_state': make_oauth_http_app,
+ 'make_document_for_test': tests.make_document_for_test,
+ 'sync_target': oauth_leap_sync_target}),
+ ]
+
load_tests = tests.load_with_scenarios