Skip to content

Commit a262459

Browse files
committed
pass tests
1 parent 5d77519 commit a262459

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

elasticsearch_metrics/metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def check_index_template(cls, using=None):
164164
"""
165165
client = connections.get_connection(using or "default")
166166
try:
167-
template = client.indices.get_template(cls._template_name)
167+
template = client.indices.get_template(name=cls._template_name)
168168
except NotFoundError as client_error:
169169
template_name = cls._template_name
170170
metric_name = cls.__name__

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def _es_marker(request, client):
1919

2020
def teardown_es():
2121
client.indices.delete(index="*")
22-
client.indices.delete_template("*")
22+
client.indices.delete_template(name="*")
2323

2424
teardown_es()
2525
yield

tests/test_metrics.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
)
2828

2929

30+
# support elasticsearch-dsl 6 and 7
31+
def mappings_fortytwo(mapping):
32+
return mapping.get("doc", mapping)
33+
34+
3035
class PreprintView(metrics.Metric):
3136
provider_id = metrics.Keyword(index=True)
3237
user_id = metrics.Keyword(index=True)
@@ -95,9 +100,9 @@ def test_get_index_template_respects_index_settings(self):
95100

96101
def test_get_index_template_creates_template_with_mapping(self):
97102
template = PreprintView.get_index_template()
98-
mappings = template.to_dict()["mappings"]
99-
assert mappings["doc"]["_source"]["enabled"] is False
100-
properties = mappings["doc"]["properties"]
103+
mappings = mappings_fortytwo(template.to_dict()["mappings"])
104+
assert mappings["_source"]["enabled"] is False
105+
properties = mappings["properties"]
101106
assert "timestamp" in properties
102107
assert properties["timestamp"] == {"doc_values": True, "type": "date"}
103108
assert properties["provider_id"] == {"type": "keyword", "index": True}
@@ -108,10 +113,12 @@ def test_get_index_template_creates_template_with_mapping(self):
108113
def test_mappings_are_not_shared(self):
109114
template1 = DummyMetric.get_index_template()
110115
template2 = DummyMetricWithExplicitTemplateName.get_index_template()
111-
assert "my_int" in template1.to_dict()["mappings"]["doc"]["properties"]
112-
assert "my_keyword" not in template1.to_dict()["mappings"]["doc"]["properties"]
113-
assert "my_int" not in template2.to_dict()["mappings"]["doc"]["properties"]
114-
assert "my_keyword" in template2.to_dict()["mappings"]["doc"]["properties"]
116+
mappings1 = mappings_fortytwo(template1.to_dict()["mappings"])
117+
mappings2 = mappings_fortytwo(template2.to_dict()["mappings"])
118+
assert "my_int" in mappings1["properties"]
119+
assert "my_keyword" not in mappings1["properties"]
120+
assert "my_int" not in mappings2["properties"]
121+
assert "my_keyword" in mappings2["properties"]
115122

116123
def test_declaring_metric_with_no_app_label_or_template_name_errors(self):
117124
with pytest.raises(RuntimeError):
@@ -189,8 +196,8 @@ class Meta:
189196
template = MyMetric.get_index_template()
190197

191198
template_dict = template.to_dict()
192-
doc = template_dict["mappings"]["doc"]
193-
assert doc["_source"]["enabled"] is True
199+
mappings = mappings_fortytwo(template_dict["mappings"])
200+
assert mappings["_source"]["enabled"] is True
194201

195202

196203
class TestRecord:
@@ -264,7 +271,7 @@ def test_init(self, client):
264271
PreprintView.init()
265272
name = PreprintView.get_index_name()
266273
mapping = client.indices.get_mapping(index=name)
267-
properties = mapping[name]["mappings"]["doc"]["properties"]
274+
properties = mappings_fortytwo(mapping[name]["mappings"])["properties"]
268275
assert properties["timestamp"] == {"type": "date"}
269276
assert properties["provider_id"] == {"type": "keyword"}
270277
assert properties["user_id"] == {"type": "keyword"}

0 commit comments

Comments
 (0)