def test_raise_with_proper_code_and_args(self): """ Ensure that the requested exception is raised. """ with self.assertRaises(CloudantClientException) as cm: raise CloudantClientException(404, 'foo') self.assertEqual(cm.exception.status_code, 404)
def test_raise_without_code(self): """ Ensure that a default exception/code is used if none is provided. """ with self.assertRaises(CloudantClientException) as cm: raise CloudantClientException() self.assertEqual(cm.exception.status_code, 100)
def test_raise_using_invalid_code(self): """ Ensure that a default exception/code is used if invalid code is provided. """ with self.assertRaises(CloudantClientException) as cm: raise CloudantClientException('foo') self.assertEqual(cm.exception.status_code, 100)
def test_raise_without_args(self): """ Ensure that a default exception/code is used if the message requested by the code provided requires an argument list and none is provided. """ with self.assertRaises(CloudantClientException) as cm: raise CloudantClientException(404) self.assertEqual(cm.exception.status_code, 100)
def create_database(self, dbname, throw_on_exists=False, remote=None): if remote is None: remote = self.remote new_db = self._DATABASE_CLASS(self, dbname, remote=remote) try: new_db.create(throw_on_exists) except CloudantDatabaseException as ex: if ex.status_code == 412: raise CloudantClientException(412, dbname) super(RemoteCouchDB, self).__setitem__(dbname, new_db) return new_db