def test_flow(self):
     """
     This function tests all the flow of this SDK. To test it - remove @skip decorator
     """
     try:
         configs = read_file_to_dict()
         reso = RESO(
             client_id=configs['reso']['client_id'],
             client_secret=configs['reso']['client_secret'],
             api_auth_url=configs['reso']['api_auth_url'],
             api_token_url=configs['reso']['api_token_url'],
             verify_ssl=configs['reso']['verify_ssl'],
             api_request_url=configs['reso']['api_request_url']
         )
         reso.set_logging_level('debug')
         req_obj = OpenIDAuthentication(
             redirect_uri=configs['open_id']['redirect_uri'],
             scope=configs['open_id']['scope'],
             reso=reso
         )
         response = req_obj.authorize(configs['username'], configs['password'])
         req_obj.auth_code = response
         auth_token = req_obj.request_access_token()
         reso.access_token = auth_token
         http_req = HttpRequest(
             reso=reso,
         )
         resp = http_req.request(
             request_url=configs['http_request']['request_path'],
             request_accept_type=configs['http_request']['accept_type'],
         )
     except KeyError:
         raise ValueError('Configs file is not filled.')
     self.assertTrue(resp)
Ejemplo n.º 2
0
def cli_example():
    configs = read_file_to_dict()
    reso = RESO(
        client_id=configs['reso']['client_id'],
        client_secret=configs['reso']['client_secret'],
        # Some vendors bypass access_token by passing and supplying a static value
        access_token=None if 'access_token' not in configs['reso'] else
        configs['reso']['access_token'],
        api_auth_url=configs['reso']['api_auth_url'],
        api_token_url=configs['reso']['api_token_url'],
        verify_ssl=configs['reso']['verify_ssl'],
        api_request_url=configs['reso']['api_request_url'])
    reso.set_logging_level('debug')
    req_obj = OpenIDAuthentication(
        redirect_uri=configs['open_id']['redirect_uri'],
        scope=configs['open_id']['scope'],
        reso=reso)
    response = req_obj.authorize(configs['username'], configs['password'])
    req_obj.auth_code = response

    if not reso.access_token:  # User did not supply access_token (most common case)
        auth_token = req_obj.request_access_token()
        reso.access_token = auth_token

    http_req = HttpRequest(reso=reso, )
    http_req.request_to_file(
        request_url=configs['http_request']['request_path'],
        filename=configs['http_request']['filename'],
        request_accept_type=configs['http_request']['accept_type'],
        output_format=configs['http_request']['output_format'],
        overwrite=True,
        indent=4  # Set to None for pretty print not to be applied
    )
 def test_api_request_url_endswith_backslash(self):
     backslash_url = 'http://example.com/'
     path = 'my-path'
     expected_result = backslash_url + path
     reso = RESO(api_request_url=backslash_url)
     request_obj = HttpRequest(reso)
     self.assertEqual(request_obj._return_formed_url(path), expected_result)
 def test_api_request_both_urls_have_backslashes(self):
     backslash_url = 'http://example.com/'
     path = '/my-path'
     expected_result = backslash_url[:-1] + path
     reso = RESO(api_request_url=backslash_url)
     request_obj = HttpRequest(reso)
     self.assertEqual(request_obj._return_formed_url(path), expected_result)
Ejemplo n.º 5
0
    def test_validate_missing_variable(self):
        reso = RESO()
        variable = 'client_id'
        with self.assertRaises(MissingVariables) as context:
            check_needed_class_vars(reso, [variable])

        self.assertEqual(
            'Missing {} on {}'.format(variable, reso.__class__.__name__),
            str(context.exception))
 def setUp(self):
     reso = RESO()
     self.request_obj = HttpRequest(reso)
     self.filename = 'example.json'
Ejemplo n.º 7
0
 def test_validate_no_missing_variable(self):
     reso = RESO(client_id='some-client-id')
     variable = 'client_id'
     check_needed_class_vars(reso, [variable])
 def setUp(self):
     reso = RESO()
     self.request_obj = HttpRequest(reso)