mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-25 03:32:55 +03:00
Added tests for LocalizedFieldWidget.get_context method
This commit is contained in:
parent
69cf0df166
commit
6522e38f18
24
tests/test_file_widget.py
Normal file
24
tests/test_file_widget.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from localized_fields.value import LocalizedFileValue
|
||||||
|
from localized_fields.widgets import LocalizedFileWidget
|
||||||
|
|
||||||
|
|
||||||
|
class LocalizedFileWidgetTestCase(TestCase):
|
||||||
|
"""Tests the workings of the :see:LocalizedFiledWidget class."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_get_context():
|
||||||
|
"""Tests whether the :see:get_context correctly
|
||||||
|
handles 'required' attribute, separately for each subwidget."""
|
||||||
|
|
||||||
|
widget = LocalizedFileWidget()
|
||||||
|
widget.widgets[0].is_required = True
|
||||||
|
widget.widgets[1].is_required = True
|
||||||
|
widget.widgets[2].is_required = False
|
||||||
|
context = widget.get_context(name='test',
|
||||||
|
value=LocalizedFileValue(dict(en='test')),
|
||||||
|
attrs=dict(required=True))
|
||||||
|
assert 'required' not in context['widget']['subwidgets'][0]['attrs']
|
||||||
|
assert context['widget']['subwidgets'][1]['attrs']['required']
|
||||||
|
assert 'required' not in context['widget']['subwidgets'][2]['attrs']
|
@ -42,3 +42,16 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
|||||||
|
|
||||||
for _, value in zip(settings.LANGUAGES, decompressed_values):
|
for _, value in zip(settings.LANGUAGES, decompressed_values):
|
||||||
assert not value
|
assert not value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def test_get_context():
|
||||||
|
"""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']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user