diff --git a/gazu/task.py b/gazu/task.py index f705ef00..4d5e0888 100644 --- a/gazu/task.py +++ b/gazu/task.py @@ -1174,9 +1174,11 @@ def new_task_type(name, color="#000000", for_entity="Asset", client=default): Returns: dict: The created task type """ - data = {"name": name, "color": color, "for_entity": for_entity} - return raw.post("data/task-types", data, client=client) - + task_type = get_task_type_by_name(name, for_entity) + if task_type is None: + data = {"name": name, "color": color, "for_entity": for_entity} + task_type = raw.post("data/task-types", data, client=client) + return(task_type) def new_task_status(name, short_name, color, client=default): """ diff --git a/tests/test_task.py b/tests/test_task.py index 5618972b..62720d05 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -508,13 +508,10 @@ def test_assign_task(self): self.assertIn("person-01", task["assignees"]) def test_new_task_type(self): - task_type_name = "task-type-name" with requests_mock.mock() as mock: - task_type = {"id": "task-type-01", "name": task_type_name} - mock.post( - gazu.client.get_full_url("data/task-types"), - text=json.dumps(task_type), - ) + task_type = {"id": "task-type-01", "name": "task-type-name"} + mock_route(mock, "GET", "data/task-types", text=[]) + mock_route(mock, "POST", "data/task-types", text=task_type) self.assertEqual(gazu.task.new_task_type(task_type), task_type) def test_new_task_status(self):