mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-12-14 15:52:25 +03:00
Re-format all files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
@@ -11,8 +12,7 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_widget_creation():
|
||||
"""Tests whether a widget is created for every
|
||||
language correctly."""
|
||||
"""Tests whether a widget is created for every language correctly."""
|
||||
|
||||
widget = LocalizedFieldWidget()
|
||||
assert len(widget.widgets) == len(settings.LANGUAGES)
|
||||
@@ -20,9 +20,8 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_decompress():
|
||||
"""Tests whether a :see:LocalizedValue instance
|
||||
can correctly be "decompressed" over the available
|
||||
widgets."""
|
||||
"""Tests whether a :see:LocalizedValue instance can correctly be
|
||||
"decompressed" over the available widgets."""
|
||||
|
||||
localized_value = LocalizedValue()
|
||||
for lang_code, lang_name in settings.LANGUAGES:
|
||||
@@ -31,13 +30,15 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
widget = LocalizedFieldWidget()
|
||||
decompressed_values = widget.decompress(localized_value)
|
||||
|
||||
for (lang_code, _), value in zip(settings.LANGUAGES, decompressed_values):
|
||||
for (lang_code, _), value in zip(
|
||||
settings.LANGUAGES, decompressed_values
|
||||
):
|
||||
assert localized_value.get(lang_code) == value
|
||||
|
||||
@staticmethod
|
||||
def test_decompress_none():
|
||||
"""Tests whether the :see:LocalizedFieldWidget correctly
|
||||
handles :see:None."""
|
||||
"""Tests whether the :see:LocalizedFieldWidget correctly handles
|
||||
:see:None."""
|
||||
|
||||
widget = LocalizedFieldWidget()
|
||||
decompressed_values = widget.decompress(None)
|
||||
@@ -47,16 +48,17 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
|
||||
@staticmethod
|
||||
def test_get_context_required():
|
||||
"""Tests whether the :see:get_context correctly
|
||||
handles 'required' attribute, separately for each subwidget."""
|
||||
"""Tests whether the :see:get_context correctly handles 'required'
|
||||
attribute, separately for each subwidget."""
|
||||
|
||||
widget = LocalizedFieldWidget()
|
||||
widget.widgets[0].is_required = True
|
||||
widget.widgets[1].is_required = False
|
||||
context = widget.get_context(name='test', value=LocalizedValue(),
|
||||
attrs=dict(required=True))
|
||||
assert context['widget']['subwidgets'][0]['attrs']['required']
|
||||
assert 'required' not in context['widget']['subwidgets'][1]['attrs']
|
||||
context = widget.get_context(
|
||||
name="test", value=LocalizedValue(), attrs=dict(required=True)
|
||||
)
|
||||
assert context["widget"]["subwidgets"][0]["attrs"]["required"]
|
||||
assert "required" not in context["widget"]["subwidgets"][1]["attrs"]
|
||||
|
||||
@staticmethod
|
||||
def test_get_context_langs():
|
||||
@@ -64,20 +66,20 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
'lang_name' attribute for each subwidget."""
|
||||
|
||||
widget = LocalizedFieldWidget()
|
||||
context = widget.get_context(name='test', value=LocalizedValue(),
|
||||
attrs=dict())
|
||||
subwidgets_context = context['widget']['subwidgets']
|
||||
context = widget.get_context(
|
||||
name="test", value=LocalizedValue(), attrs=dict()
|
||||
)
|
||||
subwidgets_context = context["widget"]["subwidgets"]
|
||||
for widget, context in zip(widget.widgets, subwidgets_context):
|
||||
assert 'lang_code' in context
|
||||
assert 'lang_name' in context
|
||||
assert widget.lang_code == context['lang_code']
|
||||
assert widget.lang_name == context['lang_name']
|
||||
assert "lang_code" in context
|
||||
assert "lang_name" in context
|
||||
assert widget.lang_code == context["lang_code"]
|
||||
assert widget.lang_name == context["lang_name"]
|
||||
|
||||
@staticmethod
|
||||
def test_render():
|
||||
"""Tests whether the :see:LocalizedFieldWidget correctly
|
||||
render."""
|
||||
"""Tests whether the :see:LocalizedFieldWidget correctly render."""
|
||||
|
||||
widget = LocalizedFieldWidget()
|
||||
output = widget.render(name='title', value=None)
|
||||
assert bool(re.search('<label (.|\n|\t)*>\w+<\/label>', output))
|
||||
output = widget.render(name="title", value=None)
|
||||
assert bool(re.search("<label (.|\n|\t)*>\w+<\/label>", output))
|
||||
|
||||
Reference in New Issue
Block a user