def test_long_running_put(self):
        #TODO: Test custom header field

        # Test throw on non LRO related status code
        response = TestLongRunningOperation.mock_send('PUT', 1000, {})
        op = LongRunningOperation(response(), lambda x: None)
        with self.assertRaises(BadStatus):
            op.get_initial_status(response())
        with self.assertRaises(CloudError):
            AzureOperationPoller(response,
                                 TestLongRunningOperation.mock_outputs,
                                 TestLongRunningOperation.mock_update,
                                 0).result()

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201, {'azure-asyncoperation': ASYNC_URL})
        poll = AzureOperationPoller(response,
                                    TestLongRunningOperation.mock_outputs,
                                    TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertFalse(
            hasattr(poll._response, 'randomFieldFromPollAsyncOpHeader'))

        # Test polling location header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201, {'location': LOCATION_URL})
        poll = AzureOperationPoller(response,
                                    TestLongRunningOperation.mock_outputs,
                                    TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201, {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                                        TestLongRunningOperation.mock_outputs,
                                        TestLongRunningOperation.mock_update,
                                        0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send('PUT', 201,
                                                      {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                                        TestLongRunningOperation.mock_outputs,
                                        TestLongRunningOperation.mock_update,
                                        0).result()
Example #2
0
    def test_long_running_put(self):
        #TODO: Test custom header field

        # Test throw on non LRO related status code
        response = TestLongRunningOperation.mock_send('PUT', 1000, {})
        op = LongRunningOperation(response(), lambda x:None)
        with self.assertRaises(BadStatus):
            op.get_initial_status(response())
        with self.assertRaises(CloudError):
            AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'azure-asyncoperation': ASYNC_URL})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertFalse(hasattr(poll._response, 'randomFieldFromPollAsyncOpHeader'))

        # Test polling location header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'location': LOCATION_URL})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()
    def test_long_running_patch(self):

        # Test polling from location header
        response = TestLongRunningOperation.mock_send(
            'PATCH',
            202, {'location': LOCATION_URL},
            body={'properties': {
                'provisioningState': 'Succeeded'
            }})
        poll = AzureOperationPoller(response,
                                    TestLongRunningOperation.mock_outputs,
                                    TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PATCH',
            202, {'azure-asyncoperation': ASYNC_URL},
            body={'properties': {
                'provisioningState': 'Succeeded'
            }})
        poll = AzureOperationPoller(response,
                                    TestLongRunningOperation.mock_outputs,
                                    TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertFalse(
            hasattr(poll._response, 'randomFieldFromPollAsyncOpHeader'))

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PATCH', 202, {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                                        TestLongRunningOperation.mock_outputs,
                                        TestLongRunningOperation.mock_update,
                                        0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send('PATCH', 202,
                                                      {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                                        TestLongRunningOperation.mock_outputs,
                                        TestLongRunningOperation.mock_update,
                                        0).result()
    def test_long_running_post_delete(self):

        # Test throw on non LRO related status code
        response = TestLongRunningOperation.mock_send('POST', 201, {})
        op = LongRunningOperation(response(), lambda x: None)
        with self.assertRaises(BadStatus):
            op.get_initial_status(response())
        with self.assertRaises(CloudError):
            AzureOperationPoller(response,
                                 TestLongRunningOperation.mock_outputs,
                                 TestLongRunningOperation.mock_update,
                                 0).result()

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'POST',
            202, {'azure-asyncoperation': ASYNC_URL},
            body={'properties': {
                'provisioningState': 'Succeeded'
            }})
        poll = AzureOperationPoller(response,
                                    TestLongRunningOperation.mock_outputs,
                                    TestLongRunningOperation.mock_update, 0)
        poll.wait()
        #self.assertIsNone(poll.result())
        self.assertIsNone(poll._response.randomFieldFromPollAsyncOpHeader)

        # Test polling from location header
        response = TestLongRunningOperation.mock_send(
            'POST',
            202, {'location': LOCATION_URL},
            body={'properties': {
                'provisioningState': 'Succeeded'
            }})
        poll = AzureOperationPoller(response,
                                    TestLongRunningOperation.mock_outputs,
                                    TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'POST', 202, {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                                        TestLongRunningOperation.mock_outputs,
                                        TestLongRunningOperation.mock_update,
                                        0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send('POST', 202,
                                                      {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                                        TestLongRunningOperation.mock_outputs,
                                        TestLongRunningOperation.mock_update,
                                        0).result()
 def test_long_running_delete(self):
     # Test polling from azure-asyncoperation header
     response = TestLongRunningOperation.mock_send(
         'DELETE', 202,
         {'azure-asyncoperation': ASYNC_URL})
     poll = AzureOperationPoller(response,
         TestLongRunningOperation.mock_outputs,
         TestLongRunningOperation.mock_update, 0)
     poll.wait()
     self.assertIsNone(poll.result())
     self.assertIsNone(poll._response.randomFieldFromPollAsyncOpHeader)
Example #6
0
    def test_long_running_patch(self):

        # Test polling from location header
        response = TestLongRunningOperation.mock_send(
            'PATCH', 202,
            {'location': LOCATION_URL},
            body={'properties':{'provisioningState': 'Succeeded'}})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PATCH', 202,
            {'azure-asyncoperation': ASYNC_URL},
            body={'properties':{'provisioningState': 'Succeeded'}})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertFalse(hasattr(poll._response, 'randomFieldFromPollAsyncOpHeader'))

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PATCH', 202,
            {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send(
            'PATCH', 202,
            {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()
Example #7
0
    def test_long_running_post_delete(self):

        # Test throw on non LRO related status code
        response = TestLongRunningOperation.mock_send('POST', 201, {})
        op = LongRunningOperation(response(), lambda x:None)
        with self.assertRaises(BadStatus):
            op.get_initial_status(response())
        with self.assertRaises(CloudError):
            AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'POST', 202,
            {'azure-asyncoperation': ASYNC_URL},
            body={'properties':{'provisioningState': 'Succeeded'}})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        poll.wait()
        #self.assertIsNone(poll.result())
        self.assertIsNone(poll._response.randomFieldFromPollAsyncOpHeader)

        # Test polling from location header
        response = TestLongRunningOperation.mock_send(
            'POST', 202,
            {'location': LOCATION_URL},
            body={'properties':{'provisioningState': 'Succeeded'}})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'POST', 202,
            {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send(
            'POST', 202,
            {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()
    def test_long_running_put(self):
        #TODO: Test custom header field

        # Test throw on non LRO related status code
        response = TestLongRunningOperation.mock_send('PUT', 1000, {})
        op = LongRunningOperation(response(), lambda x:None)
        with self.assertRaises(BadStatus):
            op.set_initial_status(response())
        with self.assertRaises(CloudError):
            AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test with no polling necessary
        response_body = {
            'properties':{'provisioningState': 'Succeeded'},
            'name': TEST_NAME
        }
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {}, response_body
        )
        def no_update_allowed(url, headers=None):
            raise ValueError("Should not try to update")
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            no_update_allowed,
            0
        )
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertFalse(hasattr(poll._response, 'randomFieldFromPollAsyncOpHeader'))

        # Test polling from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'azure-asyncoperation': ASYNC_URL})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertFalse(hasattr(poll._response, 'randomFieldFromPollAsyncOpHeader'))

        # Test polling location header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'location': LOCATION_URL})
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test polling initial payload invalid (SQLDb)
        response_body = {}  # Empty will raise
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'location': LOCATION_URL}, response_body)
        poll = AzureOperationPoller(response,
            TestLongRunningOperation.mock_outputs,
            TestLongRunningOperation.mock_update, 0)
        self.assertEqual(poll.result().name, TEST_NAME)
        self.assertIsNone(poll._response.randomFieldFromPollLocationHeader)

        # Test fail to poll from azure-asyncoperation header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'azure-asyncoperation': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()

        # Test fail to poll from location header
        response = TestLongRunningOperation.mock_send(
            'PUT', 201,
            {'location': ERROR})
        with self.assertRaises(BadEndpointError):
            poll = AzureOperationPoller(response,
                TestLongRunningOperation.mock_outputs,
                TestLongRunningOperation.mock_update, 0).result()