コード例 #1
0
def test_config_clear_api_key():
    config.config_file_clear_section(SECTION)
    random_key = ''.join(
        random.choices(string.ascii_uppercase + string.digits, k=12))
    config.config_file_save_api_key(random_key, USERNAME, SECTION)
    assert config.config_file_read_api_key(SECTION) == random_key
    config.config_file_clear_api_key(SECTION)
    assert config.config_file_read_api_key(SECTION) is None
コード例 #2
0
 def setUp(self):
     config_file_clear_section('test')
     config_file_save_api_key('11223344556677889900',
                              'cedric',
                              section='test')
     config_file_save_organisation_membership('saao',
                                              'superadmin',
                                              section='test')
     httpretty.enable()
コード例 #3
0
 def _get_and_save_api_key(cls, state, username, auth_token):
     ArcsecondAPI._echo_message(state, 'Fetching API Key...')
     # To get API key one must fetch it with Auth token obtained via login.
     endpoint = ProfileAPIKeyAPIEndPoint(state.make_new_silent())
     endpoint.use_headers({'Authorization': 'Token ' + auth_token})
     result, error = endpoint.read(username)
     if error:
         ArcsecondAPI._echo_error(state, error)
     if result:
         config_file_save_api_key(result['api_key'], username, state.config_section())
         msg = f'Successful API key retrieval and storage in {config_file_path()}. Enjoy.'
         ArcsecondAPI._echo_message(state, msg)
     return result, error
コード例 #4
0
 def _get_and_save_api_key(cls, state, username, auth_token):
     headers = {'Authorization': 'Token ' + auth_token}
     silent_state = state.make_new_silent()
     result, error = ProfileAPIKeyAPIEndPoint(silent_state).read(
         username, **headers)
     if error:
         return ArcsecondAPI._echo_error(state, error)
     if result:
         api_key = result['api_key']
         config_file_save_api_key(api_key, username, state.debug)
         if state.verbose:
             click.echo(
                 'Successful API key retrieval and storage in {}. Enjoy.'.
                 format(config_file_path()))
         return result
コード例 #5
0
def test_config_file_is_logged_in_has_api_and_upload_keys():
    config.config_file_clear_section(SECTION)
    config.config_file_save_api_key(API_KEY, USERNAME, SECTION)
    config.config_file_save_upload_key(UPLOAD_KEY, USERNAME, SECTION)
    assert config.config_file_is_logged_in(SECTION) is True
コード例 #6
0
def save_test_credentials(username, memberships=None):
    if memberships is None:
        memberships = dict()
    config_file_save_api_key(TEST_API_KEY, username, section='test')
    for k, v in memberships.items():
        config_file_save_organisation_membership(k, v, 'test')