def test_update_except_exception(self, mock_cinder, mock_exceptions):
        mock_cinder.volume_list.side_effect = Exception
        mock_cinder.volume_snapshot_list.side_effect = Exception
        volume_choice_field = fields.VolumeChoiceField(include_snapshots=True)
        volume_choice_field.choices = []
        volume_choice_field.update(self.request)

        expected_choices = [('', _('No volumes available'))]
        expected_calls = [
            mock.call(self.request['request'],
                      _('Unable to retrieve volume list.')),
            mock.call(self.request['request'],
                      _('Unable to retrieve snapshot list.'))
        ]
        self.assertEqual(expected_choices, volume_choice_field.choices)
        mock_exceptions.handle.assert_has_calls(expected_calls)
示例#2
0
    def test_update_withoutvolume(self, mock_cinder):
        foo_vol = mock.Mock()
        baz_snap = mock.Mock()
        foo_vol.configure_mock(name='foo_vol', id='foo_id', status='available')
        baz_snap.configure_mock(name='baz_snap',
                                id='baz_id',
                                status='available')
        mock_cinder.volume_list.return_value = [foo_vol]
        mock_cinder.volume_snapshot_list.return_value = [baz_snap]
        volume_choice_field = fields.VolumeChoiceField(include_volumes=False)
        volume_choice_field.choices = []
        volume_choice_field.update(self.request)

        expected_choices = [('', _('Select volume')), ('baz_id', 'baz_snap')]

        self.assertEqual(sorted(expected_choices),
                         sorted(volume_choice_field.choices))
示例#3
0
    def test_update_except_volume_list_exception(self, mock_cinder,
                                                 mock_exceptions):
        bar_snap = mock.Mock()
        bar_snap.configure_mock(name='bar_snap',
                                id='bar_id',
                                status='available')
        mock_cinder.volume_list.side_effect = Exception
        mock_cinder.volume_snapshot_list.return_value = [bar_snap]
        volume_choice_field = fields.VolumeChoiceField(include_volumes=True,
                                                       include_snapshots=True)
        volume_choice_field.choices = []
        volume_choice_field.update(self.request)

        expected_choices = [('', _('Select volume')), ('bar_id', 'bar_snap')]

        self.assertEqual(expected_choices, volume_choice_field.choices)
        mock_exceptions.handle.assert_called_once_with(
            self.request['request'], _('Unable to retrieve volume list.'))
    def test_update_except_snapshot_list_exception(self, mock_cinder,
                                                   mock_exceptions):
        foo_vol = mock.Mock()
        bar_vol = mock.Mock()
        foo_vol.configure_mock(name='foo_vol', id='foo_id', status='available')
        bar_vol.configure_mock(name='bar_vol', id='bar_id', status='error')
        mock_cinder.volume_list.return_value = [foo_vol]
        mock_cinder.volume_snapshot_list.side_effect = Exception
        volume_choice_field = fields.VolumeChoiceField(include_snapshots=True)
        volume_choice_field.choices = []
        volume_choice_field.update(self.request)

        expected_choices = [('', _('Select volume')), ('foo_id', 'foo_vol')]

        self.assertEqual(sorted(expected_choices),
                         sorted(volume_choice_field.choices))
        mock_exceptions.handle.assert_called_once_with(
            self.request['request'], _('Unable to retrieve snapshot list.'))