From 13900bc6033ad12866fdd14be9b3385fe97c1144 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 1 Jul 2020 22:27:58 +0200 Subject: [PATCH] lib: cleanup unused widgets --- passbook/core/tests/tests_tasks.py | 25 +++++++++++++++++++++ passbook/lib/widgets.py | 36 ------------------------------ 2 files changed, 25 insertions(+), 36 deletions(-) create mode 100644 passbook/core/tests/tests_tasks.py delete mode 100644 passbook/lib/widgets.py diff --git a/passbook/core/tests/tests_tasks.py b/passbook/core/tests/tests_tasks.py new file mode 100644 index 000000000..a6e9590e9 --- /dev/null +++ b/passbook/core/tests/tests_tasks.py @@ -0,0 +1,25 @@ +"""passbook user view tests""" +from guardian.shortcuts import get_anonymous_user +from django.test import TestCase +from django.utils.timezone import now + +from passbook.core.tasks import clean_tokens +from passbook.core.models import Token + + +class TestTasks(TestCase): + """Test Tasks""" + + def test_token_cleanup(self): + """Test Token cleanup task""" + Token.objects.create( + expires=now(), + user=get_anonymous_user() + ) + self.assertEqual( + Token.objects.all().count(), 1 + ) + clean_tokens() + self.assertEqual( + Token.objects.all().count(), 0 + ) diff --git a/passbook/lib/widgets.py b/passbook/lib/widgets.py deleted file mode 100644 index 5012a1ff7..000000000 --- a/passbook/lib/widgets.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Dynamic array widget""" -from django import forms - - -class DynamicArrayWidget(forms.TextInput): - """Dynamic array widget""" - - template_name = "lib/arrayfield.html" - - def get_context(self, name, value, attrs): - value = value or [""] - context = super().get_context(name, value, attrs) - final_attrs = context["widget"]["attrs"] - id_ = context["widget"]["attrs"].get("id") - - subwidgets = [] - for index, item in enumerate(context["widget"]["value"]): - widget_attrs = final_attrs.copy() - if id_: - widget_attrs["id"] = "{id_}_{index}".format(id_=id_, index=index) - widget = forms.TextInput() - widget.is_required = self.is_required - subwidgets.append(widget.get_context(name, item, widget_attrs)["widget"]) - - context["widget"]["subwidgets"] = subwidgets - return context - - def value_from_datadict(self, data, files, name): - try: - getter = data.getlist - return [value for value in getter(name) if value] - except AttributeError: - return data.get(name) - - def format_value(self, value): - return value or []