Coverage for tests/integration/test_testbed.py: 100%

35 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-23 13:14 -0600

1"""Test functions in es_testbed.TestBed""" 

2# pylint: disable=redefined-outer-name,missing-function-docstring 

3import pytest 

4from es_testbed import TestPlan, TestBed 

5from es_testbed.defaults import NAMEMAPPER 

6from es_testbed.helpers.es_api import get_write_index 

7 

8@pytest.fixture(scope='module') 

9def settings(prefix, uniq): 

10 return { 

11 'type': 'indices', 

12 'prefix': prefix, 

13 'rollover_alias': True, 

14 'uniq': uniq, 

15 'ilm': False 

16 } 

17 

18class TestTestBedBasicIndices: 

19 """Test basic TestBed class functionality""" 

20 @pytest.fixture(scope="class") 

21 def tb(self, client, settings): 

22 teebee = TestBed(client, plan=TestPlan(settings=settings)) 

23 teebee.setup() 

24 yield teebee 

25 teebee.teardown() 

26 

27 def test_entity_count(self, tb): 

28 assert len(tb.tracker.entities.entity_list) == 3 

29 

30 def test_first_index(self, tb, prefix, uniq): 

31 value = f'{prefix}-{NAMEMAPPER['index']}-{uniq}-000001' 

32 assert tb.tracker.entities.entity_list[0].name == value 

33 

34 def test_last_index(self, tb, prefix, uniq): 

35 value = f'{prefix}-{NAMEMAPPER['index']}-{uniq}-000003' 

36 assert tb.tracker.entities.last.name == value 

37 

38 def test_write_index(self, tb, prefix, uniq): 

39 alias = f'{prefix}-{NAMEMAPPER['index']}-{uniq}' 

40 assert tb.tracker.entities.last.name == get_write_index(tb.client, alias) 

41 

42 def test_index_template(self, tb, prefix, uniq): 

43 components = [] 

44 components.append(f'{prefix}-{NAMEMAPPER['component']}-{uniq}-000001') 

45 components.append(f'{prefix}-{NAMEMAPPER['component']}-{uniq}-000002') 

46 assert tb.tracker.components.entity_list == components 

47 template = f'{prefix}-{NAMEMAPPER['template']}-{uniq}-000001' 

48 assert tb.tracker.templates.last == template 

49 result = tb.client.indices.get_index_template(name=template)['index_templates'] 

50 assert len(result) == 1 

51 assert result[0]['index_template']['composed_of'] == components