"Fossies" - the Fresh Open Source Software Archive

Member "horizon-14.0.4/openstack_dashboard/dashboards/project/vg_snapshots/tests.py" (22 Oct 2019, 8730 Bytes) of package /linux/misc/openstack/horizon-14.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    2 #    not use this file except in compliance with the License. You may obtain
    3 #    a copy of the License at
    4 #
    5 #         http://www.apache.org/licenses/LICENSE-2.0
    6 #
    7 #    Unless required by applicable law or agreed to in writing, software
    8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   10 #    License for the specific language governing permissions and limitations
   11 #    under the License.
   12 
   13 from django.urls import reverse
   14 import mock
   15 
   16 from openstack_dashboard.api import cinder
   17 from openstack_dashboard.test import helpers as test
   18 
   19 
   20 INDEX_URL = reverse('horizon:project:vg_snapshots:index')
   21 
   22 
   23 class GroupSnapshotTests(test.TestCase):
   24     @mock.patch.object(cinder, 'group_snapshot_get')
   25     @mock.patch.object(cinder, 'group_create_from_source')
   26     def test_create_group_from_snapshot(self,
   27                                         mock_group_create_from_source,
   28                                         mock_group_snapshot_get):
   29         group = self.cinder_groups.first()
   30         vg_snapshot = self.cinder_group_snapshots.first()
   31         formData = {'vg_snapshot_id': vg_snapshot.id,
   32                     'name': 'test VG SS Create',
   33                     'description': 'test desc'}
   34 
   35         mock_group_snapshot_get.return_value = vg_snapshot
   36         mock_group_create_from_source.return_value = group
   37 
   38         url = reverse('horizon:project:vg_snapshots:create_group',
   39                       args=[vg_snapshot.id])
   40         res = self.client.post(url, formData)
   41         self.assertNoFormErrors(res)
   42         self.assertRedirectsNoFollow(
   43             res, reverse('horizon:project:volume_groups:index'))
   44 
   45         mock_group_snapshot_get.assert_called_once_with(
   46             test.IsHttpRequest(), vg_snapshot.id)
   47         mock_group_create_from_source.assert_called_once_with(
   48             test.IsHttpRequest(),
   49             formData['name'],
   50             group_snapshot_id=formData['vg_snapshot_id'],
   51             description=formData['description'])
   52 
   53     @mock.patch.object(cinder, 'group_snapshot_get')
   54     @mock.patch.object(cinder, 'group_create_from_source')
   55     def test_create_group_from_snapshot_exception(
   56             self,
   57             mock_group_create_from_source,
   58             mock_group_snapshot_get):
   59         vg_snapshot = self.cinder_group_snapshots.first()
   60         new_cg_name = 'test VG SS Create'
   61         formData = {'vg_snapshot_id': vg_snapshot.id,
   62                     'name': new_cg_name,
   63                     'description': 'test desc'}
   64 
   65         mock_group_snapshot_get.return_value = vg_snapshot
   66         mock_group_create_from_source.side_effect = \
   67             self.exceptions.cinder
   68 
   69         url = reverse('horizon:project:vg_snapshots:create_group',
   70                       args=[vg_snapshot.id])
   71         res = self.client.post(url, formData)
   72         self.assertNoFormErrors(res)
   73         # There are a bunch of backslashes for formatting in the message from
   74         # the response, so remove them when validating the error message.
   75         self.assertIn('Unable to create group "%s" from snapshot.'
   76                       % new_cg_name,
   77                       res.cookies.output().replace('\\', ''))
   78         self.assertRedirectsNoFollow(res, INDEX_URL)
   79 
   80         mock_group_snapshot_get.assert_called_once_with(
   81             test.IsHttpRequest(), vg_snapshot.id)
   82         mock_group_create_from_source.assert_called_once_with(
   83             test.IsHttpRequest(),
   84             formData['name'],
   85             group_snapshot_id=formData['vg_snapshot_id'],
   86             description=formData['description'])
   87 
   88     @mock.patch.object(cinder, 'group_snapshot_list')
   89     @mock.patch.object(cinder, 'group_snapshot_delete')
   90     @mock.patch.object(cinder, 'group_list')
   91     def test_delete_group_snapshot(self,
   92                                    mock_group_list,
   93                                    mock_group_snapshot_delete,
   94                                    mock_group_snapshot_list):
   95         vg_snapshots = self.cinder_group_snapshots.list()
   96         vg_snapshot = self.cinder_group_snapshots.first()
   97 
   98         mock_group_snapshot_list.return_value = vg_snapshots
   99         mock_group_snapshot_delete.return_value = None
  100         mock_group_list.return_value = self.cinder_groups.list()
  101 
  102         form_data = {'action': 'volume_vg_snapshots__delete_vg_snapshot__%s'
  103                      % vg_snapshot.id}
  104         res = self.client.post(INDEX_URL, form_data, follow=True)
  105         self.assertEqual(res.status_code, 200)
  106         self.assertIn("Scheduled deletion of Snapshot: %s" % vg_snapshot.name,
  107                       [m.message for m in res.context['messages']])
  108 
  109         self.assert_mock_multiple_calls_with_same_arguments(
  110             mock_group_snapshot_list, 2,
  111             mock.call(test.IsHttpRequest()))
  112         mock_group_snapshot_delete.assert_called_once_with(
  113             test.IsHttpRequest(), vg_snapshot.id)
  114         self.assert_mock_multiple_calls_with_same_arguments(
  115             mock_group_list, 2,
  116             mock.call(test.IsHttpRequest()))
  117 
  118     @mock.patch.object(cinder, 'group_snapshot_list')
  119     @mock.patch.object(cinder, 'group_snapshot_delete')
  120     @mock.patch.object(cinder, 'group_list')
  121     def test_delete_group_snapshot_exception(self,
  122                                              mock_group_list,
  123                                              mock_group_snapshot_delete,
  124                                              mock_group_snapshot_list):
  125         vg_snapshots = self.cinder_group_snapshots.list()
  126         vg_snapshot = self.cinder_group_snapshots.first()
  127 
  128         mock_group_snapshot_list.return_value = vg_snapshots
  129         mock_group_snapshot_delete.side_effect = self.exceptions.cinder
  130         mock_group_list.return_value = self.cinder_groups.list()
  131 
  132         form_data = {'action': 'volume_vg_snapshots__delete_vg_snapshot__%s'
  133                      % vg_snapshot.id}
  134         res = self.client.post(INDEX_URL, form_data, follow=True)
  135         self.assertEqual(res.status_code, 200)
  136         self.assertIn("Unable to delete snapshot: %s" % vg_snapshot.name,
  137                       [m.message for m in res.context['messages']])
  138 
  139         self.assert_mock_multiple_calls_with_same_arguments(
  140             mock_group_snapshot_list, 2,
  141             mock.call(test.IsHttpRequest()))
  142         mock_group_snapshot_delete.assert_called_once_with(
  143             test.IsHttpRequest(), vg_snapshot.id)
  144         self.assert_mock_multiple_calls_with_same_arguments(
  145             mock_group_list, 2,
  146             mock.call(test.IsHttpRequest()))
  147 
  148     @mock.patch.object(cinder, 'group_snapshot_get')
  149     @mock.patch.object(cinder, 'group_get')
  150     @mock.patch.object(cinder, 'volume_type_get')
  151     @mock.patch.object(cinder, 'volume_list')
  152     def test_detail_view(self,
  153                          mock_volume_list,
  154                          mock_volume_type_get,
  155                          mock_group_get,
  156                          mock_group_snapshot_get):
  157         vg_snapshot = self.cinder_group_snapshots.first()
  158         group = self.cinder_groups.first()
  159         volume_type = self.cinder_volume_types.first()
  160         volumes = self.cinder_volumes.list()
  161 
  162         mock_group_snapshot_get.return_value = vg_snapshot
  163         mock_group_get.return_value = group
  164         mock_volume_type_get.return_value = volume_type
  165         mock_volume_list.return_value = volumes
  166 
  167         url = reverse(
  168             'horizon:project:vg_snapshots:detail',
  169             args=[vg_snapshot.id])
  170         res = self.client.get(url)
  171         self.assertNoFormErrors(res)
  172         self.assertEqual(res.status_code, 200)
  173 
  174         mock_group_snapshot_get.assert_called_once_with(
  175             test.IsHttpRequest(), vg_snapshot.id)
  176         mock_group_get.assert_called_once_with(
  177             test.IsHttpRequest(), group.id)
  178         mock_volume_type_get.assert_called_once_with(
  179             test.IsHttpRequest(), volume_type.id)
  180         search_opts = {'group_id': group.id}
  181         mock_volume_list.assert_called_once_with(
  182             test.IsHttpRequest(), search_opts=search_opts)
  183 
  184     @mock.patch.object(cinder, 'group_snapshot_get')
  185     def test_detail_view_with_exception(self, mock_group_snapshot_get):
  186         vg_snapshot = self.cinder_group_snapshots.first()
  187 
  188         mock_group_snapshot_get.side_effect = self.exceptions.cinder
  189 
  190         url = reverse(
  191             'horizon:project:vg_snapshots:detail',
  192             args=[vg_snapshot.id])
  193         res = self.client.get(url)
  194         self.assertNoFormErrors(res)
  195         self.assertRedirectsNoFollow(res, INDEX_URL)
  196 
  197         mock_group_snapshot_get.assert_called_once_with(
  198             test.IsHttpRequest(), vg_snapshot.id)