예제 #1
0
    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())
예제 #2
0
    def setup_context(self):
        if Path(self.determine_bunq_conf_filename()).is_file():
            pass
        else:
            sandbox_user = self.generate_new_sandbox_user()
            ApiContext(
                ApiEnvironmentType.SANDBOX, sandbox_user.api_key, socket.gethostname()
            ).save(self.determine_bunq_conf_filename())

        self._api_context = ApiContext.restore(self.determine_bunq_conf_filename())
        self._api_context.ensure_session_active()
        self._api_context.save(self.determine_bunq_conf_filename())

        BunqContext.load_api_context(self._api_context)

        self._user_context = BunqContext.user_context()
예제 #3
0
    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)
예제 #4
0
    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.alias_first, self._CARD_TYPE_MAESTRO,
                                      [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)
예제 #5
0
from bunq.sdk.context import ApiContext, BunqContext

with open('bunq.conf', 'r') as content_file:
    content = content_file.read()
    api = ApiContext.from_json(content)

BunqContext.load_api_context(api)

print(BunqContext.user_context().primary_monetary_account.balance.value)
예제 #6
0
from bunq.sdk.context import ApiContext, BunqContext

with open('bunq.conf', 'r') as content_file:
    content = content_file.read()
    api = ApiContext.from_json(content)

BunqContext.load_api_context(api)

print(BunqContext.user_context().user_person.alias[0].value)
print(BunqContext.user_context().user_person.alias[1].value)
예제 #7
0
 def __should_request_spending_money(self):
     return self.env == ApiEnvironmentType.SANDBOX \
            and float(BunqContext.user_context().primary_monetary_account.balance.value) <= self._ZERO_BALANCE