def _get_bol_username(context, has_bol=True): """ Utility method to call get_bol_username with or without a Benefits OnLine account """ context.has_bol = has_bol with mock_login_requests(context): with mock_request(context, ContextXmlMock(context).paychex_account_data): try: return context.paychex.get_bol_username() except (PychexNoBolUsernameError, PychexUnauthenticatedError): context.exceptions.append(sys.exc_info()[1])
def _login(context, logging_into, password=None, http_status=200): """ Call the login method of the specified type of object """ with mock_login_requests(context): with mock_benefits_requests(context, http_status): try: if logging_into == 'paychex': assert context.paychex.login(password) elif logging_into == 'benefits_online': context.benefits_online.password = password assert context.benefits_online.login() else: assert context.benefits_online.retirement_services.login() except (PychexInvalidPasswordError, PychexUnknownError, PychexSecurityImageMissingError): context.exceptions.append(sys.exc_info()[1])
def authorize(context, input_mock, getpass_mock, image_open_mock): """ Test running the authorize method """ with mock_login_requests(context): with mock_request(context, FileMock().security_image_gif): mock_func = ContextXmlMock(context).paychex_account_data with mock_request(context, mock_func): getpass_mock.return_value = context.password input_mock.return_value = context.security_answer arguments = { 'authorize': True, '--config': context.config_file, '<username>': context.username } pychex_cli = PychexCli(arguments) input_mock.assert_called_once_with( 'Is this your security image (Y/n)? ') assert image_open_mock.call_count == 1 if context.security_answer in ['yes', 'y', 'ye', '']: getpass_mock.assert_called_once_with( 'Password (input hidden): ') assert pychex_cli.username == context.username
def run_account_summary(context, json=False): # Make sure the password check passes in the paychex_login mock context.paychex = MagicMock() context.paychex.password = context.password # Reset the stdout capture context.stdout_capture.truncate(0) context.stdout_capture.seek(0) with mock_login_requests(context): mock_obj = ContextXmlMock(context) with mock_request(context, mock_obj.paychex_account_data): with mock_benefits_requests(context): arguments = { 'authorize': False, 'account_summary': True, '--config': context.config_file, '--json': json } try: PychexCli(arguments) except Exception: assert False, 'Exception: %s' % sys.exc_info()[1]