Skip to content

Commit

Permalink
Add pytest for async REST API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed May 8, 2020
1 parent d0ad40d commit 9fe4639
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 17 deletions.
3 changes: 3 additions & 0 deletions elasticsearch/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ async def rank_eval(self, body, index=None, params=None, headers=None):

@query_params(
"max_docs",
"prefer_v2_templates",
"refresh",
"requests_per_second",
"scroll",
Expand All @@ -1316,6 +1317,8 @@ async def reindex(self, body, params=None, headers=None):
prototype for the index request.
:arg max_docs: Maximum number of documents to process (default:
all documents)
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during index creation
:arg refresh: Should the affected indexes be refreshed?
:arg requests_per_second: The throttle to set on this request in
sub-requests per second. -1 means no throttle.
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/_async/client/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ async def pending_tasks(self, params=None, headers=None):
"GET", "/_cat/pending_tasks", params=params, headers=headers
)

@query_params("format", "h", "help", "local", "master_timeout", "s", "size", "v")
@query_params("format", "h", "help", "local", "master_timeout", "s", "time", "v")
async def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
"""
Returns cluster-wide thread pool statistics per node. By default the active,
Expand All @@ -345,8 +345,8 @@ async def thread_pool(self, thread_pool_patterns=None, params=None, headers=None
to master node
:arg s: Comma-separated list of column names or column aliases
to sort by
:arg size: The multiplier in which to display values Valid
choices: , k, m, g, t, p
:arg time: The unit in which to display time values Valid
choices: d, h, m, s, ms, micros, nanos
:arg v: Verbose mode. Display column headers
"""
return await self.transport.perform_request(
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/_async/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def stats(self, node_id=None, params=None, headers=None):
"GET",
"/_cluster/stats"
if node_id in SKIP_IN_PATH
else _make_path("_cluster/stats/nodes", node_id),
else _make_path("_cluster", "stats", "nodes", node_id),
params=params,
headers=headers,
)
Expand Down
14 changes: 9 additions & 5 deletions elasticsearch/_async/client/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,20 +1301,19 @@ async def get_index_template(self, name=None, params=None, headers=None):
"GET", _make_path("_index_template", name), params=params, headers=headers
)

@query_params("create", "master_timeout", "order")
@query_params("cause", "create", "master_timeout")
async def put_index_template(self, name, body, params=None, headers=None):
"""
Creates or updates an index template.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
:arg name: The name of the template
:arg body: The template definition
:arg cause: User defined reason for creating/updating the index
template
:arg create: Whether the index template should only be added if
new or can also replace an existing one
:arg master_timeout: Specify timeout for connection to master
:arg order: The order for this template when merging multiple
matching ones (higher numbers are merged later, overriding the lower
numbers)
"""
for param in (name, body):
if param in SKIP_IN_PATH:
Expand Down Expand Up @@ -1349,7 +1348,7 @@ async def exists_index_template(self, name, params=None, headers=None):
"HEAD", _make_path("_index_template", name), params=params, headers=headers
)

@query_params("master_timeout")
@query_params("cause", "create", "master_timeout")
async def simulate_index_template(self, name, body=None, params=None, headers=None):
"""
Simulate matching the given index name against the index templates in the
Expand All @@ -1360,6 +1359,11 @@ async def simulate_index_template(self, name, body=None, params=None, headers=No
name)
:arg body: New index template definition, which will be included
in the simulation, as if it already exists in the system
:arg cause: User defined reason for dry-run creating the new
template for simulation purposes
:arg create: Whether the index template we optionally defined in
the body should only be dry-run added if new or can also replace an
existing one
:arg master_timeout: Specify timeout for connection to master
"""
if name in SKIP_IN_PATH:
Expand Down
3 changes: 3 additions & 0 deletions elasticsearch/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,7 @@ def rank_eval(self, body, index=None, params=None, headers=None):

@query_params(
"max_docs",
"prefer_v2_templates",
"refresh",
"requests_per_second",
"scroll",
Expand All @@ -1316,6 +1317,8 @@ def reindex(self, body, params=None, headers=None):
prototype for the index request.
:arg max_docs: Maximum number of documents to process (default:
all documents)
:arg prefer_v2_templates: favor V2 templates instead of V1
templates during index creation
:arg refresh: Should the affected indexes be refreshed?
:arg requests_per_second: The throttle to set on this request in
sub-requests per second. -1 means no throttle.
Expand Down
6 changes: 3 additions & 3 deletions elasticsearch/client/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def pending_tasks(self, params=None, headers=None):
"GET", "/_cat/pending_tasks", params=params, headers=headers
)

@query_params("format", "h", "help", "local", "master_timeout", "s", "size", "v")
@query_params("format", "h", "help", "local", "master_timeout", "s", "time", "v")
def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
"""
Returns cluster-wide thread pool statistics per node. By default the active,
Expand All @@ -345,8 +345,8 @@ def thread_pool(self, thread_pool_patterns=None, params=None, headers=None):
to master node
:arg s: Comma-separated list of column names or column aliases
to sort by
:arg size: The multiplier in which to display values Valid
choices: , k, m, g, t, p
:arg time: The unit in which to display time values Valid
choices: d, h, m, s, ms, micros, nanos
:arg v: Verbose mode. Display column headers
"""
return self.transport.perform_request(
Expand Down
14 changes: 9 additions & 5 deletions elasticsearch/client/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,20 +1299,19 @@ def get_index_template(self, name=None, params=None, headers=None):
"GET", _make_path("_index_template", name), params=params, headers=headers
)

@query_params("create", "master_timeout", "order")
@query_params("cause", "create", "master_timeout")
def put_index_template(self, name, body, params=None, headers=None):
"""
Creates or updates an index template.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
:arg name: The name of the template
:arg body: The template definition
:arg cause: User defined reason for creating/updating the index
template
:arg create: Whether the index template should only be added if
new or can also replace an existing one
:arg master_timeout: Specify timeout for connection to master
:arg order: The order for this template when merging multiple
matching ones (higher numbers are merged later, overriding the lower
numbers)
"""
for param in (name, body):
if param in SKIP_IN_PATH:
Expand Down Expand Up @@ -1347,7 +1346,7 @@ def exists_index_template(self, name, params=None, headers=None):
"HEAD", _make_path("_index_template", name), params=params, headers=headers
)

@query_params("master_timeout")
@query_params("cause", "create", "master_timeout")
def simulate_index_template(self, name, body=None, params=None, headers=None):
"""
Simulate matching the given index name against the index templates in the
Expand All @@ -1358,6 +1357,11 @@ def simulate_index_template(self, name, body=None, params=None, headers=None):
name)
:arg body: New index template definition, which will be included
in the simulation, as if it already exists in the system
:arg cause: User defined reason for dry-run creating the new
template for simulation purposes
:arg create: Whether the index template we optionally defined in
the body should only be dry-run added if new or can also replace an
existing one
:arg master_timeout: Specify timeout for connection to master
"""
if name in SKIP_IN_PATH:
Expand Down
Loading

0 comments on commit 9fe4639

Please sign in to comment.