def test_auto_bunq_context_update(self): """ Tests the auto update of BunqContext. """ api_context: ApiContext = BunqContext.api_context() api_context_json: object = json.loads(api_context.to_json()) api_context_json[self.__FIELD_SESSION_CONTEXT][ self.__FIELD_EXPIRE_TIME] = self.__TIME_STAMP_IN_PAST expired_api_context = ApiContext.from_json( json.dumps(api_context_json)) self.assertNotEqual(api_context.session_context.expiry_time, expired_api_context.session_context.expiry_time) self.assertEqual(BunqContext.api_context().session_context.expiry_time, api_context.session_context.expiry_time) BunqContext.update_api_context(expired_api_context) BunqContext.user_context().refresh_user_context() self.assertNotEqual( BunqContext.api_context().session_context.expiry_time, api_context.session_context.expiry_time) self.assertFalse(BunqContext.api_context().ensure_session_active())
def alias_first(self) -> Pointer: if BunqContext.user_context().is_only_user_company_set(): return BunqContext.user_context().user_company.alias[ self._FIRST_INDEX] if BunqContext.user_context().is_only_user_person_set(): return BunqContext.user_context().user_person.alias[ self._FIRST_INDEX] raise BunqException(self.__ERROR_COULD_NOT_DETERMINE_USER)
def _determine_monetary_account_id(cls, monetary_account_id: int = None) -> int: from bunq.sdk.context.bunq_context import BunqContext if monetary_account_id is None: return BunqContext.user_context().primary_monetary_account.id_ return monetary_account_id
def test_create_and_update_tab(self): """ Tests the creation of a Tab, adds a tab item to it and updates this tab This test has no assertion as of its testing to see if the code runs without errors """ if BunqContext.user_context().is_only_user_person_set(): return unittest.skip(self._ERROR_ONLY_USER_COMPANY_CAN_CREATE_TAB) tab_uuid = TabUsageSingle.create( self._get_cash_register_id(), self._TAB_DESCRIPTION, self._STATUS_OPEN, Amount(self._AMOUNT_EUR, self._CURRENCY)).value self._add_item_to_tab(tab_uuid) self._update_tab(tab_uuid)
def test_order_debit_card(self): """ Tests ordering a new card and checks if the fields we have entered are indeed correct by retrieving the card from the card endpoint and checks this date against the data we have submitted """ second_line = self.second_line_random pin_code_assignment = CardPinAssignment( self._PIN_CODE_ASSIGNMENT_TYPE_PRIMARY, self._CARD_PIN_CODE, BunqContext.user_context().primary_monetary_account.id_) card_debit = CardDebit.create(second_line, self.card_name_allowed, self._CARD_TYPE_MAESTRO, self.alias_first, self._PRODUCT_TYPE_MAESTRO_DEBIT, [pin_code_assignment]).value card = Card.get(card_debit.id_).value self.assertEqual(self.card_name_allowed, card.name_on_card) self.assertEqual(second_line, card.second_line) self.assertEqual(card_debit.created, card.created)
def get_primary_monetary_account(): return BunqContext.user_context().primary_monetary_account
def __should_request_spending_money(self): return self.env == ApiEnvironmentType.SANDBOX \ and float(BunqContext.user_context().primary_monetary_account.balance.value) <= self._ZERO_BALANCE
def setUp(self): self.__set_second_monetary_account() self.__request_spending_money() time.sleep(self.__TIME_OUT_AUTO_ACCEPT_SPENDING_MONEY) BunqContext.user_context().refresh_user_context()
def _determine_user_id(cls) -> int: from bunq.sdk.context.bunq_context import BunqContext return BunqContext.user_context().user_id