def test_replication_state(self): """ _test_replication_state_ Verify that we can get the replication state. """ dbsource = u"test_replication_state_source_{}".format( unicode(uuid.uuid4())) dbtarget = u"test_replication_state_target_{}".format( unicode(uuid.uuid4())) self.dbs = [dbsource, dbtarget] with cloudant(self.user, self.passwd) as c: dbs = c.create_database(dbsource) dbt = c.create_database(dbtarget) doc1 = dbs.create_document( {"_id": "doc1", "testing": "document 1"} ) doc2 = dbs.create_document( {"_id": "doc2", "testing": "document 1"} ) doc3 = dbs.create_document( {"_id": "doc3", "testing": "document 1"} ) replicator = ReplicatorDatabase(c) repl_id = u"test_replication_state_{}".format( unicode(uuid.uuid4())) self.replication_ids.append(repl_id) ret = replicator.create_replication( source_db=dbs, target_db=dbt, repl_id=repl_id, continuous=False, ) replication_state = "not_yet_set" while True: # Verify that replication_state returns either None # (if the field doesn't exist yet), or a valid # replication state. replication_state = replicator.replication_state(repl_id) if replication_state is not None: self.assertTrue( replication_state in [ 'completed', 'error', 'triggered' ] ) if replication_state in ('error', 'completed'): break LOG.debug("got replication state: {}".format( replication_state)) time.sleep(1)
def test_replication_state(self): """test replication state method""" mock_account = mock.Mock() repl = ReplicatorDatabase(mock_account) mock_doc = mock.Mock() mock_doc.fetch = mock.Mock() mock_doc.get = mock.Mock() mock_doc.get.return_value = "STATE" repl['replication_1'] = mock_doc self.assertEqual(repl.replication_state('replication_1'), 'STATE') with mock.patch('cloudant.replicator.ReplicatorDatabase.__getitem__') as mock_gi: mock_gi.side_effect = KeyError("womp") self.assertRaises( CloudantException, repl.replication_state, 'replication_2' )