def create_client(): """ Create a session using credentials in secrets.json. :return: new Agave client """ secrets = get_secrets() credentials = secrets['agave'] if not (credentials.get('api_key') and credentials.get('api_secret')): print( "Generating new api_key and api_secret and saving to secrets.json") ag = Agave(api_server=credentials['api_server'], username=credentials['username'], password=credentials['password']) new_secrets = ag.clients_create() credentials.update(new_secrets) save_secrets(secrets) ag = Agave(api_server=credentials['api_server'], username=credentials['username'], password=credentials['password'], api_key=credentials['api_key'], api_secret=credentials['api_secret'], client_name=credentials['client_name'], tenant_id="sd2e") me = ag.profiles.get() print('Client created as {} {}'.format(me['first_name'], me['last_name'])) return ag
def test_client_create(self, mock_input, mock_pass): """ Test client create op Patch username and password from user to send a client create request to mock server. """ # Patch username and password. mock_input.return_value = "user" mock_pass.return_value = "pass" # Instantiate Agave object making reference to local mock server. local_uri = "http://localhost:{port}/".format( port=self.mock_server_port) ag = Agave(api_server=local_uri) # Create client. ag.clients_create("client-name", "some description") assert ag.api_key == "some api key" assert ag.api_secret == "some secret"