Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/classes/entities/alias.py: 81%

24 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-27 20:59 -0600

1"""Alias Entity Class""" 

2 

3import typing as t 

4from es_testbed.helpers.utils import getlogger 

5from es_testbed.helpers import es_api 

6from .entity import Entity 

7 

8if t.TYPE_CHECKING: 8 ↛ 9line 8 didn't jump to line 9, because the condition on line 8 was never true

9 from elasticsearch8 import Elasticsearch 

10 

11# pylint: disable=missing-docstring,too-many-arguments 

12 

13 

14class Alias(Entity): 

15 

16 def __init__( 

17 self, 

18 client: 'Elasticsearch', 

19 name: t.Union[str, None] = None, 

20 ): 

21 super().__init__(client=client, name=name) 

22 self.logger = getlogger('es_testbed.Alias') 

23 

24 def rollover(self) -> None: 

25 es_api.rollover(self.client, self.name) 

26 

27 def verify(self, index_list: t.Sequence[str]) -> bool: 

28 retval = False 

29 res = es_api.resolver(self.client, self.name) 

30 for idx, alias in enumerate(res['aliases']): 30 ↛ 41line 30 didn't jump to line 41, because the loop on line 30 didn't complete

31 if alias['name'] == self.name: 31 ↛ 34line 31 didn't jump to line 34, because the condition on line 31 was never false

32 self.logger.debug('Confirm match of alias %s at index %s', alias, idx) 

33 else: 

34 continue 

35 if alias['indices'] == index_list: 35 ↛ 30line 35 didn't jump to line 30, because the condition on line 35 was never false

36 self.logger.debug( 

37 'Confirm match of indices backed by alias %s', self.name 

38 ) 

39 retval = True 

40 break 

41 return retval