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 test_session_delete(self): """ Tests the deletion and resetting of the current active session This test has no assertion as of its testing to see if the code runs without errors. Notes ----- time.sleep() is needed as of you can only make 1 POST call to Session endpoint per second. """ Session.delete(self._SESSION_ID) time.sleep(2) BunqContext.api_context().reset_session() BunqContext.api_context().save(self._BUNQ_CONFIG_FILE)
def create(cls, grant_type: OauthGrantType, oauth_code: str, redirect_uri: str, client: OauthClient) -> OauthAccessToken: api_client = AnonymousApiClient(BunqContext.api_context()) response_raw = api_client.post( cls.create_token_uri(grant_type.value, oauth_code, redirect_uri, client), bytearray(), {}) return cls.from_json(OauthAccessToken, response_raw).value
def determine_auth_uri_format(cls) -> str: environment_type = BunqContext.api_context().environment_type if ApiEnvironmentType.PRODUCTION == environment_type: return cls.TOKEN_URI_FORMAT_PRODUCTION if ApiEnvironmentType.SANDBOX == environment_type: return cls.TOKEN_URI_FORMAT_SANDBOX raise BunqException(cls.ERROR_ENVIRONMENT_TYPE_NOT_SUPPORTED)
def update_context(self): BunqContext.api_context().save(self.determine_bunq_conf_filename())
def _get_api_context(cls) -> ApiContext: from bunq.sdk.context.bunq_context import BunqContext return BunqContext.api_context()