summaryrefslogtreecommitdiff
path: root/tests/test_leap_backend.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-01-03 17:42:34 -0200
committerdrebs <drebs@leap.se>2013-01-03 17:42:34 -0200
commitc8dd8908ee11d1ef057b1d439d3fe12ad50c5071 (patch)
treef77bb6c2df351e789ffaa9b1d090f2d8ad8ba8f1 /tests/test_leap_backend.py
parenta1c727b32464895f2dc912672ec51d1e5b5f392d (diff)
LeapSyncTarget passes HTTPSyncTarget tests.
Diffstat (limited to 'tests/test_leap_backend.py')
-rw-r--r--tests/test_leap_backend.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/test_leap_backend.py b/tests/test_leap_backend.py
index 9a8daf1a..1e46051c 100644
--- a/tests/test_leap_backend.py
+++ b/tests/test_leap_backend.py
@@ -19,6 +19,15 @@ from leap.soledad.tests.u1db_tests.test_document import (
TestDocument,
TestPyDocument,
)
+from leap.soledad.tests.u1db_tests.test_remote_sync_target import (
+ TestHTTPSyncTargetBasics,
+ TestParsingSyncStream,
+)
+
+
+#-----------------------------------------------------------------------------
+# LeapDatabase
+#-----------------------------------------------------------------------------
class TestLeapDatabaseSimpleOperations(TestHTTPDatabaseSimpleOperations):
@@ -118,6 +127,10 @@ class TestLeapClientBase(TestHTTPClientBase):
pass
+#-----------------------------------------------------------------------------
+# LeapDocument
+#-----------------------------------------------------------------------------
+
def make_document_for_test(test, doc_id, rev, content, has_conflicts=False):
return LeapDocument(doc_id, rev, content, has_conflicts=has_conflicts)
@@ -133,3 +146,83 @@ class TestLeapPyDocument(TestPyDocument):
scenarios = ([(
'py', {'make_document_for_test': make_document_for_test})])
+
+#-----------------------------------------------------------------------------
+# LeapSyncTarget
+#-----------------------------------------------------------------------------
+
+class TestLeapSyncTargetBasics(TestHTTPSyncTargetBasics):
+
+ def test_parse_url(self):
+ remote_target = http_database.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 = http_database.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 = http_database.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 = http_database.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 = http_database.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "[\r\n]", None)
+
+ def test_extra_comma(self):
+ tgt = http_database.LeapSyncTarget("http://foo/foo")
+
+ self.assertRaises(errors.BrokenSyncStream,
+ tgt._parse_sync_stream, "[\r\n{},\r\n]", None)
+
+ self.assertRaises(http_database.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 = http_database.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)
+