Skip to content

Commit

Permalink
Add: test for error view
Browse files Browse the repository at this point in the history
Fix:		removed print statement from debugging
Add:		Basic documentation
  • Loading branch information
fsbraun committed Dec 13, 2021
1 parent 03489fe commit f20bf65
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 5 deletions.
17 changes: 16 additions & 1 deletion doc/core-concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
39 changes: 39 additions & 0 deletions doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
========

Expand All @@ -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
*********

Expand Down
8 changes: 7 additions & 1 deletion src/automations/tests/test_automations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion src/automations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
urlpatterns = [
path("", views.TaskListView.as_view(), name="task_list"),
path("<int:task_id>", 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/<int:automation_id>",
Expand Down
3 changes: 1 addition & 2 deletions src/automations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:
Expand Down

0 comments on commit f20bf65

Please sign in to comment.