def test_close_account_http_error(self, mock_post):
        mock_post.side_effect = HTTPError(self.error_msg)

        with self.assertRaises(ApplicationError) as context:
            verification_api = VerificationAPI()
            verification_api.close_account(self.item_id, self.staff_id,
                                           self.close_requester,
                                           self.close_reason)

        self.assertEqual(
            context.exception.message,
            'Received the following response from verification_api: {}'.format(
                self.error_msg))
        self.assertEqual(context.exception.code, 'E401')
        self.assertEqual(context.exception.http_code, 500)
    def test_close_account_timeout_error(self, mock_post):
        mock_post.side_effect = Timeout(self.error_msg)

        with self.assertRaises(ApplicationError) as context:
            verification_api = VerificationAPI()
            verification_api.close_account(self.item_id, self.staff_id,
                                           self.close_requester,
                                           self.close_reason)

        self.assertEqual(
            context.exception.message,
            'Connection to verification_api timed out: {}'.format(
                self.error_msg))
        self.assertEqual(context.exception.code, 'E403')
        self.assertEqual(context.exception.http_code, 500)
Esempio n. 3
0
def close_account():
    try:
        session['search_params'] = None
        staff_id = _get_user_name()
        item_id = request.form['item_id']
        requester = request.form['close_requester']
        reason = request.form['close_reason']
        current_app.logger.info('User {} closing account {}...'.format(
            staff_id, item_id))

        verification_api = VerificationAPI()
        verification_api.close_account(item_id, staff_id, requester, reason)
    except ApplicationError:
        raise ApplicationError(
            'Something went wrong when closing the account. '
            'Please raise an incident quoting the following id: {}'.format(
                g.trace_id))
    else:
        current_app.logger.info('Account {} was closed'.format(item_id))
        if requester == 'customer':
            flash('Account was closed and email was sent to account holder')
        else:
            flash('Account was closed')
        return redirect(url_for('verification.get_worklist'))
    def test_close_account(self, mock_post):
        mock_post.return_value.json.return_value = {
            "staff_id": self.staff_id,
            "requester": self.close_requester,
            "case_id": self.item_id,
            "status_updated": True,
            "close_detail": self.close_reason
        }
        mock_post.return_value.status_code = 201

        verification_api = VerificationAPI()
        response = verification_api.close_account(self.item_id, self.staff_id,
                                                  self.close_requester,
                                                  self.close_reason)

        self.assertEqual(
            response, {
                "staff_id": self.staff_id,
                "requester": self.close_requester,
                "case_id": self.item_id,
                "status_updated": True,
                "close_detail": self.close_reason
            })