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 test_purchase_package_return_value( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_msisdn = mock.ANY mock_package_type = mock.ANY mock_package_grade = mock.ANY mock_profile = mock.ANY mock_current_user = mock.Mock() mock_inconnection_enter.return_value.purchase_package.return_value = True mock_host = '172.18.0.2' mock_port = 7090 mock_buffer_size = 4096 prepaid_request = INRequestHandler( host=mock_host, port=mock_port, buffer_size=mock_buffer_size) # Act success_result = prepaid_request.purchase_package( msisdn=mock_msisdn, current_profile=mock_profile, package_type=mock_package_type, current_user=mock_current_user, package_grade=mock_package_grade) # Assert assert success_result == { 'operationResult': 'OK', 'msisdn': mock_msisdn, 'packageType': mock_package_type, 'packageGrade': mock_package_grade }
def test_purchase_package_failed( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_msisdn = mock.ANY mock_package_type = mock.ANY mock_package_grade = mock.ANY mock_profile = mock.ANY mock_current_user = mock.Mock() mock_inconnection_enter.return_value.purchase_package.return_value = False prepaid_request = INRequestHandler( None, None, None ) # Act success_result = prepaid_request.purchase_package( msisdn=mock_msisdn, current_profile=mock_profile, package_type=mock_package_type, current_user=mock_current_user, package_grade=mock_package_grade) # Assert assert success_result == { 'operationResult': 'FAILED', 'msisdn': mock_msisdn, 'packageType': mock_package_type, 'packageGrade': mock_package_grade }
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 test_purchase_package_returns_dict( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_msisdn = mock.ANY mock_package_type = mock.ANY mock_package_grade = mock.ANY mock_profile = mock.ANY mock_current_user = mock.Mock() mock_inconnection_enter.return_value.purchase_package.return_value = True prepaid_request = INRequestHandler( None, None, None ) # Act success_result = prepaid_request.purchase_package( msisdn=mock_msisdn, current_profile=mock_profile, package_type=mock_package_type, current_user=mock_current_user, package_grade=mock_package_grade) # Assert assert isinstance(success_result, dict)
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 debit_msisdn(current_user: User, transaction_id: str): try: data = request.get_json() request_manager = INRequestHandler( host=app.config['IN_SERVER']['HOST'], port=app.config['IN_SERVER']['PORT'], buffer_size=app.config['IN_SERVER']['BUFFER_SIZE']) successful_operation = request_manager.debit_airtime( msisdn=data['msisdn'], amount=data['amount'], current_user=current_user) if successful_operation: debit_response = { 'transactionalId': transaction_id, 'operationalResult': 'OK', 'msisdn': data['msisdn'], 'amount': data['amount'] } status_code = 200 logger.info( 'API - SYSTEM - %s - SUCCESS debit of airtime %s from %s - %s', transaction_id, data['amount'], data['msisdn'], current_user.username) else: debit_response = { 'transactionalId': transaction_id, 'operationalResult': 'FAILED', 'msisdn': data['msisdn'], 'amount': data['amount'] } status_code = 400 logger.warning( 'API - SYSTEM - %s - FAILED debit of airtime %s from %s - %s', transaction_id, data['amount'], data['msisdn'], current_user.username) return jsonify(debit_response), status_code 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 INDebitError as in_debit_error: logger.error('API - SYSTEM - %s - %s', transaction_id, in_debit_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)
def test_credit_airtime_failure( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_msisdn = mock.ANY mock_amount = mock.ANY mock_current_user = mock.Mock() mock_inconnection_enter.return_value.credit_account.return_value = False prepaid_request = INRequestHandler( None, None, None ) # Act success_result = prepaid_request.credit_airtime( mock_msisdn, mock_amount, mock_current_user) # Assert assert not success_result
def test_debit_airtime_success( mock_inconnection_enter, mock_inconnection_exit ): # Arrange mock_inconnection_exit.return_value = None mock_msisdn = mock.ANY mock_amount = mock.ANY mock_current_user = mock.Mock() mock_inconnection_enter.return_value.debit_account.return_value = True prepaid_request = INRequestHandler( None, None, None ) # Act success_result = prepaid_request.debit_airtime( mock_msisdn, mock_amount, mock_current_user) # Assert assert success_result