Пример #1
0
    def setUp(self):
        self.waiter_config = mock.Mock()
        self.waiter_config.description = ''
        self.waiter_config.operation = 'MyOperation'

        # Set up the acceptors.
        self.success_acceptor = mock.Mock()
        self.success_acceptor.state = 'success'
        self.fail_acceptor = mock.Mock()
        self.fail_acceptor.state = 'failure'
        self.error_acceptor = mock.Mock()
        self.error_acceptor.state = 'error'
        self.waiter_config.acceptors = [
            self.fail_acceptor, self.success_acceptor, self.error_acceptor
        ]

        self.doc_builder = WaiterStateDocBuilder(self.waiter_config)
Пример #2
0
    def setUp(self):
        self.waiter_config = mock.Mock()
        self.waiter_config.description = ""
        self.waiter_config.operation = "MyOperation"
        self.waiter_config.delay = 5
        self.waiter_config.max_attempts = 20

        # Set up the acceptors.
        self.success_acceptor = mock.Mock()
        self.success_acceptor.state = "success"
        self.fail_acceptor = mock.Mock()
        self.fail_acceptor.state = "failure"
        self.error_acceptor = mock.Mock()
        self.error_acceptor.state = "error"
        self.waiter_config.acceptors = [self.fail_acceptor, self.success_acceptor, self.error_acceptor]

        self.doc_builder = WaiterStateDocBuilder(self.waiter_config)
Пример #3
0
    def setUp(self):
        self.waiter_config = mock.Mock()
        self.waiter_config.description = ''
        self.waiter_config.operation = 'MyOperation'

        # Set up the acceptors.
        self.success_acceptor = mock.Mock()
        self.success_acceptor.state = 'success'
        self.fail_acceptor = mock.Mock()
        self.fail_acceptor.state = 'failure'
        self.error_acceptor = mock.Mock()
        self.error_acceptor.state = 'error'
        self.waiter_config.acceptors = [
            self.fail_acceptor,
            self.success_acceptor,
            self.error_acceptor
        ]

        self.doc_builder = WaiterStateDocBuilder(self.waiter_config)
Пример #4
0
class TestWaiterStateDocBuilder(unittest.TestCase):
    def setUp(self):
        self.waiter_config = mock.Mock()
        self.waiter_config.description = ''
        self.waiter_config.operation = 'MyOperation'

        # Set up the acceptors.
        self.success_acceptor = mock.Mock()
        self.success_acceptor.state = 'success'
        self.fail_acceptor = mock.Mock()
        self.fail_acceptor.state = 'failure'
        self.error_acceptor = mock.Mock()
        self.error_acceptor.state = 'error'
        self.waiter_config.acceptors = [
            self.fail_acceptor,
            self.success_acceptor,
            self.error_acceptor
        ]

        self.doc_builder = WaiterStateDocBuilder(self.waiter_config)

    def test_config_provided_description(self):
        # Description is provided by the config file
        self.waiter_config.description = 'my description'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(description, 'my description')

    def test_error_acceptor(self):
        self.success_acceptor.matcher = 'error'
        self.success_acceptor.expected = 'MyException'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until MyException is thrown when polling with '
            '``my-operation``.'
        )

    def test_status_acceptor(self):
        self.success_acceptor.matcher = 'status'
        self.success_acceptor.expected = 200
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until 200 response is received when polling with '
            '``my-operation``.'
        )

    def test_path_acceptor(self):
        self.success_acceptor.matcher = 'path'
        self.success_acceptor.argument = 'MyResource.name'
        self.success_acceptor.expected = 'running'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until JMESPath query MyResource.name returns running when '
            'polling with ``my-operation``.'
        )

    def test_path_all_acceptor(self):
        self.success_acceptor.matcher = 'pathAll'
        self.success_acceptor.argument = 'MyResource[].name'
        self.success_acceptor.expected = 'running'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until JMESPath query MyResource[].name returns running for '
            'all elements when polling with ``my-operation``.'
        )

    def test_path_any_acceptor(self):
        self.success_acceptor.matcher = 'pathAny'
        self.success_acceptor.argument = 'MyResource[].name'
        self.success_acceptor.expected = 'running'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until JMESPath query MyResource[].name returns running for '
            'any element when polling with ``my-operation``.'
        )
