1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
"""Test helpers.schemacheck"""
from unittest import TestCase
import pytest
from voluptuous import Schema
from es_client.exceptions import FailedValidation
from es_client.helpers.schemacheck import SchemaCheck
from es_client.defaults import (
config_schema,
VERSION_MIN,
version_min,
VERSION_MAX,
version_max,
)
class TestSchemaCheck(TestCase):
"""Test SchemaCheck class and member functions"""
def test_bad_port_value(self):
"""Ensure that a bad port value Raises a FailedValidation"""
config = {"elasticsearch": {"client": {"port": 70000}}}
schema = SchemaCheck(config, config_schema(), "elasticsearch", "client")
with pytest.raises(FailedValidation):
schema.result()
def test_entirely_wrong_keys(self):
"""Ensure that unacceptable keys Raises a FailedValidation"""
config = {
"elasticsearch": {
"client_not": {},
"not_aws": {},
},
"something_else": "foo",
}
schema = SchemaCheck(config, config_schema(), "elasticsearch", "client")
with pytest.raises(FailedValidation):
schema.result()
def test_does_not_password_filter_non_dict(self):
"""Ensure that if config is not a dictionary that it doesn't choke"""
config = None
schema = SchemaCheck(config, Schema(config), "arbitrary", "anylocation")
assert schema.result() is None
class TestVersionMinMax(TestCase):
"""Test version min and max functions"""
def test_version_max(self):
"""Ensure version_max returns what it's set with"""
assert VERSION_MAX == version_max()
def test_version_min(self):
"""Ensure version_min returns what it's set with"""
assert VERSION_MIN == version_min()
|