[5ec3a0b] | 1 | |
---|
| 2 | from datetime import date, datetime, timezone |
---|
| 3 | |
---|
| 4 | import pytest |
---|
| 5 | from pyramid.testing import DummyRequest |
---|
| 6 | from pyramid_simpleform import Form |
---|
| 7 | |
---|
| 8 | from ow.views.renderers import OWFormRenderer |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | class TestOWFormRenderer(object): |
---|
| 12 | |
---|
| 13 | @pytest.fixture |
---|
| 14 | def req(self): |
---|
| 15 | request = DummyRequest() |
---|
| 16 | return request |
---|
| 17 | |
---|
| 18 | @pytest.fixture |
---|
| 19 | def form(self, req): |
---|
| 20 | form = Form(req) |
---|
| 21 | return form |
---|
| 22 | |
---|
| 23 | @pytest.fixture |
---|
| 24 | def renderer(self, form): |
---|
| 25 | renderer = OWFormRenderer(form) |
---|
| 26 | return renderer |
---|
| 27 | |
---|
| 28 | def test_date(self, renderer): |
---|
| 29 | html = renderer.date('current_date') |
---|
| 30 | match = u'<input id="current_date" name="current_date" type="text" />' |
---|
| 31 | assert html == match |
---|
| 32 | |
---|
| 33 | def test_date_with_value(self, renderer): |
---|
| 34 | html = renderer.date('current_date', value=date(2016, 3, 17)) |
---|
| 35 | match = u'<input id="current_date" name="current_date" type="text"' |
---|
| 36 | match += u' value="2016-03-17" />' |
---|
| 37 | assert html == match |
---|
| 38 | html = renderer.date( |
---|
| 39 | 'current_date', value=datetime(2016, 3, 17, tzinfo=timezone.utc)) |
---|
| 40 | match = u'<input id="current_date" name="current_date" type="text"' |
---|
| 41 | match += u' value="2016-03-17 00:00:00+00:00" />' |
---|
| 42 | assert html == match |
---|
| 43 | |
---|
| 44 | def test_date_with_format(self, renderer): |
---|
| 45 | html = renderer.date('current_date', value=date(2016, 3, 17), |
---|
| 46 | date_format='%d/%m/%Y') |
---|
| 47 | match = u'<input id="current_date" name="current_date" type="text"' |
---|
| 48 | match += u' value="17/03/2016" />' |
---|
| 49 | assert html == match |
---|
| 50 | html = renderer.date( |
---|
| 51 | 'current_date', value=datetime(2016, 3, 17, tzinfo=timezone.utc), |
---|
| 52 | date_format='%d/%m/%Y') |
---|
| 53 | assert html == match |
---|