import pytest
from elasticsearch import Elasticsearch
@pytest.fixture()
def es():
es = Elasticsearch()
return es
def test_zsh_history_index_exists(es):
assert es.indices.exists(index='zsh_history') is True
def test_zsh_history_mapping_exists(es):
zsh_history_mapping = es.indices.get_mapping(index='zsh_history')
assert 'zsh_history' in zsh_history_mapping
def test_zsh_history_mapping_has_correct_fields(es):
timestamp_mapping = es.indices.get_field_mapping(index='zsh_history', fields='@timestamp')
timestamp_type = timestamp_mapping['zsh_history']['mappings']['@timestamp']['mapping']['@timestamp']['type']
assert timestamp_type == 'date'
aW1wb3J0IHB5dGVzdApmcm9tIGVsYXN0aWNzZWFyY2ggaW1wb3J0IEVsYXN0aWNzZWFyY2gKCgpAcHl0ZXN0LmZpeHR1cmUoKQpkZWYgZXMoKToKICAgIGVzID0gRWxhc3RpY3NlYXJjaCgpCiAgICByZXR1cm4gZXMKCgpkZWYgdGVzdF96c2hfaGlzdG9yeV9pbmRleF9leGlzdHMoZXMpOgogICAgYXNzZXJ0IGVzLmluZGljZXMuZXhpc3RzKGluZGV4PSd6c2hfaGlzdG9yeScpIGlzIFRydWUKCgpkZWYgdGVzdF96c2hfaGlzdG9yeV9tYXBwaW5nX2V4aXN0cyhlcyk6CiAgICB6c2hfaGlzdG9yeV9tYXBwaW5nID0gZXMuaW5kaWNlcy5nZXRfbWFwcGluZyhpbmRleD0nenNoX2hpc3RvcnknKQogICAgYXNzZXJ0ICd6c2hfaGlzdG9yeScgaW4genNoX2hpc3RvcnlfbWFwcGluZwoKCmRlZiB0ZXN0X3pzaF9oaXN0b3J5X21hcHBpbmdfaGFzX2NvcnJlY3RfZmllbGRzKGVzKToKICAgIHRpbWVzdGFtcF9tYXBwaW5nID0gZXMuaW5kaWNlcy5nZXRfZmllbGRfbWFwcGluZyhpbmRleD0nenNoX2hpc3RvcnknLCBmaWVsZHM9J0B0aW1lc3RhbXAnKQogICAgdGltZXN0YW1wX3R5cGUgPSB0aW1lc3RhbXBfbWFwcGluZ1snenNoX2hpc3RvcnknXVsnbWFwcGluZ3MnXVsnQHRpbWVzdGFtcCddWydtYXBwaW5nJ11bJ0B0aW1lc3RhbXAnXVsndHlwZSddCiAgICBhc3NlcnQgdGltZXN0YW1wX3R5cGUgPT0gJ2RhdGUnCg==