def test_account_info_return_notactive_account( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_inconnection_exit.return_value = None mock_msisdn = mock.ANY mock_current_user = mock.Mock() mock_inconnection_enter.return_value.display_account_info.return_value = { 'ACCLEFT': '12300', 'SUBSCRIBERTYPE': '9', 'ACNTSTAT': '1', 'CALLSERVSTOP': '2018-03-12' } prepaid_request = INRequestHandler( None, None, None ) # Act result = prepaid_request.account_info(mock_msisdn, mock_current_user) # Assert assert result == { 'mobileNumber': mock_msisdn, 'balance': 12300.0, 'subscriberProfile': '9', 'status': 'NOT ACTIVE' }
def info(current_user: User, transaction_id: str, msisdn: str): """Get MSISDN account profile. """ try: request_manager = INRequestHandler( host=app.config['IN_SERVER']['HOST'], port=app.config['IN_SERVER']['PORT'], buffer_size=app.config['IN_SERVER']['BUFFER_SIZE']) logger.info('API - SYSTEM - %s - PROFILE query for %s - %s', transaction_id, msisdn, current_user.username) account_info = request_manager.account_info(msisdn, current_user) account_info['transactionId'] = transaction_id return jsonify(account_info), 200 except INLoginError as login_error: logger.error('API - SYSTEM - %s - %s', transaction_id, login_error.msg) except INLogoutError as logout_error: logger.error('API - SYSTEM - %s - %s', transaction_id, logout_error.msg) except MsisdnMatchError as invalid_msisdn_error: logger.error('API - SYSTEM - %s - %s', transaction_id, invalid_msisdn_error.msg) except INQueryError as in_query_error: logger.error('API - SYSTEM - %s - %s', transaction_id, in_query_error.msg)
def balance(current_user: User, transaction_id: str, msisdn: str): """Get MSISDN balance """ try: request_manager = INRequestHandler( host=app.config['IN_SERVER']['HOST'], port=app.config['IN_SERVER']['PORT'], buffer_size=app.config['IN_SERVER']['BUFFER_SIZE']) logger.info('API - SYSTEM - %s - BALANCE query for %s - %s', transaction_id, msisdn, current_user.username) account_info = request_manager.account_info(msisdn, current_user) account_balance = { 'transactionId': transaction_id, 'mobileNumber': account_info['mobileNumber'], 'balance': account_info['balance'], } return jsonify(account_balance), 200 except INLoginError as login_error: logger.error('API - SYSTEM - %s - %s', transaction_id, login_error.msg) except INLogoutError as logout_error: logger.error('API - SYSTEM - %s - %s', transaction_id, logout_error.msg) except MsisdnMatchError as invalid_msisdn_error: logger.error('API - SYSTEM - %s - %s', transaction_id, invalid_msisdn_error.msg) except INQueryError as in_query_error: logger.error('API - SYSTEM - %s - %s', transaction_id, in_query_error.msg)
def test_account_info_returns_dict( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_inconnection_enter.return_value.display_account_info.return_value = { 'ACCLEFT': '12300', 'SUBSCRIBERTYPE': '9', 'ACNTSTAT': '1', 'CALLSERVSTOP': '2019-03-12' } mock_inconnection_exit.return_value = None mock_msisdn = mock.ANY mock_current_user = mock.Mock() prepaid_request = INRequestHandler(None, None, None) # Act result = prepaid_request.account_info(mock_msisdn, mock_current_user) # Assert assert isinstance(result, dict)