~kevin-wright-1/u1db-qt/document-april-6-i

« back to all changes in this revision

Viewing changes to tests/test-upstream.py

  • Committer: Tarmac
  • Author(s): Christian Dywan
  • Date: 2013-03-28 12:50:56 UTC
  • mfrom: (56.1.4 u1db-qt)
  • Revision ID: tarmac-20130328125056-24eoheu4foxj67kc
Use consistent test database naming and disable getIndexKeys test.

Approved by Ubuntu Phone Apps Jenkins Bot, Christian Dywan.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# Copyright 2013 Canonical Ltd.
 
3
#
 
4
# This file is part of u1db.
 
5
#
 
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.
 
9
#
 
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.
 
14
#
 
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/>.
 
17
 
 
18
import os, sys, unittest
 
19
 
 
20
try:
 
21
    from testtools import run
 
22
    import testscenarios
 
23
except:
 
24
    print('Required modules: python-testtools python-testscenarios')
 
25
    sys.exit(1)
 
26
 
 
27
try:
 
28
    import u1dbqt
 
29
except Exception:
 
30
    msg = sys.exc_info()[1] # Python 2/3 compatibility
 
31
    print(msg)
 
32
    print('u1dbqt Python wrapper not built? Did you run "make"?')
 
33
    sys.exit(1)
 
34
 
 
35
try:
 
36
    import u1db # Database, SyncTarget, Document, errors
 
37
    import u1db.tests
 
38
    from u1db.tests import test_backends
 
39
except:
 
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')
 
42
    sys.exit(1)
 
43
 
 
44
# u1db-qt specific test cases
 
45
 
 
46
class TestQt(u1db.tests.DatabaseBaseTests):
 
47
    def setUp(self):
 
48
        super(TestQt, self).setUp()
 
49
 
 
50
    def test_sanity(self):
 
51
        self.assertTrue('Qt' in str(self))
 
52
 
 
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
 
55
 
 
56
class QtDatabase(u1dbqt.Database):
 
57
    def __init__(self, replica_uid):
 
58
        u1dbqt.Database.__init__(self, replica_uid)
 
59
 
 
60
    def create_doc_from_json(self, json, doc_id=None):
 
61
        # FIXME create in db
 
62
        doc = u1db.Document(doc_id=doc_id)
 
63
        doc.set_json(json)
 
64
        return doc
 
65
 
 
66
    def put_doc (self, doc):
 
67
        u1dbqt.Database.put_doc(self, contents=doc.get_json(), doc_id=doc.doc_id)
 
68
 
 
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)
 
72
 
 
73
    def get_docs (self):
 
74
        pass # TODO
 
75
 
 
76
    def get_all_docs (self):
 
77
        pass # TODO
 
78
 
 
79
    def close (self):
 
80
        pass # TODO
 
81
 
 
82
# TODO complete wrappers
 
83
 
 
84
def make_database(test, replica_uid):
 
85
    db = QtDatabase(replica_uid)
 
86
    def cleanup():
 
87
        pass # FIXME delete old databases
 
88
    test.addCleanup(cleanup)
 
89
    return db
 
90
 
 
91
# upstream Python test cases
 
92
# cf http://bazaar.launchpad.net/~pedronis/u1db/u1db-js/view/head:/tests/test_bridged.py
 
93
 
 
94
SCENARIOS = [("jsbridged", {
 
95
        "make_database_for_test": make_database,
 
96
        })]
 
97
class BridgedAllDatabaseTests(test_backends.AllDatabaseTests):
 
98
    scenarios = SCENARIOS
 
99
 
 
100
# TODO enable more cases
 
101
 
 
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)