summaryrefslogtreecommitdiff
path: root/src/leap/soledad/tests/test_leap_backend.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-04-30 15:37:37 -0300
committerdrebs <drebs@leap.se>2013-04-30 15:37:37 -0300
commit1b9009c0b67e6209abbb7047b1edea7961bd3256 (patch)
tree5059da0cdee2bb5ad7177cdc3b703bfdd02774df /src/leap/soledad/tests/test_leap_backend.py
parentb567343c7b4daa54a05ed31592078fc69966f421 (diff)
Update tests with monkey patching to always use our SyncTarget.
Diffstat (limited to 'src/leap/soledad/tests/test_leap_backend.py')
-rw-r--r--src/leap/soledad/tests/test_leap_backend.py103
1 files changed, 34 insertions, 69 deletions
diff --git a/src/leap/soledad/tests/test_leap_backend.py b/src/leap/soledad/tests/test_leap_backend.py
index 7509af0e..4c76bbb9 100644
--- a/src/leap/soledad/tests/test_leap_backend.py
+++ b/src/leap/soledad/tests/test_leap_backend.py
@@ -1,7 +1,23 @@
-"""Test ObjectStore backend bits.
+# -*- coding: utf-8 -*-
+# test_leap_backend.py
+# Copyright (C) 2013 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
-For these tests to run, a leap server has to be running on (default) port
-5984.
+
+"""
+Test Leap backend bits.
"""
import u1db
@@ -12,9 +28,11 @@ except ImportError:
from leap.soledad.backends import leap_backend
+from leap.soledad.server import SoledadApp
+
+
from leap.soledad.tests import u1db_tests as tests
from leap.soledad.tests.u1db_tests.test_remote_sync_target import (
- make_http_app,
make_oauth_http_app,
)
from leap.soledad.tests import BaseSoledadTest
@@ -36,12 +54,16 @@ def make_leap_document_for_test(test, doc_id, rev, content,
doc_id, rev, content, has_conflicts=has_conflicts)
+def make_soledad_app(state):
+ return SoledadApp(state)
+
+
LEAP_SCENARIOS = [
('http', {
'make_database_for_test': test_backends.make_http_database_for_test,
'copy_database_for_test': test_backends.copy_http_database_for_test,
'make_document_for_test': make_leap_document_for_test,
- 'make_app_with_state': make_http_app}),
+ 'make_app_with_state': make_soledad_app}),
]
@@ -55,6 +77,9 @@ class LeapTests(test_backends.AllDatabaseTests, BaseSoledadTest):
#-----------------------------------------------------------------------------
class TestLeapClientBase(test_http_client.TestHTTPClientBase):
+ """
+ This class should be used to test Token auth.
+ """
pass
@@ -89,6 +114,9 @@ class TestLeapSyncTargetBasics(
self.assertEqual('/', remote_target._url.path)
+# Monkey patch test class so it uses our sync target.
+test_remote_sync_target.http_target.HTTPSyncTarget = leap_backend.LeapSyncTarget
+
class TestLeapParsingSyncStream(
test_remote_sync_target.TestParsingSyncStream,
BaseSoledadTest):
@@ -101,53 +129,6 @@ class TestLeapParsingSyncStream(
test_remote_sync_target.TestParsingSyncStream.tearDown(self)
BaseSoledadTest.tearDown(self)
- def test_wrong_start(self):
- """
- Test adapted to use a LeapSyncTarget.
- """
- tgt = leap_backend.LeapSyncTarget("http://foo/foo")
-
- self.assertRaises(u1db.errors.BrokenSyncStream,
- tgt._parse_sync_stream, "{}\r\n]", None)
-
- self.assertRaises(u1db.errors.BrokenSyncStream,
- tgt._parse_sync_stream, "\r\n{}\r\n]", None)
-
- self.assertRaises(u1db.errors.BrokenSyncStream,
- tgt._parse_sync_stream, "", None)
-
- def test_wrong_end(self):
- """
- Test adapted to use a LeapSyncTarget.
- """
- tgt = leap_backend.LeapSyncTarget("http://foo/foo")
-
- self.assertRaises(u1db.errors.BrokenSyncStream,
- tgt._parse_sync_stream, "[\r\n{}", None)
-
- self.assertRaises(u1db.errors.BrokenSyncStream,
- tgt._parse_sync_stream, "[\r\n", None)
-
- def test_missing_comma(self):
- """
- Test adapted to use a LeapSyncTarget.
- """
- tgt = leap_backend.LeapSyncTarget("http://foo/foo")
-
- self.assertRaises(u1db.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):
- """
- Test adapted to use a LeapSyncTarget.
- """
- tgt = leap_backend.LeapSyncTarget("http://foo/foo")
-
- self.assertRaises(u1db.errors.BrokenSyncStream,
- tgt._parse_sync_stream, "[\r\n]", None)
-
def test_extra_comma(self):
"""
Test adapted to use encrypted content.
@@ -168,22 +149,6 @@ class TestLeapParsingSyncStream(
',\r\n]' % json.dumps(enc_json),
lambda doc, gen, trans_id: None)
- def test_error_in_stream(self):
- tgt = leap_backend.LeapSyncTarget("http://foo/foo")
-
- self.assertRaises(u1db.errors.Unavailable,
- tgt._parse_sync_stream,
- '[\r\n{"new_generation": 0},'
- '\r\n{"error": "unavailable"}\r\n', None)
-
- self.assertRaises(u1db.errors.Unavailable,
- tgt._parse_sync_stream,
- '[\r\n{"error": "unavailable"}\r\n', None)
-
- self.assertRaises(u1db.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))
@@ -199,7 +164,7 @@ def oauth_leap_sync_target(test, path):
class TestRemoteSyncTargets(tests.TestCaseWithServer):
scenarios = [
- ('http', {'make_app_with_state': make_http_app,
+ ('http', {'make_app_with_state': make_soledad_app,
'make_document_for_test': make_leap_document_for_test,
'sync_target': leap_sync_target}),
('oauth_http', {'make_app_with_state': make_oauth_http_app,