Passed
Pull Request — master (#129)
by Jan
03:09 queued 56s
created

oval_graph._builder_oval_tree   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 61
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _BuilderOvalTree.get_oval_tree_from_dict_of_rule() 0 14 1
A _BuilderOvalTree._get_id_defintion() 0 5 2
A _BuilderOvalTree._definition_dict_to_node() 0 27 3
1
'''
2
    This file contains class for building OVAL graph
3
'''
4
5 1
import uuid
6
7 1
from .oval_node import OvalNode
8
9
10 1
class _BuilderOvalTree:
11
12 1
    @staticmethod
13
    def _definition_dict_to_node(dict_of_definition):
14 1
        children = []
15 1
        for child in dict_of_definition['node']:
16 1
            if 'operator' in child:
17 1
                children.append(
18
                    _BuilderOvalTree._definition_dict_to_node(child))
19
            else:
20 1
                children.append(
21
                    OvalNode(
22
                        node_id=child['value_id'],
23
                        node_type='value',
24
                        value=child['value'],
25
                        negation=child['negate'],
26
                        comment=child['comment'],
27
                        tag=child['tag'],
28
                        test_result_details=child['test_result_details'],
29
                    ))
30
31 1
        return OvalNode(
32
            node_id=_BuilderOvalTree._get_id_defintion(dict_of_definition),
33
            node_type='operator',
34
            value=dict_of_definition['operator'],
35
            negation=dict_of_definition['negate'],
36
            comment=dict_of_definition['comment'],
37
            tag=dict_of_definition['tag'],
38
            children=children,
39
        )
40
41 1
    @staticmethod
42
    def _get_id_defintion(dict_of_definition):
43 1
        if 'definition_id' in dict_of_definition:
44 1
            return dict_of_definition['definition_id']
45 1
        return str(uuid.uuid4())
46
47 1
    @staticmethod
48
    def get_oval_tree_from_dict_of_rule(rule):
49 1
        dict_of_definition = rule['definition']
50 1
        dict_of_definition['node']['definition_id'] = rule['definition_id']
51 1
        return OvalNode(
52
            node_id=rule['rule_id'],
53
            node_type='operator',
54
            value='and',
55
            negation=False,
56
            comment=dict_of_definition['comment'],
57
            tag="Rule",
58
            children=[
59
                _BuilderOvalTree._definition_dict_to_node(
60
                    dict_of_definition['node'])],
61
        )
62