import requests
import json


def create_user(identifier, host, manager=''):
    """Creates a user in the system having the given identifier as name, password, username and *optional* manager

       Returns the response payload of the user creation rest call as a json object.
    """
    payload_current_manager = {'name': identifier, 'password': identifier, 'username': identifier,
                               'email': identifier + '@mail.com', 'manager': manager, 'metadata': ''}

    response_create_user = requests.post('http://' + host + ':8000/api/users/', json=payload_current_manager)
    return json.loads(response_create_user.text)