Example #1
0
    def test_missing_comma(self):
        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)
Example #2
0
    def test_wrong_end(self):
        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)
Example #3
0
    def test_extra_comma(self):
        tgt = leap_backend.LeapSyncTarget("http://foo/foo")

        self.assertRaises(u1db.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)
Example #4
0
    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)
Example #5
0
def oauth_https_sync_target(test, host, path):
    _, port = test.server.server_address
    st = leap_backend.LeapSyncTarget('https://%s:%d/~/%s' % (host, port, path))
    st.set_oauth_credentials(tests.consumer1.key, tests.consumer1.secret,
                             tests.token1.key, tests.token1.secret)
    return st
Example #6
0
def leap_sync_target(test, path):
    return leap_backend.LeapSyncTarget(test.getURL(path))
Example #7
0
 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)