File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,16 @@ def delete(self, name):
209
209
"""
210
210
del self [name ]
211
211
212
+ def replicate (self , source , target ):
213
+ """Replicate changes from the source database to the target database.
214
+
215
+ :param source: URL of the source database
216
+ :param target: URL of the target database
217
+ """
218
+ data = {'source' : source , 'target' : target }
219
+ resp , data = self .resource .post ('/_replicate' , data )
220
+ return data
221
+
212
222
213
223
class Database (object ):
214
224
"""Representation of a database on a CouchDB server.
Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ def tearDown(self):
25
25
self .server .delete ('python-tests' )
26
26
except client .ResourceNotFound :
27
27
pass
28
+ try :
29
+ self .server .delete ('python-tests-a' )
30
+ except client .ResourceNotFound :
31
+ pass
28
32
29
33
def test_server_vars (self ):
30
34
version = self .server .version
@@ -49,6 +53,20 @@ def test_delete_db_missing(self):
49
53
self .assertRaises (client .ResourceNotFound , self .server .delete ,
50
54
'python-tests' )
51
55
56
+ def test_replicate (self ):
57
+ a = self .server .create ('python-tests' )
58
+ id = a .create ({'test' : 'a' })
59
+ b = self .server .create ('python-tests-a' )
60
+ result = self .server .replicate ('python-tests' , 'python-tests-a' )
61
+ self .assertEquals (result ['ok' ], True )
62
+ self .assertEquals (b [id ]['test' ], 'a' )
63
+
64
+ doc = b [id ]
65
+ doc ['test' ] = 'b'
66
+ b .update ([doc ])
67
+ self .server .replicate (client .DEFAULT_BASE_URI + 'python-tests-a' ,
68
+ 'python-tests' )
69
+ self .assertEquals (b [id ]['test' ], 'b' )
52
70
53
71
class DatabaseTestCase (unittest .TestCase ):
54
72
You can’t perform that action at this time.
0 commit comments