Пример #1
0
class TestStateOutputPass(unittest.TestCase):
    def setUp(self):
        self.ss = StairStep(
            comment="A simple minimal example of the States language",
            startAt="HelloWorld",
        )
        self.state = StatePass(name="HelloWorld",
                               comment="Pass State example",
                               end=True)
        self.ss.addState(self.state)

    def test_output(self):
        self.maxDiff = None
        #validated by statelint
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "HelloWorld",
                "States": {
                    "HelloWorld": { 
                        "Type": "Pass",
                        "Comment": "Pass State example",
                        "End": true
                    }
                }
            }
        '''

        output = json.loads(output)
        result = json.loads(self.ss.json())
        self.assertDictEqual(output, result)
Пример #2
0
class TestStateOutputTask(unittest.TestCase):
    def setUp(self):
        self.ss = StairStep(
            comment="A simple minimal example of the States language",
            startAt="HelloWorld",
        )
        self.state = StateTask(
            name="HelloWorld",
            comment="Task State example",
            resource="arn:aws:swf:us-east-1:123456789012:task:HelloWorld",
            end=True)
        self.ss.addState(self.state)

    def test_output(self):
        self.maxDiff = None
        #validated by statelint
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "HelloWorld",
                "States": {
                    "HelloWorld": { 
                        "Type": "Task",
                        "Comment": "Task State example",
                        "Resource": "arn:aws:swf:us-east-1:123456789012:task:HelloWorld",
                        "End": true
                    }
                }
            }
        '''

        output = json.loads(output)
        result = json.loads(self.ss.json())
        self.assertDictEqual(output, result)
Пример #3
0
    def test_single_state(self):
        self.maxDiff = None
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "Hello World",
                "States": {
                    "Hello World": { 
                        "Type": "Task",
                        "Resource": "arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
                        "Next": "nextResource"
                    }
                }
            }
        '''
        #compress and remove whitespace
        output = json.dumps(json.loads(output))
        ss = StairStep(
            comment="A simple minimal example of the States language",
            startAt="Hello World",
        )
        hello_step = StateTask(
            name="Hello World",
            resource=
            "arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
            snext="nextResource")

        ss.addState(hello_step)
        self.assertEqual(output, ss.json())
Пример #4
0
 def setUp(self):
     self.ss = StairStep(
         comment="A simple minimal example of the States language",
         startAt="HelloWorld",
     )
     self.state = StatePass(name="HelloWorld",
                            comment="Pass State example",
                            end=True)
     self.ss.addState(self.state)
Пример #5
0
 def setUp(self):
     self.ss = StairStep(
         comment="A simple minimal example of the States language",
         startAt="HelloWorld",
     )
     self.state = StateSucceed(
         name="HelloWorld",
         comment="Succeed State example",
     )
     self.ss.addState(self.state)
Пример #6
0
 def setUp(self):
     self.ss = StairStep(
         comment="A simple minimal example of the States language",
         startAt="HelloWorld",
     )
     self.state = StateTask(
         name="HelloWorld",
         comment="Task State example",
         resource="arn:aws:swf:us-east-1:123456789012:task:HelloWorld",
         end=True)
     self.ss.addState(self.state)
Пример #7
0
class TestStairStepIndempodent(unittest.TestCase):
    def setUp(self):
        self.ss = StairStep(
            comment="A simple minimal example of the States language",
            startAt="HelloWorld",
        )
        self.state = StatePass(name="HelloWorld",
                               comment="Pass State example",
                               end=True)
        self.ss.addState(self.state)

    def test_export_is_indempodent(self):
        self.ss.export()
        self.ss.export()
Пример #8
0
    def setUp(self):
        self.maxDiff = None
        self.ss = StairStep(
            comment = "Example Choice State",
            startAt = "ChoiceStateX"
        )
        typeNotPrivate = ChoiceRule(operator="Not", snext="Public", conditions=
                            ChoiceExpression(operator="StringEquals", variable="$.type", value="Private")
                         )

        valueInTwenties = ChoiceRule(operator="And", snext="ValueInTwenties", conditions=[
                            ChoiceExpression(operator="NumericGreaterThanEquals", variable="$.value", value=20),
                            ChoiceExpression(operator="NumericLessThan", variable="$.value", value=30)]
                        )
    
        self.state = StateChoice(
            name    = "ChoiceStateX",
            choices = [typeNotPrivate, valueInTwenties],
            default = "DefaultState"
        )
        self.ss.addState(self.state)
Пример #9
0
    def test_single_state_comment_optional(self):
        output = '''{
                        "StartAt": "Hello World",
                        "States": {
                            "Hello World": { 
                                "Type": "Succeed",
                                "Resource": "arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
                                "Next" : "nextResource"
                            }
                        }
                    }'''
        #compress and remove whitespace
        output = json.dumps(json.loads(output))
        ss = StairStep(startAt="Hello World", )
        hello_step = StateSucceed(
            name="Hello World",
            resource=
            "arn:aws:lambda:us-east-1:123456789012:function:HelloWorld",
            snext="nextResource")

        ss.addState(hello_step)
        self.assertEqual(output, ss.json())
Пример #10
0
 def setUp(self):
     self.ss = StairStep(
         comment="A simple minimal example of the States language",
         startAt="HelloWorld",
     )
Пример #11
0
class TestStateOutputWait(unittest.TestCase):
    def setUp(self):
        self.ss = StairStep(
            comment="A simple minimal example of the States language",
            startAt="HelloWorld",
        )

    def test_output_delay(self):
        self.state = StateWait(name="wait_ten_seconds",
                               seconds=10,
                               snext="NextState")
        self.ss.addState(self.state)

        self.maxDiff = None
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "HelloWorld",
                "States": {
                    "wait_ten_seconds" : {
                        "Type" : "Wait",
                        "Seconds" : 10,
                        "Next": "NextState"
                    }
                }
            }
        '''

        output = json.loads(output)
        result = json.loads(self.ss.json())
        self.assertDictEqual(output, result)

    def test_output_absolute(self):
        from datetime import datetime, timezone

        wait_until = datetime(year=2016,
                              month=3,
                              day=14,
                              hour=1,
                              minute=59,
                              second=0,
                              tzinfo=timezone.utc)
        self.state = StateWait(name="wait_until",
                               timestamp=wait_until,
                               snext="NextState")
        self.ss.addState(self.state)

        self.maxDiff = None
        #python datetime ISO export doesn't suppport Zulu, changed to +00
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "HelloWorld",
                "States": {
                    "wait_until" : {
                        "Type": "Wait",
                        "Timestamp": "2016-03-14T01:59:00+00:00",
                        "Next": "NextState"
                    }
                }
            }
        '''

        output = json.loads(output)
        result = json.loads(self.ss.json())
        self.assertDictEqual(output, result)

    def test_output_reference_time(self):
        from datetime import datetime, timezone

        self.state = StateWait(name="wait_until",
                               timestamppath="$.expirydate",
                               snext="NextState")
        self.ss.addState(self.state)

        self.maxDiff = None
        #python datetime ISO export doesn't suppport Zulu, changed to +00
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "HelloWorld",
                "States": {
                    "wait_until" : {
                        "Type": "Wait",
                        "TimestampPath": "$.expirydate",
                        "Next": "NextState"
                    }
                }
            }
        '''

        output = json.loads(output)
        result = json.loads(self.ss.json())
        self.assertDictEqual(output, result)

    def test_output_reference_seconds(self):
        from datetime import datetime, timezone

        self.state = StateWait(name="wait_until",
                               secondspath="$.seconds",
                               snext="NextState")
        self.ss.addState(self.state)

        self.maxDiff = None
        #python datetime ISO export doesn't suppport Zulu, changed to +00
        output = '''
            {
                "Comment": "A simple minimal example of the States language",
                "StartAt": "HelloWorld",
                "States": {
                    "wait_until" : {
                        "Type": "Wait",
                        "SecondsPath": "$.seconds",
                        "Next": "NextState"
                    }
                }
            }
        '''

        output = json.loads(output)
        result = json.loads(self.ss.json())
        self.assertDictEqual(output, result)
