Skip to content

Commit

Permalink
fix(toolchain): reset toolchain if exipres_at is badly formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Kl0ven committed Nov 3, 2022
1 parent a0a14ae commit 665b986
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
34 changes: 33 additions & 1 deletion admin_action_tools/tests/unit/test_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestToolchain(AdminConfirmTestCase):
def test_form_action(self):
def test_toolchain_expired(self):
request = self.factory.request()
name = f"toolchain{request.path}"
request.session[name] = {
Expand All @@ -20,3 +20,35 @@ def test_form_action(self):

# test data is save
self.assertEqual(request.session[name]["history"], [])

def test_toolchain_wrong_date(self):
request = self.factory.request()
name = f"toolchain{request.path}"
request.session[name] = {
"expire_at": "ggg",
"history": ["tool1"],
"tool1": {"data": {"field1": True}, "metadata": {}},
}
toolchain = ToolChain(request)

# test toolchain reset
self.assertEqual(toolchain.get_history(), [])

# test data is save
self.assertEqual(request.session[name]["history"], [])

def test_toolchain_wrong_date_type(self):
request = self.factory.request()
name = f"toolchain{request.path}"
request.session[name] = {
"expire_at": 3,
"history": ["tool1"],
"tool1": {"data": {"field1": True}, "metadata": {}},
}
toolchain = ToolChain(request)

# test toolchain reset
self.assertEqual(toolchain.get_history(), [])

# test data is save
self.assertEqual(request.session[name]["history"], [])
6 changes: 5 additions & 1 deletion admin_action_tools/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def _get_data(self):
expire_at = old_data.get("expire_at")

if expire_at:
expire_at = datetime.fromisoformat(expire_at)
try:
expire_at = datetime.fromisoformat(expire_at)
except Exception: # pylint: disable=broad-except
expire_at = None
old_data = None

if not old_data:
self.data = {"expire_at": self._get_expiration()}
Expand Down

0 comments on commit 665b986

Please sign in to comment.