From f20bf65b37a2552524da2b78803c0105e565ffe2 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Mon, 13 Dec 2021 12:25:25 +0100 Subject: [PATCH] Add: test for error view Fix: removed print statement from debugging Add: Basic documentation --- doc/core-concepts.rst | 17 +++++++++- doc/reference.rst | 39 +++++++++++++++++++++++ src/automations/tests/test_automations.py | 8 ++++- src/automations/urls.py | 2 +- src/automations/views.py | 3 +- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/doc/core-concepts.rst b/doc/core-concepts.rst index 2f73d58..553ccef 100644 --- a/doc/core-concepts.rst +++ b/doc/core-concepts.rst @@ -99,4 +99,19 @@ Also, an automation may advance, e.g., after an processing form has been filled Django Automations is not a task scheduler for background worker processes. It is a framework that defines what tasks have to be done at what time under what conditions. It works, however, well with background worker processes. -Currently, there is no native integration with, say, Celery. However, this might be an extension which would be welcomed. \ No newline at end of file +Currently, there is no native integration with, say, Celery. However, this might be an extension which would be welcomed. + +Debugging automations +********************* + +Django-automations offers some help in debugging automations. Since +they run invisible to the user and developer errors caught and tracebacks +stored for debugging purposes. + +To make them available, it is necessary to give the respective users the +permissions ``automations.change_automationmodel`` **and** ``automations.change_automationtaskmodel``. + +.. note:: + + Automations are not debugged by actually changing instances of these models. Automations need to + be changed on the source code. \ No newline at end of file diff --git a/doc/reference.rst b/doc/reference.rst index 95045dd..b341834 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -713,6 +713,8 @@ Execution errors are stored as task results. If not caught by ``.OnError`` an er Views ***** +For convenience django-automations includes a set of views that allow to manage required interactions with automations. + TaskView ======== @@ -722,6 +724,43 @@ TaskListView DashboardView ============= +.. warning:: + This view only is available to users with the permissions ``automations.view_automationmodel`` **and** + ``automations.view_automationtaskmodel`` set. + +AutomationErrorsView +==================== + +.. warning:: + This view only is available to users with the permissions ``automations.change_automationmodel`` **and** + ``automations.change_automationtaskmodel`` set. + +This view gives an overview on automation instances which failed with an error. Instances are grouped by +automation. Each instance contains a reference to the instance's ``AutomationHistoryView`` where each +individual step from the automation instance's start to the step where the error occurred is listed. + + +AutomationHistoryView +===================== + +.. warning:: + This view only is available to users with the permissions ``automations.change_automationmodel`` **and** + ``automations.change_automationtaskmodel`` set. + +This view lists all steps as they were processed for a given automation. This is meant to support automation debugging. +Note that loops are unrolled (since each step within a loop is recorded). Splits are shown as they are processed +in parallel. If an automation instance stopped due to an error a link to the ``AutomationTracebackView`` is added. + +AutomationTracebackView +======================= + +.. warning:: + This view only is available to users with the permissions ``automations.change_automationmodel`` **and** + ``automations.change_automationtaskmodel`` set. + +This view shows the Django-style traceback if an automation task fails with an error. + + Templates ********* diff --git a/src/automations/tests/test_automations.py b/src/automations/tests/test_automations.py index c8ff42e..6a6a5a2 100644 --- a/src/automations/tests/test_automations.py +++ b/src/automations/tests/test_automations.py @@ -284,7 +284,7 @@ def setUp(self): self.admin.save() self.assertEqual(self.admin.is_superuser, True) login = self.client.login(username="admin", password="Even More Secr3t") - self.failUnless(login, "Could not login") + self.assertTrue(login, "Could not login") def test_history_test(self): atm = TestSplitJoin() @@ -308,6 +308,12 @@ def test_traceback_test(self): self.assertEqual(response.status_code, 200) self.assertIn("Darn, this is not good", response.content.decode("utf8")) + def test_error_view(self): + BogusAutomation1() + response = self.client.get("/errors") + self.assertEqual(response.status_code, 200) + self.assertIn("BogusAutomation1", response.content.decode("utf8")) + test_signal = django.dispatch.Signal() diff --git a/src/automations/urls.py b/src/automations/urls.py index c12babb..6dfbc29 100644 --- a/src/automations/urls.py +++ b/src/automations/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ path("", views.TaskListView.as_view(), name="task_list"), path("", views.TaskView.as_view(), name="task"), - path("errors", views.AutomationErrorView.as_view(), name="error_report"), + path("errors", views.AutomationErrorsView.as_view(), name="error_report"), path("dashboard", views.TaskDashboardView.as_view(), name="dashboard"), path( "dashboard/", diff --git a/src/automations/views.py b/src/automations/views.py index 82dea9a..dce287a 100644 --- a/src/automations/views.py +++ b/src/automations/views.py @@ -224,7 +224,7 @@ def get_context_data(self, **kwargs): return dict() -class AutomationErrorView(PermissionRequiredMixin, TemplateView): +class AutomationErrorsView(PermissionRequiredMixin, TemplateView): permission_required = ( "automations.change_automationmodel", "automations.change_automationtaskmodel", @@ -233,7 +233,6 @@ class AutomationErrorView(PermissionRequiredMixin, TemplateView): def get_context_data(self, **kwargs): tasks = models.AutomationTaskModel.objects.filter(message__contains="Error") - print(tasks) automations = [] done = [] for task in tasks: