Mapping yaml tests

This commit is contained in:
Honza Kral
2013-06-16 16:04:00 +02:00
parent 1702dc3ed0
commit 6a9cc530c1
3 changed files with 83 additions and 0 deletions
+39
View File
@@ -175,6 +175,45 @@ class InidicesClient(NamespacedClient):
return False
return True
@query_params('ignore_conflicts', 'timeout')
def put_mapping(self, index, body, doc_type=None, params=None):
"""
The put mapping API allows to register specific mapping definition for a specific type.
http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping/
:arg index: A comma-separated list of index names; use `_all` to perform the operation on all indices
:arg doc_type: The name of the document type
:arg body: The mapping definition
:arg ignore_conflicts: Specify whether to ignore conflicts while updating the mapping (default: false)
:arg timeout: Explicit operation timeout
"""
status, data = self.transport.perform_request('PUT', _make_path(index, doc_type, '_mapping'), params=params, body=body)
return data
@query_params()
def get_mapping(self, index=None, doc_type=None, params=None):
"""
The get mapping API allows to retrieve mapping definition of index or index/type.
http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping/
:arg index: A comma-separated list of index names; use `_all` or empty string for all indices
:arg doc_type: A comma-separated list of document types
"""
status, data = self.transport.perform_request('GET', _make_path(index, doc_type, '_mapping'), params=params)
return data
@query_params()
def delete_mapping(self, index, doc_type, params=None):
"""
Allow to delete a mapping (type) along with its data.
http://www.elasticsearch.org/guide/reference/api/admin-indices-delete-mapping/
:arg index: A comma-separated list of index names; use `_all` for all indices
:arg doc_type: The name of the document type to delete
"""
status, data = self.transport.perform_request('DELETE', _make_path(index, doc_type, '_mapping'), params=params)
return data
class Elasticsearch(object):
"""
@@ -10,6 +10,13 @@ from unittest import TestCase, SkipTest
from elasticsearch import Elasticsearch
# some params had to be changed in python, keep track of them so we can rename
# those in the tests accordingly
PARAMS_RENAMES = {
'type': 'doc_type',
'from': 'offset',
}
class InvalidActionType(SkipTest):
pass
@@ -39,6 +46,12 @@ class YamlTestCase(TestCase):
self.assertTrue(hasattr(api, m))
api = getattr(api, m)
# some parameters had to be renamed to not clash with python builtins,
# compensate
for k in PARAMS_RENAMES:
if k in args:
args[PARAMS_RENAMES[k]] = args.pop(k)
self.last_response = api(**args)
def run_length(self, action):
@@ -0,0 +1,31 @@
---
"Mapping setup":
- do:
indices.create:
index: test
- do:
indices.put_mapping:
index: test
type: test-type
body:
test-type:
properties:
text:
type: string
---
"Test get mapping retrieves existing mapping":
- do:
indices.get_mapping:
index: test
type: test-type
- is: { test-type.properties.text.type: string }
---
"Test delete mapping removes mapping":
- do:
indices.delete_mapping:
index: test
type: test-type
- do:
indices.get_mapping:
index: test
- length: { test: 0 }