def test_wait_for_snapshot_status_good_response_and_entity_bad_status( self): recieved_status = 'error' client = Mock(spec=VolumesClient) config = Mock(spec=VolumesAPIConfig) config.snapshot_status_poll_frequency = 1 snapshot_model = Mock(spec=VolumeSnapshotResponse) snapshot_model.status = recieved_status response = Mock(spec=Response) response.ok = True response.entity = snapshot_model client.get_snapshot_info = MagicMock( return_value=response) behavior = VolumesAPI_Behaviors(client, config) with self.assertRaises(VolumesAPIBehaviorException): behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout, poll_rate=self.defaults.poll_rate)
def test_good_response_code_empty_entity(self): client, config, snapshot_model, response = self.get_mocks() response.entity = None response.status_code = '200' client.get_snapshot_info = MagicMock(return_value=response) behavior = VolumesAPI_Behaviors(client, config) with self.assertRaises(VolumesAPIBehaviorException): behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout, poll_rate=self.defaults.poll_rate)
def test_bad_response_code(self): client, config, snapshot_model, response = self.get_mocks() response.ok = False response.entity = snapshot_model response.status_code = '401' client.get_snapshot_info = MagicMock(return_value=response) behavior = VolumesAPI_Behaviors(client, config) with self.assertRaises(StatusProgressionError): behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout, poll_rate=self.defaults.poll_rate)
def test_good_response_good_entity_bad_status(self): client, config, snapshot_model, response = self.get_mocks() recieved_status = 'error' poll_rate = 1 snapshot_model.status = recieved_status response.entity = snapshot_model client.get_snapshot_info = MagicMock(return_value=response) behavior = VolumesAPI_Behaviors(client, config) with self.assertRaises(VolumesAPIBehaviorException): behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout, poll_rate=poll_rate)
def test_bad_response_code(self): client, config, snapshot_model, response = self.get_mocks() response.ok = False response.entity = snapshot_model response.status_code = '401' client.get_snapshot_info = MagicMock(return_value=response) behavior = VolumesAPI_Behaviors(client, config) with self.assertRaises(StatusProgressionError): behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout, poll_rate=self.defaults.poll_rate)
def test_wait_for_snapshot_status_good_response_code_config_wait_period( self): client = Mock(spec=VolumesClient) config = Mock(spec=VolumesAPIConfig) config.snapshot_status_poll_frequency = 1 snapshot_model = Mock(spec=VolumeSnapshotResponse) snapshot_model.status = self.defaults.expected_status response = Mock(spec=Response) response.ok = True response.entity = snapshot_model client.get_snapshot_info = MagicMock( return_value=response) behavior = VolumesAPI_Behaviors(client, config) resp = behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout) self.assertIsNone(resp)
def test_good_response_code_bad_status(self): client, config, snapshot_model, response = self.get_mocks() behavior = VolumesAPI_Behaviors(client, config) resp = behavior.wait_for_snapshot_status( self.defaults.snapshot_name, self.defaults.expected_status, self.defaults.timeout, poll_rate=self.defaults.poll_rate) self.assertIsNone(resp)