Completed
Push — master ( ad0bb7...3fb24c )
by Nicolas
01:07
created

tests.DeciderStep   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 10
Duplicated Lines 0 %
Metric Value
dl 0
loc 10
rs 10
wmc 3
1
"""Unit tests for pydecider.activity
2
"""
3
4
import os
5
import sys
6
import unittest
7
8
sys.path.append(
9
    os.path.realpath(
10
        os.path.join(
11
            os.path.dirname(__file__),
12
            '..'
13
        )
14
    )
15
)
16
17
import pydecider
18
import pydecider.activity
19
20
21
class StepStateTest(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
22
23
    def test_basic_activity(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
        """Test basic definition of activities.
25
        """
26
        my_act = pydecider.activity.Activity.from_data(
27
            {
28
                'name': 'MyActivity',
29
                'version': '1.0',
30
                'input_spec': None,
31
                'outputs_spec': None,
32
            }
33
        )
34
35
        self.assertEqual(my_act.name, 'MyActivity')
36
        self.assertEqual(my_act.version, '1.0')
37
        self.assertTrue(my_act.check_input({'anything': 'goes'}))
38
        self.assertEqual(my_act.render_outputs({'anything': 'goes'}), {})
39
        # Test default values
40
        self.assertEqual(my_act.heartbeat_timeout, '60')
41
        self.assertEqual(my_act.schedule_to_start_timeout, '43200')
42
        self.assertEqual(my_act.schedule_to_close_timeout, '518400')
43
        self.assertEqual(my_act.start_to_close_timeout, '432000')
44
45
    def test_basic_activity_advanced(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
        """Test advanced definition of activities.
47
        """
48
        my_act = pydecider.activity.Activity.from_data(
49
            {
50
                'name': 'MyActivity2',
51
                'version': '2.0',
52
                'task_list': 'foobar',
53
                'heartbeat_timeout': '42',
54
                'schedule_to_start_timeout': '43',
55
                'schedule_to_close_timeout': '44',
56
                'start_to_close_timeout': '45',
57
            }
58
        )
59
60
        self.assertEqual(my_act.name, 'MyActivity2')
61
        self.assertEqual(my_act.version, '2.0')
62
        self.assertTrue(my_act.check_input({'anything': 'goes'}))
63
        self.assertEqual(my_act.render_outputs({'anything': 'goes'}), {})
64
        self.assertEqual(my_act.heartbeat_timeout, '42')
65
        self.assertEqual(my_act.schedule_to_start_timeout, '43')
66
        self.assertEqual(my_act.schedule_to_close_timeout, '44')
67
        self.assertEqual(my_act.start_to_close_timeout, '45')
68
69
    def test_input_spec(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
70
        my_act = pydecider.activity.Activity.from_data(
71
            {
72
                'name': 'MyActivity',
73
                'version': '1.0',
74
                'input_spec': {
75
                    'type': 'object',
76
                    'properties': {
77
                        'a': {
78
                            'type': 'string'
79
                        }
80
                    },
81
                    'required': ['a']
82
                }
83
            }
84
        )
85
86
        self.assertTrue(my_act.check_input({'a': 'hello'}))
87
        self.assertRaises(
88
            pydecider.schema.ValidationError,
89
            my_act.check_input,
90
            {'anything': 'goes'},
91
        )
92
93
    def test_outputs_spec(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
94
        my_act = pydecider.activity.Activity.from_data(
95
            {
96
                'name': 'MyActivity',
97
                'version': '1.0',
98
                'outputs_spec': {
99
                    'a': '$',
100
                    'b': '$.hello',
101
                }
102
            }
103
        )
104
105
        self.assertEquals(
106
            my_act.render_outputs({'hello': 'world'}),
107
            {
108
                'a': {'hello': 'world'},
109
                'b': 'world'
110
            }
111
        )
112
113
    def test_invalid_outputs_spec(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
114
        self.assertRaises(
115
            pydecider.schema.ValidationError,
116
            pydecider.activity.Activity.from_data,
117
            {
118
                'name': 'MyActivity',
119
                'version': '1.0',
120
                'outputs_spec': {
121
                    '__bad_name__': 'bad',
122
                }
123
            }
124
        )
125
126
127
if __name__ == '__main__':
128
    import logging
129
    logging.basicConfig(level=logging.DEBUG)
130
    unittest.main()
131