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

17 statements  

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

1"""Base Entity Class""" 

2 

3import typing as t 

4from es_testbed.helpers import es_api 

5from es_testbed.helpers.utils import getlogger 

6 

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

8 from elasticsearch8 import Elasticsearch 

9 

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

11 

12 

13class Entity: 

14 

15 def __init__( 

16 self, 

17 client: 'Elasticsearch', 

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

19 ): 

20 self.client = client 

21 self.name = name # This will change with entity name changes 

22 self.aka = [] # Aliases, in other words 

23 self.logger = getlogger('es_testbed.Entity') 

24 

25 @property 

26 def am_i_write_idx(self) -> bool: 

27 if self.name.startswith('.ds-'): # Datastream 

28 ds = es_api.resolver(self.client, self.name)['indices'][0]['data_stream'] 

29 return bool(self.name == es_api.get_ds_current(self.client, ds)) 

30 return bool(self.name == es_api.find_write_index(self.client, self.name))