def setup_context(self, reset_config_if_needed=True): if isfile(self.conf): self._BUNQ_CONF_CUSTOM = self.conf pass # Config is already present elif isfile(self.determine_bunq_conf_filename()): pass # Config is already present elif self.env == ApiEnvironmentType.SANDBOX: sandbox_user = self.generate_new_sandbox_user() ApiContext.create(ApiEnvironmentType.SANDBOX, sandbox_user.api_key, socket.gethostname()).save( self.determine_bunq_conf_filename()) else: raise BunqException(self._ERROR_COULD_NOT_DETIRMINE_CONF) try: api_context = ApiContext.restore( self.determine_bunq_conf_filename()) api_context.ensure_session_active() api_context.save(self.determine_bunq_conf_filename()) BunqContext.load_api_context(api_context) except ForbiddenException as forbidden_exception: if reset_config_if_needed: self.__handle_forbidden_exception(forbidden_exception) else: raise forbidden_exception
def test_bad_request_with_response_id(self): """ """ BunqContext.load_api_context(self._get_api_context()) with self.assertRaises(ApiException) as caught_exception: MonetaryAccountBank.get(self._INVALID_MONETARY_ACCOUNT_ID) self.assertIsNotNone(caught_exception.exception.response_id)
def setUpClass(cls): cls._PAYMENT_LISTING_PAGE_SIZE = 2 cls._PAYMENT_REQUIRED_COUNT_MINIMUM = cls._PAYMENT_LISTING_PAGE_SIZE * 2 cls._NUMBER_ZERO = 0 cls._PAYMENT_AMOUNT_EUR = '0.01' cls._PAYMENT_CURRENCY = 'EUR' cls._PAYMENT_DESCRIPTION = 'Python test Payment' BunqContext.load_api_context(cls._get_api_context())
def setup_test_data(cls) -> None: if not os.path.isfile(cls._FILE_TEST_CONFIGURATION_PATH_FULL): try: BunqContext.load_api_context(cls._create_api_context()) except FileNotFoundError: return api_context = ApiContext.restore( cls._FILE_TEST_CONFIGURATION_PATH_FULL) BunqContext.load_api_context(api_context)
def test_create_psd2_context(self) -> None: if os.path.isfile(self._FILE_TEST_CONFIGURATION_PATH_FULL): return try: api_context = self._create_api_context() BunqContext.load_api_context(api_context) self.assertTrue( os.path.isfile(self._FILE_TEST_CONFIGURATION_PATH_FULL)) except AssertionError: raise AssertionError
def init(api_key_fn): AnchorObjectAdapter._override_field_map.update({ 'ScheduledPaymentBatch': 'SchedulePaymentBatch', 'TransferwisePayment': 'TransferwiseTransfer', }) if CONTEXTFILE.exists(): context = ApiContext.restore(str(CONTEXTFILE)) else: context = ApiContext.create(ApiEnvironmentType.PRODUCTION, api_key_fn(), DEVICE_DESCRIPTION) context.save(str(CONTEXTFILE)) BunqContext.load_api_context(context)
def setup_context(self): if isfile(self.determine_bunq_conf_filename()): pass # Config is already present elif self.env == ApiEnvironmentType.SANDBOX: sandbox_user = self.generate_new_sandbox_user() ApiContext.create(ApiEnvironmentType.SANDBOX, sandbox_user.api_key, socket.gethostname()).save( self.determine_bunq_conf_filename()) else: raise BunqException(self._ERROR_COULD_NOT_DETIRMINE_CONF) api_context = ApiContext.restore(self.determine_bunq_conf_filename()) api_context.ensure_session_active() api_context.save(self.determine_bunq_conf_filename()) BunqContext.load_api_context(api_context)
def main(ctx, iban: str, api_key: str, sandbox: bool, currency: str): """ \b ____ _ | __ ) _ _ __ _ _ _| |_ | _ \| | | |/ _` | | | | __| | |_) | |_| | (_| | |_| | |_ |____/ \__,_|\__,_|\__,_|\__| Buaut are several Bunq automations in a convenient CLI tool. Enable autocomplete for Bash (.bashrc): eval "$(_BUAUT_COMPLETE=source buaut)" Enable autocomplete for ZSH (.zshrc): eval "$(_BUAUT_COMPLETE=source_zsh buaut)" """ # Set Bunq context context = ApiEnvironmentType.SANDBOX if sandbox \ else ApiEnvironmentType.PRODUCTION # Setup Bunq authentication api_context = ApiContext.create(context, api_key, socket.gethostname()) api_context.ensure_session_active() # Load api context into BunqContext used for subsequent calls BunqContext.load_api_context(api_context) if validators.iban(iban): try: # Set monetary_account monetary_account: int = utils.get_monetary_account( value_type='IBAN', value=iban) except: # TODO: Exit nicely exit(1) else: # TODO: Exit nicely exit(1) # Append to ctx object to have available in commands ctx.obj = {} ctx.obj['args'] = {} ctx.obj['args']['iban'] = iban ctx.obj['args']['api_key'] = api_key ctx.obj['monetary_account'] = monetary_account ctx.obj['currency'] = currency
def setup_context(self): if 'bunq-conf' in self.config.value: LOGGER.debug('Found existing api context config. Restoring.') api_context = ApiContext.from_json(self.config.value['bunq-conf']) api_context.ensure_session_active() else: LOGGER.debug('Did not find existing api context config. creating.') api_context = ApiContext.create( ApiEnvironmentType.PRODUCTION, self.config.value['bunq']['api_token'], self.DEVICE_DESCRIPTION) self.config.value['bunq-conf'] = api_context.to_json() LOGGER.info('persisting new api context config') self.config.save(self.config.value) BunqContext.load_api_context(api_context)
def setUpClass(cls) -> None: BunqContext.load_api_context(cls._get_api_context())