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)
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_negative(self): global LOCATION_BODY global POLLING_STATUS # Test LRO PUT throws for invalid json LOCATION_BODY = '{' response = TestLongRunningOperation.mock_send( 'POST', 202, {'location': LOCATION_URL}) poll = AzureOperationPoller(response, TestLongRunningOperation.mock_outputs, TestLongRunningOperation.mock_update, 0) with self.assertRaises(DeserializationError): poll.wait() LOCATION_BODY = '{\'"}' response = TestLongRunningOperation.mock_send( 'POST', 202, {'location': LOCATION_URL}) poll = AzureOperationPoller(response, TestLongRunningOperation.mock_outputs, TestLongRunningOperation.mock_update, 0) with self.assertRaises(DeserializationError): poll.wait() LOCATION_BODY = '{' POLLING_STATUS = 203 response = TestLongRunningOperation.mock_send( 'POST', 202, {'location': LOCATION_URL}) poll = AzureOperationPoller(response, TestLongRunningOperation.mock_outputs, TestLongRunningOperation.mock_update, 0) with self.assertRaises(CloudError): # TODO: Node.js raises on deserialization poll.wait() LOCATION_BODY = json.dumps({ 'name': TEST_NAME }) POLLING_STATUS = 200
def test_long_running_negative(self): global LOCATION_BODY global POLLING_STATUS # Test LRO PUT throws for invalid json LOCATION_BODY = '{' response = TestLongRunningOperation.mock_send( 'POST', 202, {'location': LOCATION_URL}) poll = AzureOperationPoller(response, TestLongRunningOperation.mock_outputs, TestLongRunningOperation.mock_update, 0) with self.assertRaises(DeserializationError): poll.wait() LOCATION_BODY = '{\'"}' response = TestLongRunningOperation.mock_send( 'POST', 202, {'location': LOCATION_URL}) poll = AzureOperationPoller(response, TestLongRunningOperation.mock_outputs, TestLongRunningOperation.mock_update, 0) with self.assertRaises(DeserializationError): poll.wait() LOCATION_BODY = '{' POLLING_STATUS = 203 response = TestLongRunningOperation.mock_send( 'POST', 202, {'location': LOCATION_URL}) poll = AzureOperationPoller(response, TestLongRunningOperation.mock_outputs, TestLongRunningOperation.mock_update, 0) with self.assertRaises(CloudError): # TODO: Node.js raises on deserialization poll.wait() LOCATION_BODY = json.dumps({ 'status': 'Succeeded', 'name': TEST_NAME }) POLLING_STATUS = 200