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%

31 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-08-30 19:06 -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 .scenarios 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 scenarios = Scenarios() 

30 newvals = getattr(scenarios, scenario) 

31 ilm = {} 

32 if 'ilm' in newvals: 

33 ilm = newvals.pop('ilm') 

34 if ilm: 

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

36 retval.update(newvals) 

37 return retval 

38 

39 

40def mappings() -> dict: 

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

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

43 

44 

45def modpath() -> Path: 

46 """Return the local file path""" 

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

48 

49 

50def settings() -> dict: 

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

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