def test_aggregator_raises_collision(): inventory_items: List[Union[Attributes, TableRow]] = [ Attributes(path=["a", "b", "c"], status_attributes={"foo": "bar"}), TableRow(path=["a", "b", "c"], key_columns={"foo": "bar"}), ] result = inventory.TreeAggregator().aggregate_results(inventory_items) assert isinstance(result, TypeError) assert str(result) == ( "Cannot create TableRow at path ['a', 'b', 'c']: this is a Attributes node." )
def test_integrate_attributes(): inventory_items: List[Attributes] = [ Attributes( path=["a", "b", "c"], inventory_attributes={ "foo0": "bar0", "foo1": "bar1", }, ), ] tree_aggr = inventory.TreeAggregator() tree_aggr.aggregate_results( inventory_generator=inventory_items, retentions_tracker=RetentionsTracker([]), raw_cache_info=None, is_legacy_plugin=False, ) assert tree_aggr.trees.inventory.serialize() == { "Attributes": {}, "Nodes": { "a": { "Attributes": {}, "Nodes": { "b": { "Attributes": {}, "Nodes": { "c": { "Attributes": { "Pairs": { "foo0": "bar0", "foo1": "bar1" }, }, "Nodes": {}, "Table": {}, } }, "Table": {}, } }, "Table": {}, } }, "Table": {}, }
def test_aggregator_raises_collision(): inventory_items: List[Union[Attributes, TableRow]] = [ Attributes(path=["a", "b", "c"], status_attributes={"foo": "bar"}), TableRow(path=["a", "b", "c"], key_columns={"foo": "bar"}), ] result = inventory.TreeAggregator().aggregate_results( inventory_generator=inventory_items, retentions_tracker=RetentionsTracker([]), raw_cache_info=None, is_legacy_plugin=False, ) assert isinstance(result, TypeError) assert str(result) == ( "Cannot create TableRow at path ['a', 'b', 'c']: this is a Attributes node." )
def test_aggregator_raises_collision() -> None: inventory_items: List[Union[Attributes, TableRow]] = [ Attributes(path=["a", "b", "c"], status_attributes={"foo": "bar"}), TableRow(path=["a", "b", "c"], key_columns={"foo": "bar"}), ] # For some reason, the callee raises instead of returning the exception if # it runs in debug mode. So let us explicitly disable that here. cmk.utils.debug.disable() result = inventory.TreeAggregator().aggregate_results( inventory_generator=inventory_items, retentions_tracker=RetentionsTracker([]), raw_cache_info=None, is_legacy_plugin=False, ) assert isinstance(result, TypeError) assert str(result) == ( "Cannot create TableRow at path ['a', 'b', 'c']: this is a Attributes node." )
def test_integrate_table_row() -> None: inventory_items: List[TableRow] = [ TableRow( path=["a", "b", "c"], key_columns={"foo": "baz"}, inventory_columns={ "col1": "baz val1", "col2": "baz val2", "col3": "baz val3", }, ), TableRow( path=["a", "b", "c"], key_columns={"foo": "bar"}, inventory_columns={ "col1": "bar val1", "col2": "bar val2", }, ), TableRow( path=["a", "b", "c"], key_columns={"foo": "bar"}, inventory_columns={ "col1": "new bar val1", "col3": "bar val3", }, ), ] tree_aggr = inventory.TreeAggregator() tree_aggr.aggregate_results( inventory_generator=inventory_items, retentions_tracker=RetentionsTracker([]), raw_cache_info=None, is_legacy_plugin=False, ) assert tree_aggr.trees.inventory.serialize() == { "Attributes": {}, "Nodes": { "a": { "Attributes": {}, "Nodes": { "b": { "Attributes": {}, "Nodes": { "c": { "Attributes": {}, "Nodes": {}, "Table": { "KeyColumns": ["foo"], "Rows": [ { "col1": "baz " "val1", "col2": "baz " "val2", "col3": "baz " "val3", "foo": "baz", }, { "col1": "new " "bar " "val1", "col2": "bar " "val2", "col3": "bar " "val3", "foo": "bar", }, ], }, } }, "Table": {}, } }, "Table": {}, } }, "Table": {}, }