forked from viewflow/django-material
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_widget_dateinput.py
130 lines (98 loc) · 4.63 KB
/
test_widget_dateinput.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import json
from django import forms
from django.test.utils import override_settings
from django_webtest import WebTest
from . import build_test_urls
class DateInputForm(forms.Form):
test_field = forms.DateField(
widget=forms.DateInput(attrs={'data-test': 'Test Attr'}))
data_field = forms.BooleanField(required=False, widget=forms.HiddenInput, initial=True,
help_text='To produce non empty POST for empty test_field')
@override_settings(ROOT_URLCONF=__name__)
class Test(WebTest):
default_form = DateInputForm
def test_default_usecase(self):
page = self.app.get(self.test_default_usecase.url)
body = page.pyquery('#id_test_field_container').outerHtml()
self.assertIn('id="id_test_field_container"', body)
self.assertIn('id="id_test_field"', body)
self.assertIn('data-test="Test Attr"', body)
form = page.form
self.assertIn('test_field', form.fields)
form['test_field'] = '2012-01-01'
response = json.loads(form.submit().body.decode('utf-8'))
self.assertIn('cleaned_data', response)
self.assertIn('test_field', response['cleaned_data'])
self.assertEqual('2012-01-01', response['cleaned_data']['test_field'])
def test_invalid_value(self):
form = self.app.get(self.test_invalid_value.url).form
response = form.submit()
form['data_field'] = 1
response = form.submit()
self.assertIn('This field is required.', response.body.decode('utf-8'))
def test_part_group_class(self):
page = self.app.get(self.test_part_group_class.url)
self.assertIn('class="yellow required checkbox-field col s12"', page.body.decode('utf-8'))
test_part_group_class.template = '''
{% form %}
{% attr form.test_field 'group' class override %}yellow required checkbox-field col s12{% endattr %}
{% endform %}
'''
def test_part_add_group_class(self):
page = self.app.get(self.test_part_add_group_class.url)
self.assertIn('class="input-field col s12 required deep-purple lighten-5"',
page.pyquery('#id_test_field_container').outerHtml())
test_part_add_group_class.template = '''
{% form %}
{% attr form.test_field 'group' class append %}deep-purple lighten-5{% endattr %}
{% endform %}
'''
def test_part_prefix(self):
response = self.app.get(self.test_part_prefix.url)
self.assertIn('<i class="mdi-communication-email prefix"></i>', response.body.decode('utf-8'))
test_part_prefix.template = '''
{% form %}
{% part form.test_field prefix %}<i class="mdi-communication-email prefix"></i>{% endpart %}
{% endform %}
'''
def test_part_add_control_class(self):
response = self.app.get(self.test_part_add_control_class.url)
self.assertIn('class="orange"', response.body.decode('utf-8'))
test_part_add_control_class.template = '''
{% form %}
{% attr form.test_field 'widget' class append %}orange{% endattr %}
{% endform %}
'''
def test_part_label(self):
response = self.app.get(self.test_part_label.url)
self.assertIn('<label for="id_test_field">My label</label>', response.body.decode('utf-8'))
test_part_label.template = '''
{% form %}
{% part form.test_field label %}<label for="id_test_field">My label</label>{% endpart %}
{% endform %}
'''
def test_part_add_label_class(self):
response = self.app.get(self.test_part_add_label_class.url)
self.assertIn('class="green-text"', response.body.decode('utf-8'))
test_part_add_label_class.template = '''
{% form %}
{% attr form.test_field 'label' class append %}green-text{% endattr %}
{% endform %}
'''
def test_part_help_text(self):
response = self.app.get(self.test_part_help_text.url)
self.assertIn('<div class="help-block">My help</div>', response.body.decode('utf-8'))
test_part_help_text.template = '''
{% form %}
{% part form.test_field help_text %}<div class="help-block">My help</div>{% endpart %}
{% endform %}
'''
def test_part_errors(self):
response = self.app.get(self.test_part_errors.url)
self.assertIn('<div class="errors"><small class="error">My Error</small></div>', response.body.decode('utf-8'))
test_part_errors.template = '''
{% form %}
{% part form.test_field errors%}<div class="errors"><small class="error">My Error</small></div>{% endpart %}
{% endform %}
'''
urlpatterns = build_test_urls(Test)