Пример #12
0
class TestChoiceStateRule(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None
        self.ss = StairStep(
            comment = "Example Choice State",
            startAt = "ChoiceStateX"
        )
        typeNotPrivate = ChoiceRule(operator="Not", snext="Public", conditions=
                            ChoiceExpression(operator="StringEquals", variable="$.type", value="Private")
                         )

        valueInTwenties = ChoiceRule(operator="And", snext="ValueInTwenties", conditions=[
                            ChoiceExpression(operator="NumericGreaterThanEquals", variable="$.value", value=20),
                            ChoiceExpression(operator="NumericLessThan", variable="$.value", value=30)]
                        )
    
        self.state = StateChoice(
            name    = "ChoiceStateX",
            choices = [typeNotPrivate, valueInTwenties],
            default = "DefaultState"
        )
        self.ss.addState(self.state)
    
    def test_choice_state(self):
        output = '''
            {
                "Comment": "Example Choice State",
                "StartAt": "ChoiceStateX",
                "States": {
                    "ChoiceStateX": {
                        "Type" : "Choice",
                        "Choices": [
                            {
                                "Not": {
                                "Variable": "$.type",
                                "StringEquals": "Private"
                                },
                                "Next": "Public"
                            },
                            {
                            "And": [
                                {
                                "Variable": "$.value",
                                "NumericGreaterThanEquals": 20
                                },
                                {
                                "Variable": "$.value",
                                "NumericLessThan": 30
                                }
                            ],
                            "Next": "ValueInTwenties"
                            }
                        ],
                        "Default": "DefaultState"
                        }

                }
            }
        '''     
        output = json.loads(output)
        result = json.loads( self.ss.json() )
        self.assertDictEqual(output, result)
Пример #13
0
 def test_base_object(self):
     ss = StairStep()
     self.assertIsInstance(ss, StairStep)