def create_account_membership(account_id):
     client = RequestManager()
     client.set_method("POST")
     client.set_endpoint(
         "/accounts/{account_id}/memberships".format(account_id=account_id))
     client.set_body(json.dumps(Account_helper.generate_body_membership()))
     client.execute_request()
 def create_stories(proj_id):
     client = RequestManager()
     client.set_method('POST')
     client.set_endpoint('/projects/' + str(proj_id) + '/stories')
     client.set_body("""
         {"name": "Test_001"}
         """)
     return client.execute_request().json()['id']
 def delete_workspace(id_workspace):
     '''
     Delete Workspace
     :param response: Json
     '''
     client = RequestManager()
     client.set_method('DELETE')
     client.set_endpoint('/my/workspaces/' + str(id_workspace))
     client.execute_request()
 def get_accounts():
     """
     Do a request to get the accounts.
     :return: a list of accounts
     """
     client = RequestManager()
     client.set_method('GET')
     client.set_endpoint('/accounts')
     return client.execute_request().json()
 def get_all_workspaces():
     '''
     Get all workspaces
     :return: workspace list
     '''
     client = RequestManager()
     client.set_method('GET')
     client.set_endpoint('/my/workspaces')
     response = client.execute_request()
     return response.json()
 def get_membership_id(account_id):
     """
     get the id of the first membership of an account.
     :param account_id: for the account id
     :return: the id of membership
     """
     client = RequestManager()
     client.set_method("GET")
     client.set_endpoint(
         "/accounts/{account_id}/memberships".format(account_id=account_id))
     client.set_body(json.dumps(Account_helper.generate_body_membership()))
     return client.execute_request().json()[0]["id"]
 def create_account():
     """
     Create a account with a project if account list is less than 5.
     :return: if the account was created return its id else return the id the an account random.
     """
     if len(Account_helper.get_accounts()) < 5:
         client = RequestManager()
         client.set_method("POST")
         client.set_endpoint("/projects")
         client.set_body(json.dumps(Account_helper.generate_body_account()))
         id_account = client.execute_request().json()['account_id']
     else:
         id_account = Account_helper.get_account_random()['id']
     return id_account
 def create_workspace(response):
     '''
     Create workspace
     :return: Workspace Json
     '''
     client = RequestManager()
     client.set_method('POST')
     id_project = response['id']
     client.set_endpoint('/my/workspaces')
     body = {
         "name": "Workspace Test" + str(random.randint(1, 1001)),
         "project_ids": [id_project]
     }
     client.set_body(json.dumps(body))
     response = client.execute_request()
     return response.json()
 def get_account_of_other_user():
     """
     Get the id of a account random of other user account.
     :return: id account.
     """
     client = RequestManager()
     client.set_headers({
         'X-TrackerToken': '6c8164fd6ceaefc042ba28e4c6887184',
         'Content-Type': 'application/json'
     })
     client.set_method('GET')
     client.set_endpoint('/accounts')
     account_list_other_user = client.execute_request().json()
     account = random.choice(account_list_other_user)
     id_account = account['id']
     return id_account
 def get_story_by_proj_id(proj_id):
     client = RequestManager()
     client.set_method('GET')
     client.set_endpoint('/projects/' + str(proj_id) + '/stories')
     response = client.execute_request()
     return response.json()['id']
 def get_account_id():
     client = RequestManager()
     client.set_method('GET')
     client.set_endpoint('/accounts')
     response = client.execute_request()
     return response.json()[0]["id"]