~sil/u1db/cors-headers-and-web-admin

« back to all changes in this revision

Viewing changes to u1db/tests/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2012-01-23 14:52:01 UTC
  • mfrom: (160.1.25 c-layout)
  • Revision ID: john@arbash-meinel.com-20120123145201-l1xzif2qe1kt1wb5
Land the initial C implementation of u1db.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    server_state,
37
37
    )
38
38
 
 
39
try:
 
40
    from u1db.tests import c_backend_wrapper
 
41
except ImportError:
 
42
    c_backend_wrapper = None
39
43
 
40
44
# Setting this means that failing assertions will not include this module in
41
45
# their traceback. However testtools doesn't seem to set it, and we don't want
53
57
        self.addCleanup(shutil.rmtree, tempdir)
54
58
        return tempdir
55
59
 
 
60
    def make_document(self, doc_id, doc_rev, content, has_conflicts):
 
61
        return Document(doc_id, doc_rev, content, has_conflicts)
 
62
 
56
63
    def assertGetDoc(self, db, doc_id, doc_rev, content, has_conflicts):
57
64
        """Assert that the document in the database looks correct."""
58
 
        exp_doc = Document(doc_id, doc_rev, content,
59
 
                           has_conflicts=has_conflicts)
 
65
        exp_doc = self.make_document(doc_id, doc_rev, content,
 
66
                                     has_conflicts=has_conflicts)
60
67
        self.assertEqual(exp_doc, db.get_doc(doc_id))
61
68
 
62
69
    def assertGetDocConflicts(self, db, doc_id, conflicts):
101
108
    return db
102
109
 
103
110
 
 
111
def create_doc(doc_id, rev, content, has_conflicts=False):
 
112
    return Document(doc_id, rev, content, has_conflicts=has_conflicts)
 
113
 
 
114
 
 
115
def create_c_database(test, replica_uid):
 
116
    if c_backend_wrapper is None:
 
117
        test.skipTest('c_backend_wrapper is not available')
 
118
    db = c_backend_wrapper.CDatabase(':memory:')
 
119
    db._set_machine_id(replica_uid)
 
120
    return db
 
121
 
 
122
 
 
123
def create_c_document(doc_id, rev, content, has_conflicts=False):
 
124
    return c_backend_wrapper.make_document(doc_id, rev, content,
 
125
                                           has_conflicts=has_conflicts)
 
126
 
 
127
 
104
128
LOCAL_DATABASES_SCENARIOS = [
105
 
        ('mem', {'do_create_database': create_memory_database}),
106
 
        ('sql', {'do_create_database': create_sqlite_partial_expanded}),
 
129
        ('mem', {'do_create_database': create_memory_database,
 
130
                 'make_document': create_doc}),
 
131
        ('sql', {'do_create_database': create_sqlite_partial_expanded,
 
132
                 'make_document': create_doc}),
107
133
        ]
108
134
 
109
135
 
 
136
C_DATABASE_SCENARIOS = [
 
137
        ('c', {'do_create_database': create_c_database,
 
138
               'make_document': create_c_document})]
 
139
 
 
140
 
110
141
class DatabaseBaseTests(TestCase):
111
142
 
112
143
    scenarios = LOCAL_DATABASES_SCENARIOS