Compare commits

5 Commits

Author SHA1 Message Date
allegroai
b1a50c1370 Version bump to v1.9.1 2023-01-03 12:16:07 +02:00
allegroai
22a2a02760 Allow renaming published reports 2023-01-03 12:15:44 +02:00
allegroai
ab798e4170 Allow updating tags on published reports 2023-01-03 12:15:02 +02:00
allegroai
f09ac672d2 Add pipeline test 2023-01-03 12:14:12 +02:00
allegroai
2149b76f63 Fix crash when starting pipeline 2023-01-03 12:13:48 +02:00
5 changed files with 69 additions and 12 deletions

View File

@@ -60,6 +60,7 @@ def start_pipeline(call: APICall, company_id: str, request: StartPipelineRequest
queued, res = enqueue_task(
task_id=task.id,
company_id=company_id,
user_id=call.identity.user,
queue_id=request.queue,
status_message="Starting pipeline",
status_reason="",

View File

@@ -73,10 +73,6 @@ def update_report(call: APICall, company_id: str, request: UpdateReportRequest):
task = _assert_report(
task_id=request.task, company_id=company_id, only_fields=("status",),
)
if task.status != TaskStatus.created:
raise errors.bad_request.InvalidTaskStatus(
expected=TaskStatus.created, status=task.status
)
partial_update_dict = {
field: value for field, value in call.data.items() if field in update_fields
@@ -84,14 +80,18 @@ def update_report(call: APICall, company_id: str, request: UpdateReportRequest):
if not partial_update_dict:
return UpdateResponse(updated=0)
allowed_for_published = set(partial_update_dict.keys()).issubset({"tags", "name"})
if task.status != TaskStatus.created and not allowed_for_published:
raise errors.bad_request.InvalidTaskStatus(
expected=TaskStatus.created, status=task.status
)
now = datetime.utcnow()
updated = task.update(
upsert=False,
**partial_update_dict,
last_change=now,
last_update=now,
last_changed_by=call.identity.user,
)
more_updates = {"last_change": now, "last_changed_by": call.identity.user}
if not allowed_for_published:
more_updates["last_update"] = now
updated = task.update(upsert=False, **partial_update_dict, **more_updates)
if not updated:
return UpdateResponse(updated=0)

View File

@@ -0,0 +1,50 @@
from typing import Tuple
from apiserver.tests.automated import TestService
class TestPipelines(TestService):
def test_start_pipeline(self):
queue = self.api.queues.get_default().id
task_name = "pipelines test"
project, task = self._temp_project_and_task(name=task_name)
args = [{"name": "hello", "value": "test"}]
res = self.api.pipelines.start_pipeline(task=task, queue=queue, args=args)
pipeline_task = res.pipeline
try:
self.assertTrue(res.enqueued)
pipeline = self.api.tasks.get_all_ex(id=[pipeline_task]).tasks[0]
self.assertTrue(pipeline.name.startswith(task_name))
self.assertEqual(pipeline.status, "queued")
self.assertEqual(pipeline.project.id, project)
self.assertEqual(
pipeline.hyperparams.Args,
{
a["name"]: {
"section": "Args",
"name": a["name"],
"value": a["value"],
}
for a in args
},
)
finally:
self.api.tasks.delete(task=pipeline_task, force=True)
def _temp_project_and_task(self, name) -> Tuple[str, str]:
project = self.create_temp(
"projects", name=name, description="test", delete_params=dict(force=True),
)
return (
project,
self.create_temp(
"tasks",
name=name,
type="testing",
input=dict(view=dict()),
project=project,
system_tags=["pipeline"],
),
)

View File

@@ -58,6 +58,12 @@ class TestReports(TestService):
with self.api.raises(errors.bad_request.InvalidTaskStatus):
self.api.reports.update(task=task_id, comment=comment)
# update on tags or rename can be done for published report too
self.api.reports.update(task=task_id, name="new name", tags=["test"])
task = self.api.tasks.get_all_ex(id=[task_id]).tasks[0]
self.assertEqual(task.tags, ["test"])
self.assertEqual(task.name, "new name")
# move under another project autodeletes the empty project
new_project_name = "Reports Test"
self._delete_project(new_project_name)

View File

@@ -1 +1 @@
__version__ = "1.9.0"
__version__ = "1.9.1"