diff --git a/requirements-tests.txt b/requirements-tests.txt index e079f8a..9299da7 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1 +1,2 @@ pytest +pytz diff --git a/src/solrq/__init__.py b/src/solrq/__init__.py index 140e76b..e4b710e 100644 --- a/src/solrq/__init__.py +++ b/src/solrq/__init__.py @@ -65,7 +65,10 @@ def __init__(self, raw, safe=False): if isinstance(raw, datetime) and not safe: # Note: solr speaks ISO, wrap it with quotes to avoid further # escaping - self.raw = '"{dt}"'.format(dt=raw.isoformat()) + self.raw = '"{dt}Z"'.format( + dt=(raw.strftime('%Y-%m-%dT%H:%M:%S.%f') if raw.tzinfo + else raw.isoformat()) + ) # since we translated value we can safely mark it safe self.safe = True elif isinstance(raw, timedelta) and not safe: diff --git a/tests/test_squery.py b/tests/test_squery.py index 596f259..fba4c69 100644 --- a/tests/test_squery.py +++ b/tests/test_squery.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest from datetime import datetime, timedelta +import pytz from solrq import ( Q, QOperator, Value, Range, Proximity, ANY, SET @@ -102,9 +103,18 @@ def test_value(): assert str(Value('"foo bar"', safe=True), ) == '"foo bar"' -def test_value_datetimes(): +def test_value_nonlocalized_datetimes(): dt = datetime.now() - assert str(Value(dt)) == '"{dt}"'.format(dt=dt.isoformat()) + assert str(Value(dt)) == '"{dt}Z"'.format(dt=dt.isoformat()) + + +def test_value_localized_datetimes(): + dt = datetime.now() + dt = dt.replace(tzinfo=pytz.timezone('Europe/Warsaw')) + + assert str(Value(dt)) == '"{dt}Z"'.format( + dt=dt.strftime('%Y-%m-%dT%H:%M:%S.%f') + ) def test_value_timedelta(): diff --git a/tox.ini b/tox.ini index 0be2a0e..13609df 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,6 @@ setenv = VIRTUAL_ENV = {envdir} # but they are not run later in coverage because they are only illustratory commands = py.test --doctest-modules --ignore=setup.py --ignore docs {posargs} sitepackages = False -downloadcache = {toxworkdir}/_download [testenv:pep8] deps = flake8==2.0