Пример #1
0
    def test_check_int(self):
        self.logger.info('test_check_int')

        self.assertEqual(common.check_int(0), 0)

        self.assertEqual(common.check_int(1000), 1000)

        self.assertEqual(common.check_int('0'), 0)

        self.assertEqual(common.check_int('1000'), 1000)

        got_exception = False
        try:
            common.check_int('Hello World!')
        except Exception as ex:
            self.logger.error(ex)
            got_exception = True

        self.assertTrue(got_exception)

        got_exception = False
        try:
            common.check_int(None)
        except Exception as ex:
            self.logger.error(ex)
            got_exception = True

        self.assertTrue(got_exception)
Пример #2
0
    def from_dict(authentication_dict: Any):
        access_token = None
        expires_in = None
        token_type = None
        refresh_token = None
        scope = None
        error = None

        common.check_dict(authentication_dict)
        if "access_token" in authentication_dict:
            if authentication_dict.get("access_token") is not None:
                access_token = common.check_str(
                    authentication_dict.get("access_token"))
        if "expires_in" in authentication_dict:
            if authentication_dict.get("expires_in") is not None:
                expires_in = common.check_int(
                    authentication_dict.get("expires_in"))
        if "token_type" in authentication_dict:
            if authentication_dict.get("token_type") is not None:
                token_type = common.check_str(
                    authentication_dict.get("token_type"))
        if "refresh_token" in authentication_dict:
            if authentication_dict.get("refresh_token") is not None:
                refresh_token = common.check_str(
                    authentication_dict.get("refresh_token"))
        if "scope" in authentication_dict:
            if authentication_dict.get("scope") is not None:
                scope = common.check_str(authentication_dict.get("scope"))
        if "error" in authentication_dict:
            if authentication_dict.get("error") is not None:
                error = common.check_str(authentication_dict.get("error"))

        return OAuth2Return(access_token, expires_in, token_type,
                            refresh_token, scope, error)
Пример #3
0
    def from_dict(client_response_dict: Any):
        status = None
        body = None

        common.check_dict(client_response_dict)
        if "status" in client_response_dict:
            if client_response_dict.get("status") is not None:
                status = common.check_int(client_response_dict.get("status"))
        if "body" in client_response_dict:
            if client_response_dict.get("body") is not None:
                if isinstance(body, str):
                    body = common.check_str(client_response_dict.get("body"))
                elif isinstance(body, bytes):
                    body = client_response_dict.get("body")
        return ClientResponse(status=status, body=body)
Пример #4
0
 def from_dict(oauth2_return_dict: Any):
     
     """
     Create an OAuth2Return object from a dictionary.
     
     :param oauth2_return_dict: A dictionary that contains the keys of an OAuth2Return object.
     :type oauth2_return_dict:  Any             
     :rtype:                    ibmpairs.authentication.OAuth2Return
     :raises Exception:         if not a dictionary.
     """
     
     access_token  = None
     expires_in    = None
     token_type    = None
     refresh_token = None
     scope         = None
     error         = None
     
     common.check_dict(oauth2_return_dict)
     if "access_token" in oauth2_return_dict:
         if oauth2_return_dict.get("access_token") is not None:
             access_token = common.check_str(oauth2_return_dict.get("access_token"))
     if "expires_in" in oauth2_return_dict:
         if oauth2_return_dict.get("expires_in") is not None:
             expires_in = common.check_int(oauth2_return_dict.get("expires_in"))
     if "token_type" in oauth2_return_dict:
         if oauth2_return_dict.get("token_type") is not None:
             token_type = common.check_str(oauth2_return_dict.get("token_type"))
     if "refresh_token" in oauth2_return_dict:
         if oauth2_return_dict.get("refresh_token") is not None:
             refresh_token = common.check_str(oauth2_return_dict.get("refresh_token"))
     if "scope" in oauth2_return_dict:
         if oauth2_return_dict.get("scope") is not None:
             scope = common.check_str(oauth2_return_dict.get("scope"))
     if "error" in oauth2_return_dict:
         if oauth2_return_dict.get("error") is not None:
             error = common.check_str(oauth2_return_dict.get("error"))
         
     return OAuth2Return(access_token  = access_token,
                         expires_in    = expires_in,
                         token_type    = token_type,
                         refresh_token = refresh_token,
                         scope         = scope,
                         error         = error
                        )
Пример #5
0
 def set_integer(self, integer):
     self._integer = common.check_int(integer)
Пример #6
0
 def set_status(self, status):
     self._status = common.check_int(status)
Пример #7
0
 def set_expires_in(self, expires_in):
     self._expires_in = common.check_int(expires_in)