source: OpenWorkouts-current/ow/tests/views/test_renderers.py @ 5ec3a0b

currentfeature/docs
Last change on this file since 5ec3a0b was 5ec3a0b, checked in by borja <borja@…>, 5 years ago

Imported sources from the old python2-only repository:

  • Modified the code so it is python 3.6 compatible
  • Fixed deprecation warnings, pyramid 1.10.x supported now
  • Fixed deprecation warnings about some libraries, like pyramid-simpleform
  • Added pytest-pycodestyle and pytest-flakes for automatic checks on the source code files when running tests.
  • Added default pytest.ini setup to enforce some default parameters when running tests.
  • Cleaned up the code a bit, catched up with tests coverage.
  • Property mode set to 100644
File size: 1.7 KB
Line 
1
2from datetime import date, datetime, timezone
3
4import pytest
5from pyramid.testing import DummyRequest
6from pyramid_simpleform import Form
7
8from ow.views.renderers import OWFormRenderer
9
10
11class 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
Note: See TracBrowser for help on using the repository browser.