Пример #5
0
class TestWaiterStateDocBuilder(unittest.TestCase):
    def setUp(self):
        self.waiter_config = mock.Mock()
        self.waiter_config.description = ''
        self.waiter_config.operation = 'MyOperation'
        self.waiter_config.delay = 5
        self.waiter_config.max_attempts = 20

        # Set up the acceptors.
        self.success_acceptor = mock.Mock()
        self.success_acceptor.state = 'success'
        self.fail_acceptor = mock.Mock()
        self.fail_acceptor.state = 'failure'
        self.error_acceptor = mock.Mock()
        self.error_acceptor.state = 'error'
        self.waiter_config.acceptors = [
            self.fail_acceptor,
            self.success_acceptor,
            self.error_acceptor
        ]

        self.doc_builder = WaiterStateDocBuilder(self.waiter_config)

    def test_config_provided_description(self):
        # Description is provided by the config file
        self.waiter_config.description = 'My description.'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'My description. It will poll every 5 seconds until a '
            'successful state has been reached. This will exit with a '
            'return code of 255 after 20 failed checks.')

    def test_error_acceptor(self):
        self.success_acceptor.matcher = 'error'
        self.success_acceptor.expected = 'MyException'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until MyException is thrown when polling with '
            '``my-operation``. It will poll every 5 seconds until a '
            'successful state has been reached. This will exit with a '
            'return code of 255 after 20 failed checks.'
        )

    def test_status_acceptor(self):
        self.success_acceptor.matcher = 'status'
        self.success_acceptor.expected = 200
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until 200 response is received when polling with '
            '``my-operation``. It will poll every 5 seconds until a '
            'successful state has been reached. This will exit with a '
            'return code of 255 after 20 failed checks.'
        )

    def test_path_acceptor(self):
        self.success_acceptor.matcher = 'path'
        self.success_acceptor.argument = 'MyResource.name'
        self.success_acceptor.expected = 'running'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until JMESPath query MyResource.name returns running when '
            'polling with ``my-operation``. It will poll every 5 seconds '
            'until a successful state has been reached. This will exit with '
            'a return code of 255 after 20 failed checks.'
        )

    def test_path_all_acceptor(self):
        self.success_acceptor.matcher = 'pathAll'
        self.success_acceptor.argument = 'MyResource[].name'
        self.success_acceptor.expected = 'running'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until JMESPath query MyResource[].name returns running for '
            'all elements when polling with ``my-operation``. It will poll '
            'every 5 seconds until a successful state has been reached. '
            'This will exit with a return code of 255 after 20 failed checks.'
        )

    def test_path_any_acceptor(self):
        self.success_acceptor.matcher = 'pathAny'
        self.success_acceptor.argument = 'MyResource[].name'
        self.success_acceptor.expected = 'running'
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            'Wait until JMESPath query MyResource[].name returns running for '
            'any element when polling with ``my-operation``. It will poll '
            'every 5 seconds until a successful state has been reached. '
            'This will exit with a return code of 255 after 20 failed checks.'
        )
Пример #6
0
class TestWaiterStateDocBuilder(unittest.TestCase):
    def setUp(self):
        self.waiter_config = mock.Mock()
        self.waiter_config.description = ""
        self.waiter_config.operation = "MyOperation"
        self.waiter_config.delay = 5
        self.waiter_config.max_attempts = 20

        # Set up the acceptors.
        self.success_acceptor = mock.Mock()
        self.success_acceptor.state = "success"
        self.fail_acceptor = mock.Mock()
        self.fail_acceptor.state = "failure"
        self.error_acceptor = mock.Mock()
        self.error_acceptor.state = "error"
        self.waiter_config.acceptors = [self.fail_acceptor, self.success_acceptor, self.error_acceptor]

        self.doc_builder = WaiterStateDocBuilder(self.waiter_config)

    def test_config_provided_description(self):
        # Description is provided by the config file
        self.waiter_config.description = "My description."
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            "My description. It will poll every 5 seconds until a "
            "successful state has been reached. This will exit with a "
            "return code of 255 after 20 failed checks.",
        )

    def test_error_acceptor(self):
        self.success_acceptor.matcher = "error"
        self.success_acceptor.expected = "MyException"
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            "Wait until MyException is thrown when polling with "
            "``my-operation``. It will poll every 5 seconds until a "
            "successful state has been reached. This will exit with a "
            "return code of 255 after 20 failed checks.",
        )

    def test_status_acceptor(self):
        self.success_acceptor.matcher = "status"
        self.success_acceptor.expected = 200
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            "Wait until 200 response is received when polling with "
            "``my-operation``. It will poll every 5 seconds until a "
            "successful state has been reached. This will exit with a "
            "return code of 255 after 20 failed checks.",
        )

    def test_path_acceptor(self):
        self.success_acceptor.matcher = "path"
        self.success_acceptor.argument = "MyResource.name"
        self.success_acceptor.expected = "running"
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            "Wait until JMESPath query MyResource.name returns running when "
            "polling with ``my-operation``. It will poll every 5 seconds "
            "until a successful state has been reached. This will exit with "
            "a return code of 255 after 20 failed checks.",
        )

    def test_path_all_acceptor(self):
        self.success_acceptor.matcher = "pathAll"
        self.success_acceptor.argument = "MyResource[].name"
        self.success_acceptor.expected = "running"
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            "Wait until JMESPath query MyResource[].name returns running for "
            "all elements when polling with ``my-operation``. It will poll "
            "every 5 seconds until a successful state has been reached. "
            "This will exit with a return code of 255 after 20 failed checks.",
        )

    def test_path_any_acceptor(self):
        self.success_acceptor.matcher = "pathAny"
        self.success_acceptor.argument = "MyResource[].name"
        self.success_acceptor.expected = "running"
        description = self.doc_builder.build_waiter_state_description()
        self.assertEqual(
            description,
            "Wait until JMESPath query MyResource[].name returns running for "
            "any element when polling with ``my-operation``. It will poll "
            "every 5 seconds until a successful state has been reached. "
            "This will exit with a return code of 255 after 20 failed checks.",
        )