Ejemplo n.º 1
0
 def test_transaction_log_storage_after_put(self):
     db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port),
                              'u1db_tests')
     db.create_doc({'simple': 'doc'})
     content = self._fetch_u1db_data(db)
     self.assertEqual(self._listify(db._transaction_log),
                      self._listify(content['transaction_log']))
Ejemplo n.º 2
0
 def test_other_gens_storage_after_set(self):
     db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port),
                              'u1db_tests')
     doc = db.create_doc({'simple': 'doc'})
     db._set_replica_gen_and_trans_id('a', 'b', 'c')
     content = self._fetch_u1db_data(db)
     self.assertEqual(self._listify(db._other_generations),
                      self._listify(content['other_generations']))
Ejemplo n.º 3
0
 def test__allocate_doc_id(self):
     db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port),
                              'u1db_tests')
     doc_id1 = db._allocate_doc_id()
     self.assertTrue(doc_id1.startswith('D-'))
     self.assertEqual(34, len(doc_id1))
     int(doc_id1[len('D-'):], 16)
     self.assertNotEqual(doc_id1, db._allocate_doc_id())
Ejemplo n.º 4
0
 def test_conflict_log_storage_after_put_if_newer(self):
     db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port),
                              'u1db_tests')
     doc = db.create_doc({'simple': 'doc'})
     doc.set_json(nested_doc)
     doc.rev = db._replica_uid + ':2'
     db._force_doc_sync_conflict(doc)
     content = self._fetch_u1db_data(db)
     self.assertEqual(
         self._listify(db._conflicts),
         self._listify(json.loads(b64decode(content['conflicts']))))
Ejemplo n.º 5
0
def copy_couch_database_for_test(test, db):
    port = str(test.wrapper.port)
    new_db = couch.CouchDatabase('http://localhost:' + port,
                                 db._replica_uid + '_copy',
                                 replica_uid=db._replica_uid or 'test')
    gen, docs = db.get_all_docs(include_deleted=True)
    for doc in docs:
        new_db._put_doc(doc)
    new_db._transaction_log = copy.deepcopy(db._transaction_log)
    new_db._conflicts = copy.deepcopy(db._conflicts)
    new_db._other_generations = copy.deepcopy(db._other_generations)
    new_db._indexes = copy.deepcopy(db._indexes)
    new_db._store_u1db_data()
    return new_db
Ejemplo n.º 6
0
 def test_index_storage_after_create(self):
     db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port),
                              'u1db_tests')
     doc = db.create_doc({'name': 'john'})
     db.create_index('myindex', 'name')
     content = self._fetch_u1db_data(db)
     myind = db._indexes['myindex']
     index = {
         'myindex': {
             'definition': myind._definition,
             'name': myind._name,
             'values': myind._values,
         }
     }
     self.assertEqual(
         self._listify(index),
         self._listify(json.loads(b64decode(content['indexes']))))
Ejemplo n.º 7
0
 def test_replica_uid_storage_after_db_creation(self):
     db = couch.CouchDatabase('http://localhost:' + str(self.wrapper.port),
                              'u1db_tests')
     content = self._fetch_u1db_data(db)
     self.assertEqual(db._replica_uid, content['replica_uid'])
Ejemplo n.º 8
0
def make_couch_database_for_test(test, replica_uid):
    port = str(test.wrapper.port)
    return couch.CouchDatabase('http://localhost:' + port,
                               replica_uid,
                               replica_uid=replica_uid or 'test')