Skip to content

Commit

Permalink
Test timezone-aware datetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
honzakral committed Feb 26, 2015
1 parent c96974d commit d83d49e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
tests_require = [
"mock",
"pytest",
"pytest-cov"
"pytest-cov",
"pytz"
]

# use external unittest for 2.6
Expand Down
2 changes: 1 addition & 1 deletion test_elasticsearch_dsl/test_integration/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def create_git_index(client, index):
# repository
{'_type': 'repos', '_id': 'elasticsearch-dsl-py', '_source': {'organization': 'elasticsearch', 'created_at': '2014-03-03', 'owner': {'name': 'elasticsearch'}}, '_index': 'git'},
# documents
{'_type': 'commits', '_parent': 'elasticsearch-dsl-py', '_id': '3ca6e1e73a071a705b4babd2f581c91a2a3e5037', '_source': {'files': ['elasticsearch_dsl/aggs.py', 'elasticsearch_dsl/search.py', 'test_elasticsearch_dsl/test_aggs.py', 'test_elasticsearch_dsl/test_search.py'], 'committer': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'stats': {'deletions': 7, 'insertions': 23, 'lines': 30, 'files': 4}, 'description': "Make sure buckets aren't modified in-place", 'author': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'parent_shas': ['eb3e543323f189fd7b698e66295427204fff5755'], 'committed_date': '2014-05-02T13:47:19', 'authored_date': '2014-05-02T13:47:19'}, '_index': 'git'},
{'_type': 'commits', '_parent': 'elasticsearch-dsl-py', '_id': '3ca6e1e73a071a705b4babd2f581c91a2a3e5037', '_source': {'files': ['elasticsearch_dsl/aggs.py', 'elasticsearch_dsl/search.py', 'test_elasticsearch_dsl/test_aggs.py', 'test_elasticsearch_dsl/test_search.py'], 'committer': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'stats': {'deletions': 7, 'insertions': 23, 'lines': 30, 'files': 4}, 'description': "Make sure buckets aren't modified in-place", 'author': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'parent_shas': ['eb3e543323f189fd7b698e66295427204fff5755'], 'committed_date': '2014-05-02T13:47:19', 'authored_date': '2014-05-02T13:47:19+02:00'}, '_index': 'git'},
{'_type': 'commits', '_parent': 'elasticsearch-dsl-py', '_id': 'eb3e543323f189fd7b698e66295427204fff5755', '_source': {'files': ['elasticsearch_dsl/search.py'], 'committer': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'stats': {'deletions': 0, 'insertions': 18, 'lines': 18, 'files': 1}, 'description': 'Add communication with ES server', 'author': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'parent_shas': ['dd15b6ba17dd9ba16363a51f85b31f66f1fb1157'], 'committed_date': '2014-05-01T13:32:14', 'authored_date': '2014-05-01T13:32:14'}, '_index': 'git'},
{'_type': 'commits', '_parent': 'elasticsearch-dsl-py', '_id': 'dd15b6ba17dd9ba16363a51f85b31f66f1fb1157', '_source': {'files': ['elasticsearch_dsl/utils.py', 'test_elasticsearch_dsl/test_result.py', 'elasticsearch_dsl/result.py'], 'committer': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'stats': {'deletions': 18, 'insertions': 44, 'lines': 62, 'files': 3}, 'description': 'Minor cleanup and adding helpers for interactive python', 'author': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'parent_shas': ['ed19caf25abd25300e707fadf3f81b05c5673446'], 'committed_date': '2014-05-01T13:30:44', 'authored_date': '2014-05-01T13:30:44'}, '_index': 'git'},
{'_type': 'commits', '_parent': 'elasticsearch-dsl-py', '_id': 'ed19caf25abd25300e707fadf3f81b05c5673446', '_source': {'files': ['elasticsearch_dsl/aggs.py', 'elasticsearch_dsl/search.py', 'test_elasticsearch_dsl/test_search.py'], 'committer': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'stats': {'deletions': 0, 'insertions': 28, 'lines': 28, 'files': 3}, 'description': 'Make sure aggs do copy-on-write', 'author': {'name': 'Honza Kr\xe1l', 'email': 'honza.kral@gmail.com'}, 'parent_shas': ['583e52c71e9a72c1b291ec5843683d8fa8f1ce2d'], 'committed_date': '2014-04-27T16:28:09', 'authored_date': '2014-04-27T16:28:09'}, '_index': 'git'},
Expand Down
18 changes: 17 additions & 1 deletion test_elasticsearch_dsl/test_integration/test_document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from pytz import timezone

from elasticsearch_dsl import DocType, Date, String, construct_field
from elasticsearch_dsl import DocType, Date, String, construct_field, Mapping

user_field = construct_field('object')
user_field.property('name', 'string', fields={'raw': construct_field('string', index='not_analyzed')})
Expand All @@ -15,6 +16,15 @@ class Meta:
index = 'git'
doc_type = 'repos'

class Commit(DocType):
committed_date = Date()
authored_date = Date()

class Meta:
index = 'git'
mapping = Mapping('commits')
mapping.meta('_parent', type='repos')

def test_init(write_client):
Repository.init(index='test-git')

Expand All @@ -27,6 +37,12 @@ def test_get(data_client):
assert elasticsearch_repo.owner.name == 'elasticsearch'
assert datetime(2014, 3, 3) == elasticsearch_repo.created_at

def test_get_with_tz_date(data_client):
first_commit = Commit.get(id='3ca6e1e73a071a705b4babd2f581c91a2a3e5037', parent='elasticsearch-dsl-py')

tzinfo = timezone('Europe/Prague')
assert tzinfo.localize(datetime(2014, 5, 2, 13, 47, 19)) == first_commit.authored_date

def test_save_updates_existing_doc(data_client):
elasticsearch_repo = Repository.get('elasticsearch-dsl-py')

Expand Down

0 comments on commit d83d49e

Please sign in to comment.