Beispiel #1
0
    def test_volume_create(self, cc):
        mock_body = '''{
            "size": "",
            "name": "",
            "description": "",
            "volume_type": "",
            "snapshot_id": "",
            "metadata": "",
            "image_id": "",
            "availability_zone": "",
            "source_volid": ""
        }'''

        mock_volume_create_response = {"size": ""}

        mock_post_response = '{"size": ""}'

        request = self.mock_rest_request(POST={}, body=mock_body)
        cc.volume_create.return_value = \
            mock.Mock(**{'to_dict.return_value': mock_volume_create_response})

        response = cinder.Volumes().post(request)

        self.assertStatusCode(response, 201)
        self.assertEqual(response.content.decode("utf-8"), mock_post_response)
Beispiel #2
0
    def _test_volumes_get(self, all, filters, cc):
        if all:
            request = self.mock_rest_request(GET={'all_projects': 'true'})
        else:
            request = self.mock_rest_request(**{'GET': filters})

        cc.volume_list_paged.return_value = [
            mock.Mock(**{'to_dict.return_value': {
                'id': 'test123'
            }}),
        ], False, False
        cc.Volume.return_value = mock.Mock(
            **{'to_dict.return_value': {
                "id": "test123"
            }})
        response = cinder.Volumes().get(request)
        self.assertStatusCode(response, 200)
        self.assertEqual(
            response.json, {
                "items": [{
                    "id": "test123"
                }],
                "has_more_data": False,
                "has_prev_data": False
            })
        if all:
            cc.volume_list_paged.assert_called_once_with(
                request, {'all_tenants': 1})
        else:
            cc.volume_list_paged.assert_called_once_with(request,
                                                         search_opts=filters)
Beispiel #3
0
    def _test_volumes_get(self, all_, filters):
        if all_:
            request = self.mock_rest_request(GET={'all_projects': 'true'})
        else:
            request = self.mock_rest_request(**{'GET': filters})

        volumes = [self.cinder_volumes.first()]
        self.maxDiff = None
        self.mock_volume_list_paged.return_value = volumes, False, False

        response = cinder.Volumes().get(request)

        self.assertStatusCode(response, 200)
        self.assertEqual(
            {
                'items': [v.to_dict() for v in volumes],
                'has_more_data': False,
                'has_prev_data': False
            }, response.json)
        if all_:
            self.mock_volume_list_paged.assert_called_once_with(
                request, {'all_tenants': 1})
        else:
            self.mock_volume_list_paged.assert_called_once_with(
                request, search_opts=filters)
Beispiel #4
0
 def _test_volumes_get(self, all, filters, cc):
     if all:
         request = self.mock_rest_request(GET={'all_projects': 'true'})
     else:
         request = self.mock_rest_request(**{'GET': filters})
     cc.volume_list.return_value = [
         mock.Mock(**{'to_dict.return_value': {
             'id': 'one'
         }}),
         mock.Mock(**{'to_dict.return_value': {
             'id': 'two'
         }}),
     ]
     response = cinder.Volumes().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.json,
                      {"items": [{
                          "id": "one"
                      }, {
                          "id": "two"
                      }]})
     if all:
         cc.volume_list.assert_called_once_with(request, {'all_tenants': 1})
     else:
         cc.volume_list.assert_called_once_with(request,
                                                search_opts=filters)
Beispiel #5
0
    def test_volume_create(self):
        mock_body = '''{
            "size": "",
            "name": "",
            "description": "",
            "volume_type": "",
            "snapshot_id": "",
            "metadata": "",
            "image_id": "",
            "availability_zone": "",
            "source_volid": ""
        }'''

        request = self.mock_rest_request(POST={}, body=mock_body)
        vol = self.cinder_volumes.first()
        self.mock_volume_create.return_value = vol

        response = cinder.Volumes().post(request)

        self.assertStatusCode(response, 201)
        self.assertEqual(vol.to_dict(), response.json)