Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/presets/searchable_test/definitions.py: 100%

30 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-08-24 13:45 -0600

1"""Searchable Snapshot Test Built-in Plan""" 

2 

3import logging 

4from pathlib import Path 

5from json import loads 

6from es_client.helpers.utils import get_yaml 

7from . import scenarios 

8 

9logger = logging.getLogger(__name__) 

10 

11 

12def baseplan() -> dict: 

13 """Return the base plan object from plan.yml""" 

14 return get_yaml((modpath() / 'plan.yml')) 

15 

16 

17def buildlist() -> list: 

18 """Return the list of index build schemas from buildlist.yml""" 

19 return get_yaml((modpath() / 'buildlist.yml')) 

20 

21 

22def get_plan(scenario: str = None) -> dict: 

23 """Return the plan dict based on scenario""" 

24 retval = baseplan() 

25 retval.update(buildlist()) 

26 if not scenario: 

27 return retval 

28 retval['uniq'] = f'scenario-{scenario}' 

29 newvals = getattr(scenarios, scenario) 

30 ilm = {} 

31 if 'ilm' in newvals: 

32 ilm = newvals.pop('ilm') 

33 if ilm: 

34 retval['ilm'].update(ilm) 

35 retval.update(newvals) 

36 return retval 

37 

38 

39def mappings() -> dict: 

40 """Return the index mappings from mappings.json""" 

41 return loads((modpath() / 'mappings.json').read_text(encoding='UTF-8')) 

42 

43 

44def modpath() -> Path: 

45 """Return the local file path""" 

46 return Path(__file__).parent.resolve() 

47 

48 

49def settings() -> dict: 

50 """Return the index settings from settings.json""" 

51 return loads((modpath() / 'settings.json').read_text(encoding='UTF-8'))