Skip to content

Commit

Permalink
Make sure save() automatically tracks versions
Browse files Browse the repository at this point in the history
This is to demonstrate #139
  • Loading branch information
honzakral committed Apr 27, 2015
1 parent 334b5a5 commit 5da24f3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test_elasticsearch_dsl/test_integration/test_document.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from datetime import datetime
from pytz import timezone

from elasticsearch import ConflictError

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

from pytest import raises

user_field = construct_field('object')
user_field.field('name', 'string', fields={'raw': construct_field('string', index='not_analyzed')})

Expand Down Expand Up @@ -52,11 +56,22 @@ def test_save_updates_existing_doc(data_client):
elasticsearch_repo = Repository.get('elasticsearch-dsl-py')

elasticsearch_repo.new_field = 'testing'
v = elasticsearch_repo.meta.version
assert not elasticsearch_repo.save()

# assert version has been updated
assert elasticsearch_repo.meta.version == v + 1

new_repo = data_client.get(index='git', doc_type='repos', id='elasticsearch-dsl-py')
assert 'testing' == new_repo['_source']['new_field']

def test_save_automatially_uses_versions(data_client):
elasticsearch_repo = Repository.get('elasticsearch-dsl-py')
elasticsearch_repo.meta.version += 1

with raises(ConflictError):
elasticsearch_repo.save()

def test_can_save_to_different_index(write_client):
test_repo = Repository(description='testing', meta={'id': 42})
test_repo.meta.version_type = 'external'
Expand Down

0 comments on commit 5da24f3

Please sign in to comment.