@@ -298,9 +298,7 @@ def test_fetch_map_reduce(self):
298298 ddoc = DesignDocument (self .db , '_design/ddoc001' )
299299 view_map = 'function (doc) {\n emit(doc._id, 1);\n }'
300300 view_reduce = '_count'
301- db_copy = '{0}-copy' .format (self .db .database_name )
302301 ddoc .add_view ('view001' , view_map , view_reduce )
303- ddoc .add_view ('view002' , view_map , view_reduce , dbcopy = db_copy )
304302 ddoc .add_view ('view003' , view_map )
305303 ddoc .save ()
306304 ddoc_remote = DesignDocument (self .db , '_design/ddoc001' )
@@ -316,14 +314,55 @@ def test_fetch_map_reduce(self):
316314 'indexes' : {},
317315 'views' : {
318316 'view001' : {'map' : view_map , 'reduce' : view_reduce },
319- 'view002' : {'map' : view_map , 'reduce' : view_reduce , 'dbcopy' : db_copy },
320317 'view003' : {'map' : view_map }
321318 }
322319 })
323320 self .assertIsInstance (ddoc_remote ['views' ]['view001' ], View )
324- self .assertIsInstance (ddoc_remote ['views' ]['view002' ], View )
325321 self .assertIsInstance (ddoc_remote ['views' ]['view003' ], View )
326322
323+ @unittest .skipUnless (
324+ os .environ .get ('RUN_CLOUDANT_TESTS' ) is not None ,
325+ 'Skipping Cloudant fetch dbcopy test'
326+ )
327+ def test_fetch_dbcopy (self ):
328+ """
329+ Ensure that the document fetch from the database returns the
330+ DesignDocument format as expected when retrieving a view
331+ that has dbcopy.
332+ Note: this asserts the expected dbcopy location from Cloudant
333+ versions based on CouchDB >= 2.0
334+ """
335+ ddoc = DesignDocument (self .db , '_design/ddoc001' )
336+ view_map = 'function (doc) {\n emit(doc._id, 1);\n }'
337+ view_reduce = '_count'
338+ db_copy = '{0}-copy' .format (self .db .database_name )
339+ ddoc .add_view ('view002' , view_map , view_reduce , dbcopy = db_copy )
340+ ddoc .save ()
341+ ddoc_remote = DesignDocument (self .db , '_design/ddoc001' )
342+ self .assertNotEqual (ddoc_remote , ddoc )
343+ ddoc_remote .fetch ()
344+ # The local ddoc will not contain the server plugin options
345+ # so we need to manipulate the equalities by removing
346+ # the options from remote. The remote ddoc won't contain
347+ # the dbcopy entry in the view dict so that needs to be removed
348+ # before comparison also. Compare the removed values with
349+ # the expected content in each case.
350+ self .assertEqual (db_copy , ddoc ['views' ]['view002' ].pop ('dbcopy' ))
351+ self .assertEqual ({'epi' : {'dbcopy' : {'view002' : db_copy }}}, ddoc_remote .pop ('options' ))
352+ self .assertEqual (ddoc_remote , ddoc )
353+ self .assertTrue (ddoc_remote ['_rev' ].startswith ('1-' ))
354+ self .assertEqual (ddoc_remote , {
355+ '_id' : '_design/ddoc001' ,
356+ '_rev' : ddoc ['_rev' ],
357+ 'lists' : {},
358+ 'shows' : {},
359+ 'indexes' : {},
360+ 'views' : {
361+ 'view002' : {'map' : view_map , 'reduce' : view_reduce }
362+ }
363+ })
364+ self .assertIsInstance (ddoc_remote ['views' ]['view002' ], View )
365+
327366 def test_fetch_no_views (self ):
328367 """
329368 Ensure that the document fetched from the database returns the
@@ -515,7 +554,7 @@ def test_mr_view_save_fails_when_lang_is_query(self):
515554 view_map = 'function (doc) {\n emit(doc._id, 1);\n }'
516555 view_reduce = '_count'
517556 db_copy = '{0}-copy' .format (self .db .database_name )
518- ddoc .add_view ('view001' , view_map , view_reduce , dbcopy = db_copy )
557+ ddoc .add_view ('view001' , view_map , view_reduce )
519558 ddoc ['language' ] = 'query'
520559 with self .assertRaises (CloudantException ) as cm :
521560 ddoc .save ()
@@ -534,7 +573,7 @@ def test_mr_view_save_succeeds(self):
534573 view_map = 'function (doc) {\n emit(doc._id, 1);\n }'
535574 view_reduce = '_count'
536575 db_copy = '{0}-copy' .format (self .db .database_name )
537- ddoc .add_view ('view001' , view_map , view_reduce , dbcopy = db_copy )
576+ ddoc .add_view ('view001' , view_map , view_reduce )
538577 ddoc .save ()
539578 self .assertTrue (ddoc ['_rev' ].startswith ('1-' ))
540579
0 commit comments