2
# Copyright 2013 Canonical Ltd.
4
# This file is part of u1db.
6
# u1db is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Lesser General Public License version 3
8
# as published by the Free Software Foundation.
10
# u1db is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public License
16
# along with u1db. If not, see <http://www.gnu.org/licenses/>.
18
import os, sys, unittest
21
from testtools import run
24
print('Required modules: python-testtools python-testscenarios')
30
msg = sys.exc_info()[1] # Python 2/3 compatibility
32
print('u1dbqt Python wrapper not built? Did you run "make"?')
36
import u1db # Database, SyncTarget, Document, errors
38
from u1db.tests import test_backends
40
print('python-u1db required, with tests support')
41
print('An easy way of doing that is getting lp:u1db and setting PYTHONPATH=/path/to/u1db')
44
# u1db-qt specific test cases
46
class TestQt(u1db.tests.DatabaseBaseTests):
48
super(TestQt, self).setUp()
50
def test_sanity(self):
51
self.assertTrue('Qt' in str(self))
53
# wrap Qt code in Python classes (via ui1dbqt Python module)
54
# cf. http://bazaar.launchpad.net/~pedronis/u1db/u1db-js/view/head:/tests/bridged.py
56
class QtDatabase(u1dbqt.Database):
57
def __init__(self, replica_uid):
58
u1dbqt.Database.__init__(self, replica_uid)
60
def create_doc_from_json(self, json, doc_id=None):
62
doc = u1db.Document(doc_id=doc_id)
66
def put_doc (self, doc):
67
u1dbqt.Database.put_doc(self, contents=doc.get_json(), doc_id=doc.doc_id)
69
def delete_doc (self, doc):
70
# Deleted means empty contents in the database
71
self.put_doc(contents=None, doc_id=doc.doc_id)
76
def get_all_docs (self):
82
# TODO complete wrappers
84
def make_database(test, replica_uid):
85
db = QtDatabase(replica_uid)
87
pass # FIXME delete old databases
88
test.addCleanup(cleanup)
91
# upstream Python test cases
92
# cf http://bazaar.launchpad.net/~pedronis/u1db/u1db-js/view/head:/tests/test_bridged.py
94
SCENARIOS = [("jsbridged", {
95
"make_database_for_test": make_database,
97
class BridgedAllDatabaseTests(test_backends.AllDatabaseTests):
100
# TODO enable more cases
102
load_tests = u1db.tests.load_with_scenarios
103
if __name__ == '__main__':
104
loader = unittest.TestLoader()
105
suite = load_tests (loader, loader.loadTestsFromName(__name__), '*')
106
unittest.TextTestRunner(verbosity=2).run(suite)