Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
pytz
5 changes: 4 additions & 1 deletion src/solrq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions tests/test_squery.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down