Exemplo n.º 1
0
 def test_single_waiter_supports_all_three_states(self):
     single_waiter = {
         'acceptors': [
             {
                 'state': 'success',
                 'matcher': 'error',
                 'expected': 'DoesNotExistError'
             },
             {
                 'state': 'success',
                 'matcher': 'status',
                 'expected': 200
             },
             {
                 'state': 'success',
                 'matcher': 'path',
                 'argument': 'Foo.Bar',
                 'expected': 'baz'
             },
         ],
     }
     single_waiter.update(self.boiler_plate_config)
     config = SingleWaiterConfig(single_waiter)
     acceptors = config.acceptors
     # Each acceptors should be able to handle not matching
     # any type of response.
     matches_nothing = {}
     self.assertFalse(acceptors[0].matcher_func(matches_nothing))
     self.assertFalse(acceptors[1].matcher_func(matches_nothing))
     self.assertFalse(acceptors[2].matcher_func(matches_nothing))
Exemplo n.º 2
0
 def create_acceptor_function(self, for_config):
     single_waiter = {
         'acceptors': [for_config]
     }
     single_waiter.update(self.boiler_plate_config)
     config = SingleWaiterConfig(single_waiter)
     return config.acceptors[0].matcher_func
Exemplo n.º 3
0
 def test_unknown_matcher(self):
     unknown_type = 'arbitrary_type'
     single_waiter = {
         'acceptors': [
             {'state': 'success', 'matcher': unknown_type,
              'expected': 'foo'}
         ]
     }
     single_waiter.update(self.boiler_plate_config)
     config = SingleWaiterConfig(single_waiter)
     with self.assertRaises(WaiterConfigError):
         config.acceptors
Exemplo n.º 4
0
 def test_single_waiter_config_attributes(self):
     single_waiter = {
         'description': 'Waiter description',
         'operation': 'HeadBucket',
         'delay': 5,
         'maxAttempts': 20,
         'acceptors': [],
     }
     config = SingleWaiterConfig(single_waiter)
     self.assertEqual(config.description, 'Waiter description')
     self.assertEqual(config.operation, 'HeadBucket')
     self.assertEqual(config.delay, 5)
     self.assertEqual(config.max_attempts, 20)
Exemplo n.º 5
0
 def test_single_waiter_supports_error(self):
     single_waiter = {
         'acceptors': [
             {'state': 'success', 'matcher': 'error',
              'expected': 'DoesNotExistError'}
         ],
     }
     single_waiter.update(self.boiler_plate_config)
     config = SingleWaiterConfig(single_waiter)
     success_acceptor = config.acceptors[0].matcher_func
     self.assertTrue(
         success_acceptor({'Error': {'Code': 'DoesNotExistError'}}))
     self.assertFalse(
         success_acceptor({'Error': {'Code': 'DoesNotExistErorr'}}))
Exemplo n.º 6
0
 def test_single_waiter_supports_status_code(self):
     single_waiter = {
         'acceptors': [
             {'state': 'success', 'matcher': 'status',
              'expected': 200}
         ],
     }
     single_waiter.update(self.boiler_plate_config)
     config = SingleWaiterConfig(single_waiter)
     success_acceptor = config.acceptors[0].matcher_func
     self.assertTrue(
         success_acceptor({'ResponseMetadata': {'HTTPStatusCode': 200}}))
     self.assertFalse(
         success_acceptor({'ResponseMetadata': {'HTTPStatusCode': 404}}))
Exemplo n.º 7
0
 def create_waiter_config(self, operation='MyOperation',
                          delay=0, max_attempts=3,
                          acceptors=None):
     if acceptors is None:
         # Create some arbitrary acceptor that will never match.
         acceptors = [{'state': 'success', 'matcher': 'status',
                       'expected': 1000}]
     waiter_config = {
         'operation': operation,
         'delay': delay,
         'maxAttempts': max_attempts,
         'acceptors': acceptors
     }
     config = SingleWaiterConfig(waiter_config)
     return config
Exemplo n.º 8
0
 def test_single_waiter_acceptor_matches_jmespath(self):
     single_waiter = {
         'acceptors': [
             {'state': 'success', 'matcher': 'path',
              'argument': 'Table.TableStatus', 'expected': 'ACCEPTED'},
         ],
     }
     single_waiter.update(self.boiler_plate_config)
     config = SingleWaiterConfig(single_waiter)
     success_acceptor = config.acceptors[0].matcher_func
     # success_acceptor is a callable that takes a response dict and returns
     # True or False.
     self.assertTrue(
         success_acceptor({'Table': {'TableStatus': 'ACCEPTED'}}))
     self.assertFalse(
         success_acceptor({'Table': {'TableStatus': 'CREATING'}}))
Exemplo n.º 9
0
    def test_single_waiter_acceptors_built_with_matcher_func(self):
        # When the list of acceptors are requested, we actually will transform
        # them into values that are easier to use.
        single_waiter = {
            'acceptors': [
                {'state': 'success', 'matcher': 'status', 'expected': 200},
            ],
        }
        single_waiter.update(self.boiler_plate_config)
        config = SingleWaiterConfig(single_waiter)
        success_acceptor = config.acceptors[0]

        self.assertEqual(success_acceptor.state, 'success')
        self.assertEqual(success_acceptor.matcher, 'status')
        self.assertEqual(success_acceptor.expected, 200)
        self.assertTrue(callable(success_acceptor.matcher_func))