Skip to content

Commit

Permalink
Merge pull request #331 from flablog/fix-new-task-type
Browse files Browse the repository at this point in the history
Check task type exists before creating it
  • Loading branch information
EvanBldy authored Aug 7, 2024
2 parents 02f618d + fc96ad7 commit e44a52c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 5 additions & 3 deletions gazu/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
9 changes: 3 additions & 6 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e44a52c

Please sign in to comment.