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

41 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-21 21:08 -0600

1"""Entity Class Definition""" 

2 

3import typing as t 

4from es_testbed.defaults import NAMEMAPPER 

5 

6if t.TYPE_CHECKING: 

7 from elasticsearch8 import Elasticsearch 

8 from dotmap import DotMap 

9 

10 

11class EntityMgr: 

12 """Entity Manager Parent Class""" 

13 

14 kind = "entity_type" 

15 listname = "entity_mgrs" 

16 

17 def __init__( 

18 self, 

19 client: t.Union["Elasticsearch", None] = None, 

20 plan: t.Union["DotMap", None] = None, 

21 ): 

22 self.client = client 

23 self.plan = plan 

24 

25 @property 

26 def entity_list(self) -> t.List: 

27 """Return the stored list of entities""" 

28 return self.plan[self.listname] 

29 

30 @entity_list.setter 

31 def entity_list(self, value: t.Sequence) -> None: 

32 self.plan[self.listname] = value 

33 

34 @property 

35 def entity_root(self) -> str: 

36 """The entity root name builder""" 

37 return f"{self.plan.prefix}-{self.ident()}-{self.plan.uniq}" 

38 

39 @property 

40 def indexlist(self) -> t.Sequence[str]: 

41 """Empty attribute/property waiting to be overridden""" 

42 return [] 

43 

44 @property 

45 def last(self) -> str: 

46 """Return the most recently appended entity""" 

47 return self.entity_list[-1] 

48 

49 @property 

50 def name(self) -> str: 

51 """Return the full, incrementing name of a not yet appended entity""" 

52 return f"{self.entity_root}{self.suffix}" 

53 

54 @property 

55 def pattern(self) -> str: 

56 """Return the search pattern for the managed entity""" 

57 return f"*{self.entity_root}*" 

58 

59 @property 

60 def suffix(self) -> str: 

61 """Return the incrementing index suffix""" 

62 return f"-{len(self.entity_list) + 1:06}" 

63 

64 def appender(self, name: str) -> None: 

65 """Append an item to entity_list""" 

66 self.entity_list.append(name) 

67 

68 def ident(self, dkey=None) -> str: 

69 """Get the formatted name string of the managed entity""" 

70 if not dkey: 

71 dkey = self.kind 

72 return NAMEMAPPER[dkey] 

73 

74 def setup(self) -> None: 

75 """Setup the entity manager""" 

76 

77 def track_index(self, name: str) -> None: 

78 """Track an index and append that tracking entity to entity_list"""