Skip to content

FIXME: Move format methods from Layout to utils #1835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/onegov/core/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import transaction
import yaml

from tests.onegov.org.conftest import create_org_app
from tests.shared import Client
from tests.shared.utils import create_app
from onegov.core.cli import command_group
Expand Down Expand Up @@ -174,3 +175,18 @@ def maildir_smtp_app(temporary_directory, maildir, smtp):
app.smtp = smtp

return app


@pytest.fixture(scope='function')
def org_app(request):
yield create_org_app(request, use_elasticsearch=False)
Comment on lines +180 to +182
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use OrgApp in core tests, the tests here are supposed to pass with a CoreRequest without any org specific features, so you should create a basic Framework instance here like e.g. maildir_app above.



@pytest.fixture(scope='function')
def core_request(org_app):
yield org_app.request_class(environ={
'PATH_INFO': '/',
'SERVER_NAME': '',
'SERVER_PORT': '',
'SERVER_PROTOCOL': 'https'
}, app=org_app)
18 changes: 12 additions & 6 deletions tests/onegov/core/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def test_batched():
]


def test_format_date():
def test_format_date(core_request):
layout = Layout(
model=object(),
request=Bunch(app=Bunch(version='1.0', sentry_dsn=None))
request=core_request
)

dt = replace_timezone(datetime(2015, 6, 17, 15, 0), 'Europe/Zurich')
Expand All @@ -41,10 +41,10 @@ def test_format_date():
assert layout.format_date(dt, 'day_long') == '17. Juni'


def test_format_number():
def test_format_number(core_request):
layout = Layout(
model=object(),
request=Bunch(app=Bunch(version='1.0', sentry_dsn=None))
request=core_request
)

layout.request.locale = 'de_CH'
Expand Down Expand Up @@ -78,10 +78,16 @@ def test_format_number():
assert layout.format_number(None) == ""


def test_relative_date():
def test_relative_date(core_request):
layout = Layout(
model=object(),
request=Bunch(locale='en', app=Bunch(version='1.0', sentry_dsn=None))
request=core_request
)

# default locale is de_CH
text = layout.format_date(utcnow() - timedelta(seconds=60 * 5), 'relative')
assert text == 'vor 5 Minuten'

core_request.locale = 'en_US'
text = layout.format_date(utcnow() - timedelta(seconds=60 * 5), 'relative')
assert text == '5 minutes ago'
Loading