Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check task type exists before creating it #331

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading