diff --git a/gazu/asset.py b/gazu/asset.py index 700a53a3..2d9ca450 100644 --- a/gazu/asset.py +++ b/gazu/asset.py @@ -248,7 +248,7 @@ def remove_asset(asset, force=False, client=default): path = "data/assets/%s" % asset["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params, client=client) diff --git a/gazu/concept.py b/gazu/concept.py index 03ebd12a..1b9f9513 100644 --- a/gazu/concept.py +++ b/gazu/concept.py @@ -62,7 +62,7 @@ def remove_concept(concept, force=False, client=default): path = "data/concepts/%s" % concept["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params, client=client) diff --git a/gazu/edit.py b/gazu/edit.py index 7ff70208..2f251de0 100644 --- a/gazu/edit.py +++ b/gazu/edit.py @@ -138,7 +138,7 @@ def remove_edit(edit, force=False, client=default): path = "data/edits/%s" % edit["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params, client=client) diff --git a/gazu/entity.py b/gazu/entity.py index 9c214c21..20c35a7a 100644 --- a/gazu/entity.py +++ b/gazu/entity.py @@ -125,7 +125,7 @@ def remove_entity(entity, force=False, client=default): path = "data/entities/%s" % entity["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params, client=client) diff --git a/gazu/person.py b/gazu/person.py index 52742a66..f782a9c2 100644 --- a/gazu/person.py +++ b/gazu/person.py @@ -89,8 +89,8 @@ def get_person(id, relations=False, client=default): dict: Person corresponding to given id. """ params = {"id": id} - if relations: - params["relations"] = "true" + if not relations: + params["relations"] = False return raw.fetch_first("persons", params=params, client=client) @@ -105,7 +105,9 @@ def get_person_by_desktop_login(desktop_login, client=default): dict: Person corresponding to given desktop computer login. """ return raw.fetch_first( - "persons", {"desktop_login": desktop_login}, client=client + "persons", + {"desktop_login": desktop_login, "is_bot": False}, + client=client, ) @@ -118,7 +120,9 @@ def get_person_by_email(email, client=default): Returns: dict: Person corresponding to given email. """ - return raw.fetch_first("persons", {"email": email}, client=client) + return raw.fetch_first( + "persons", {"email": email, "is_bot": False}, client=client + ) @cache @@ -137,16 +141,19 @@ def get_person_by_full_name( if first_name is not None and last_name is not None: return raw.fetch_first( "persons", - {"first_name": first_name, "last_name": last_name}, + { + "first_name": first_name, + "last_name": last_name, + "is_bot": False, + }, client=client, ) else: return raw.fetch_first( "persons", - {"full_name": full_name}, + {"full_name": full_name, "is_bot": False}, client=client, ) - return None @cache @@ -184,8 +191,8 @@ def new_person( desktop_login="", departments=[], password=None, - is_bot=False, - expiration_date=None, + active=True, + contract_type="open-ended", client=default, ): """ @@ -193,17 +200,16 @@ def new_person( set automatically to default. Args: - first_name (str): - last_name (str): - email (str): - phone (str): + first_name (str): the first name of the person. + last_name (str): the last name of the person. + email (str): the email of the person. + phone (str): the phone number of the person. role (str): user, manager, admin (wich match CG artist, Supervisor and studio manager) desktop_login (str): The login the users uses to log on its computer. departments (list): The departments for the person. password (str): The password for the person. - is_bot (bool): Whether the person is a bot or not. - expiration_date (str): The expiration date for the person. + active (bool): Whether the person is active or not. Returns: dict: Created person. """ @@ -220,8 +226,8 @@ def new_person( "desktop_login": desktop_login, "departments": normalize_list_of_models_for_links(departments), "password": password, - "is_bot": is_bot, - "expiration_date": expiration_date, + "active": active, + "contract_type": contract_type, }, client=client, ) @@ -252,6 +258,85 @@ def update_person(person, client=default): ) +def remove_person(person, force=False, client=default): + """ + Remove given person from database. + + Args: + person (dict): Person to remove. + """ + person = normalize_model_parameter(person) + path = "data/persons/%s" % person["id"] + params = {} + if force: + params = {"force": True} + return raw.delete(path, params, client=client) + + +def new_bot( + name, + email, + role="user", + departments=[], + active=True, + expiration_date=None, + client=default, +): + """ + Create a new bot based on given parameters. His access token will be in the + return dict. + + Args: + name (str): the name of the bot. + email (str): the email of the bot. + role (str): user, manager, admin (wich match CG artist, Supervisor + and studio manager) + departments (list): The departments for the person. + active (bool): Whether the person is active or not. + expiration_date (str): The expiration date for the bot. + Returns: + dict: Created bot. + """ + bot = raw.post( + "data/persons", + { + "first_name": name, + "last_name": "", + "email": email, + "role": role, + "departments": normalize_list_of_models_for_links(departments), + "active": active, + "expiration_date": expiration_date, + "is_bot": True, + }, + client=client, + ) + return bot + + +def update_bot(bot, client=default): + """ + Update a bot. + + Args: + bot (dict): The bot dict that needs to be upgraded. + + Returns: + dict: The updated bot. + """ + return update_person(bot, client=client) + + +def remove_bot(bot, force=False, client=default): + """ + Remove given bot from database. + + Args: + bot (dict): Bot to remove. + """ + return remove_person(bot, force=force, client=client) + + def set_avatar(person, file_path, client=default): """ Upload picture and set it as avatar for given person. diff --git a/gazu/project.py b/gazu/project.py index b9498546..36aef1fe 100644 --- a/gazu/project.py +++ b/gazu/project.py @@ -396,7 +396,7 @@ def remove_metadata_descriptor( metadata_descriptor = normalize_model_parameter(metadata_descriptor_id) params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete( "data/projects/%s/metadata-descriptors/%s" % (project["id"], metadata_descriptor["id"]), diff --git a/gazu/shot.py b/gazu/shot.py index b3729c5f..ea6e02e2 100644 --- a/gazu/shot.py +++ b/gazu/shot.py @@ -446,7 +446,7 @@ def remove_shot(shot, force=False, client=default): path = "data/shots/%s" % shot["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params, client=client) @@ -532,7 +532,7 @@ def remove_episode(episode, force=False, client=default): path = "data/episodes/%s" % episode["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params=params, client=client) @@ -547,7 +547,7 @@ def remove_sequence(sequence, force=False, client=default): path = "data/sequences/%s" % sequence["id"] params = {} if force: - params = {"force": "true"} + params = {"force": True} return raw.delete(path, params=params, client=client) diff --git a/gazu/task.py b/gazu/task.py index 10ad510b..97e950fa 100644 --- a/gazu/task.py +++ b/gazu/task.py @@ -80,7 +80,7 @@ def all_tasks_for_shot(shot, relations=False, client=default): shot = normalize_model_parameter(shot) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} tasks = raw.fetch_all("shots/%s/tasks" % shot["id"], params, client=client) return sort_by_name(tasks) @@ -97,7 +97,7 @@ def all_tasks_for_concept(concept, relations=False, client=default): concept = normalize_model_parameter(concept) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} tasks = raw.fetch_all( "concepts/%s/tasks" % concept["id"], params, client=client ) @@ -116,7 +116,7 @@ def all_tasks_for_edit(edit, relations=False, client=default): edit = normalize_model_parameter(edit) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} tasks = raw.fetch_all("edits/%s/tasks" % edit["id"], params, client=client) return sort_by_name(tasks) @@ -133,7 +133,7 @@ def all_tasks_for_sequence(sequence, relations=False, client=default): sequence = normalize_model_parameter(sequence) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "sequences/%s/tasks" % sequence["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -151,7 +151,7 @@ def all_tasks_for_scene(scene, relations=False, client=default): scene = normalize_model_parameter(scene) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "scenes/%s/tasks" % scene["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -169,7 +169,7 @@ def all_tasks_for_asset(asset, relations=False, client=default): asset = normalize_model_parameter(asset) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "assets/%s/tasks" % asset["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -183,7 +183,7 @@ def all_tasks_for_episode(episode, relations=False, client=default): episode = normalize_model_parameter(episode) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "episodes/%s/tasks" % episode["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -197,7 +197,7 @@ def all_shot_tasks_for_sequence(sequence, relations=False, client=default): sequence = normalize_model_parameter(sequence) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "sequences/%s/shot-tasks" % sequence["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -211,7 +211,7 @@ def all_shot_tasks_for_episode(episode, relations=False, client=default): episode = normalize_model_parameter(episode) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "episodes/%s/shot-tasks" % episode["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -225,7 +225,7 @@ def all_assets_tasks_for_episode(episode, relations=False, client=default): episode = normalize_model_parameter(episode) params = {} if relations: - params = {"relations": "true"} + params = {"relations": True} path = "episodes/%s/asset-tasks" % episode["id"] tasks = raw.fetch_all(path, params, client=client) return sort_by_name(tasks) @@ -562,7 +562,7 @@ def remove_task_type(task_type, client=default): task_type = normalize_model_parameter(task_type) return raw.delete( "data/task-types/%s" % task_type["id"], - {"force": "true"}, + {"force": True}, client=client, ) @@ -577,7 +577,7 @@ def remove_task_status(task_status, client=default): task_status = normalize_model_parameter(task_status) return raw.delete( "data/task-status/%s" % task_status["id"], - {"force": "true"}, + {"force": True}, client=client, ) @@ -649,7 +649,7 @@ def remove_task(task, client=default): task (str / dict): The task dict or the task ID. """ task = normalize_model_parameter(task) - raw.delete("data/tasks/%s" % task["id"], {"force": "true"}, client=client) + raw.delete("data/tasks/%s" % task["id"], {"force": True}, client=client) def start_task(task, started_task_status=None, client=default): diff --git a/tests/test_asset.py b/tests/test_asset.py index f3b0452e..57d14705 100644 --- a/tests/test_asset.py +++ b/tests/test_asset.py @@ -198,9 +198,8 @@ def test_put_asset_type(self): def test_remove_asset_type(self): with requests_mock.mock() as mock: - mock.delete( - gazu.client.get_full_url("data/asset-types/asset-type-01"), - text="", + mock_route( + mock, "DELETE", "data/asset-types/asset-type-01", text="" ) asset_type = {"id": "asset-type-01", "name": "Modeling edited"} response = gazu.asset.remove_asset_type(asset_type) @@ -208,14 +207,13 @@ def test_remove_asset_type(self): def test_remove_asset(self): with requests_mock.mock() as mock: - mock.delete( - gazu.client.get_full_url("data/assets/asset-01"), - status_code=204, - ) + mock_route(mock, "DELETE", "data/assets/asset-01", status_code=204) asset = {"id": "asset-01", "name": "Table"} gazu.asset.remove_asset(asset) - mock.delete( - gazu.client.get_full_url("data/assets/asset-01?force=true"), + mock_route( + mock, + "DELETE", + "data/assets/asset-01?force=True", status_code=204, ) asset = {"id": "asset-01", "name": "Table"} diff --git a/tests/test_person.py b/tests/test_person.py index 578fd213..717bd03d 100644 --- a/tests/test_person.py +++ b/tests/test_person.py @@ -119,6 +119,26 @@ def test_new_person(self): result, ) + def test_new_bot(self): + with requests_mock.mock() as mock: + result = { + "first_name": "Bot 1", + "last_name": "", + "is_bot": True, + "id": "bot-1", + "departments": [fakeid("department-1")], + } + mock_route(mock, "POST", "data/persons", text=result) + self.assertEqual( + gazu.person.new_bot( + "Bot 1", + "test@test.com", + "admin", + departments=fakeid("department-1"), + ), + result, + ) + def test_update_person(self): result = { "first_name": "John", @@ -142,6 +162,27 @@ def test_update_person(self): } self.assertEqual(gazu.person.update_person(person), result) + def test_update_bot(self): + result = { + "first_name": "Bot 1", + "last_name": "", + "is_bot": True, + "id": "bot-1", + "departments": [fakeid("department-1")], + } + with requests_mock.mock() as mock: + mock_route( + mock, + "PUT", + "data/persons/%s" % fakeid("bot-1"), + text=result, + ) + bot = { + "id": fakeid("bot-1"), + "departments": [fakeid("department-1")], + } + self.assertEqual(gazu.person.update_bot(bot), result) + def test_all_organisations(self): result = [{"id": fakeid("organisation-1"), "name": "organisation-1"}] with requests_mock.mock() as mock: @@ -155,21 +196,58 @@ def test_all_departments(self): self.assertEqual(gazu.person.all_departments(), result) def test_get_person(self): - result = {"id": fakeid("John Doe"), "full_name": "John Doe"} + result = [{"id": fakeid("John Doe"), "full_name": "John Doe"}] with requests_mock.mock() as mock: - mock.get( - gazu.client.get_full_url( - "data/persons?id=%s" % (fakeid("John Doe")) - ), - text=json.dumps( - [ - result, - ] - ), + mock_route( + mock, + "GET", + "data/persons?id=%s" % (fakeid("John Doe")), + text=result, + ) + self.assertEqual( + gazu.person.get_person(fakeid("John Doe")), result[0] + ) + with requests_mock.mock() as mock: + mock_route( + mock, + "GET", + "data/persons?id=%s&relations=False" % (fakeid("John Doe")), + text=result, ) self.assertEqual( - gazu.person.get_person(fakeid("John Doe")), result + gazu.person.get_person(fakeid("John Doe"), relations=False), + result[0], + ) + + def test_remove_person(self): + with requests_mock.mock() as mock: + mock_route( + mock, "DELETE", "data/persons/person-01", status_code=204 + ) + person = {"id": "person-01", "name": "Table"} + gazu.person.remove_person(person) + mock_route( + mock, + "DELETE", + "data/persons/person-01?force=True", + status_code=204, + ) + person = {"id": "person-01", "name": "Table"} + gazu.person.remove_person(person, True) + + def test_remove_bot(self): + with requests_mock.mock() as mock: + mock_route(mock, "DELETE", "data/persons/bot-01", status_code=204) + bot = {"id": "bot-01", "name": "Table"} + gazu.person.remove_bot(bot) + mock_route( + mock, + "DELETE", + "data/persons/bot-01?force=True", + status_code=204, ) + bot = {"id": "bot-01", "name": "Table"} + gazu.person.remove_bot(bot, True) def test_get_person_url(self): wanted_result = "%s/people/%s/" % (