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

22 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-25 19:21 -0600

1"""Base Entity Class""" 

2import typing as t 

3from elasticsearch8 import Elasticsearch 

4from es_testbed.helpers import es_api 

5from es_testbed.helpers.utils import getlogger 

6 

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

8 

9class Entity: 

10 def __init__( 

11 self, 

12 client: Elasticsearch, 

13 name: str = None, 

14 autobuild: t.Optional[bool] = True, 

15 ): 

16 self.client = client 

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

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

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

20 if autobuild: 20 ↛ exitline 20 didn't return from function '__init__', because the condition on line 20 was never false

21 self.setup() 

22 

23 @property 

24 def am_i_write_idx(self) -> bool: 

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

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

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

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

29 

30 def setup(self): 

31 pass 

32 

33 def teardown(self): 

34 pass