Skip to content

Commit

Permalink
Fix: Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 17, 2022
1 parent 8705f36 commit d582988
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/automations/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def __init__(
**kwargs,
):
super().__init__(**kwargs)
self._db_defaults = dict(
self._model_defaults = dict(
locked=-1, requires_interaction=True
) # Start w/o lock, but interaction needed
self._form = form
Expand All @@ -594,6 +594,7 @@ def execute(self, task: models.AutomationTaskModel):
)
task.interaction_user = self.get_user()
task.interaction_group = self.get_group()

if task.requires_interaction: # Not yet validated -> pause
return self.release_lock(task)
return task # Continue with validated form
Expand Down
5 changes: 3 additions & 2 deletions src/automations/tests/test_automations.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,16 @@ def setUp(self):

def test_form(self):
atm = FormTest(autorun=False)
tasks = atm._db.automationtaskmodel_set.filter(finished=None)
self.assertEqual(len(tasks), 0)
atm.form._user = dict(id=self.user.id) # Fake User
atm.form2._user = dict(id=self.user.id) # Fake User
atm.run()

users = atm.form.get_users_with_permission()
self.assertEqual(len(users), 0)

tasks = atm._db.automationtaskmodel_set.filter(finished=None)
self.assertEqual(len(tasks), 1)
self.assertEqual(len(tasks), 1) # Form not validated

# Create an instance of a GET request.
request = self.factory.get(f"/{tasks[0].id}")
Expand Down
2 changes: 1 addition & 1 deletion src/automations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def form_valid(self, form):
self.node.is_valid(self.task, self.request, form)
if self.node._run:
self.node._automation.run(self.task.previous, self.node)
if hasattr(self.node, "_success_url"):
if getattr(self.node, "_success_url", None):
return redirect(self.node._success_url)
elif "back" in self.request.GET:
return redirect(self.request.GET.get("back"))
Expand Down

0 comments on commit d582988

Please sign in to comment.