def test_unsubscribe_channel_for_value_errors(self): with self.assertRaises(ValueError) as wrong_param_channel: channel.unsubscribe_channel(channel_name='some-random-channel-name', user_id=self.user_id) with self.assertRaises(ValueError) as wrong_param_user: channel.unsubscribe_channel(channel_name=self.channel_name, user_id='some-random-user-id') self.assertEqual('INVALID-CHANNEL-NAME', wrong_param_channel.exception.message) self.assertEqual('INVALID-CHANNEL-MAPPING', wrong_param_user.exception.message)
def post(self): unsubscribe_channel_request_format = reqparse.RequestParser() unsubscribe_channel_request_format.add_argument('channel_name', type=non_empty_str, required=True, help="CHANNEL-REQ-NAME") params = unsubscribe_channel_request_format.parse_args() params.update(dict(user_id=current_identity.id)) log.info('Channel unsubscibe params: {}'.format(params)) try: session.rollback() response = unsubscribe_channel(**params) session.commit() return channel_unsubscribe_transform_response(response) except ValueError as val_err: log.error(repr(val_err)) session.rollback() abort(400, message=val_err.message) except KeyError as key_err: log.error(repr(key_err)) session.rollback() abort(400, message="UNSUB-INVALID-PARAM") except IOError as io_err: log.exception(io_err) session.rollback() abort(500, message="API-ERR-IO") except SQLAlchemyError as sa_err: log.exception(sa_err) session.rollback() abort(500, message="API-ERR-DB") except Exception as excp: log.error(repr(excp)) session.rollback() abort(400, message=excp.message) finally: session.close()
def test_unsubscribe_channel_for_key_errors(self): with self.assertRaises(KeyError) as err_empty_param: channel.unsubscribe_channel() with self.assertRaises(KeyError) as wrong_param: channel.unsubscribe_channel(channel_id=self.channel_id) with self.assertRaises(KeyError) as missing_param: channel.unsubscribe_channel(channel_name=self.channel_name) with self.assertRaises(KeyError) as missing_user_param: channel.unsubscribe_channel(channel_name=self.channel_name, user_name=self.username) self.assertEqual('REQ-CHANNEL-NAME', err_empty_param.exception.message) self.assertEqual('REQ-CHANNEL-NAME', wrong_param.exception.message) self.assertEqual('REQ-USER-ID', missing_param.exception.message) self.assertEqual('REQ-USER-ID', missing_user_param.exception.message)