Functional tests for Blacklists

Change-Id: I79fe267a8d80208b3e71a64a78ffca47fc71b164
Depends-On: Ie1bb259e7e683081f0ad127617acc8deb98467c0
This commit is contained in:
Endre Karlson 2015-05-18 15:56:53 +02:00
parent 77db137bfd
commit 8d7fdac946
4 changed files with 199 additions and 2 deletions

View File

@ -0,0 +1,53 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Author: Endre Karlson <endre.karlson@hp.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from functionaltests.api.v2.models.blacklist_model import BlacklistModel
from functionaltests.api.v2.models.blacklist_model import BlacklistListModel
from functionaltests.common.client import ClientMixin
class BlacklistClient(ClientMixin):
@classmethod
def blacklists_uri(cls):
return "/v2/blacklists"
@classmethod
def blacklist_uri(cls, blacklist_id):
return "{0}/{1}".format(cls.blacklists_uri(), blacklist_id)
def list_blacklists(self, **kwargs):
resp, body = self.client.get(self.blacklists_uri(), **kwargs)
return self.deserialize(resp, body, BlacklistListModel)
def get_blacklist(self, blacklist_id, **kwargs):
resp, body = self.client.get(self.blacklist_uri(blacklist_id))
return self.deserialize(resp, body, BlacklistModel)
def post_blacklist(self, blacklist_model, **kwargs):
resp, body = self.client.post(
self.blacklists_uri(),
body=blacklist_model.to_json(), **kwargs)
return self.deserialize(resp, body, BlacklistModel)
def patch_blacklist(self, blacklist_id, blacklist_model, **kwargs):
resp, body = self.client.patch(
self.blacklist_uri(blacklist_id),
body=blacklist_model.to_json(), **kwargs)
return self.deserialize(resp, body, BlacklistModel)
def delete_blacklist(self, blacklist_id, **kwargs):
return self.client.delete(self.blacklist_uri(blacklist_id), **kwargs)

View File

@ -0,0 +1,33 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Author: Endre Karlson <endre.karlson@hp.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from functionaltests.common.models import BaseModel
from functionaltests.common.models import CollectionModel
from functionaltests.common.models import EntityModel
class BlacklistData(BaseModel):
pass
class BlacklistModel(EntityModel):
ENTITY_NAME = 'blacklist'
MODEL_TYPE = BlacklistData
class BlacklistListModel(CollectionModel):
COLLECTION_NAME = 'blacklists'
MODEL_TYPE = BlacklistData

View File

@ -0,0 +1,103 @@
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Author: Endre Karlson <endre.karlson@hp.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from tempest_lib import exceptions
from functionaltests.common import datagen
from functionaltests.api.v2.base import DesignateV2Test
from functionaltests.api.v2.clients.blacklist_client import BlacklistClient
class BlacklistTest(DesignateV2Test):
def _create_blacklist(self, blacklist_model, user='admin'):
resp, model = BlacklistClient.as_user(user).post_blacklist(
blacklist_model)
self.assertEqual(resp.status, 201)
return resp, model
def test_list_blacklists(self):
self._create_blacklist(datagen.random_blacklist_data())
resp, model = BlacklistClient.as_user('admin').list_blacklists()
self.assertEqual(resp.status, 200)
self.assertGreater(len(model.blacklists), 0)
def test_create_blacklist(self):
self._create_blacklist(datagen.random_blacklist_data(), user='admin')
def test_update_blacklist(self):
post_model = datagen.random_blacklist_data()
resp, old_model = self._create_blacklist(post_model)
patch_model = datagen.random_blacklist_data()
resp, new_model = BlacklistClient.as_user('admin').patch_blacklist(
old_model.id, patch_model)
self.assertEqual(resp.status, 200)
resp, model = BlacklistClient.as_user('admin').get_blacklist(
new_model.id)
self.assertEqual(resp.status, 200)
self.assertEqual(new_model.id, old_model.id)
self.assertEqual(new_model.pattern, model.pattern)
def test_delete_blacklist(self):
resp, model = self._create_blacklist(datagen.random_blacklist_data())
resp, model = BlacklistClient.as_user('admin').delete_blacklist(
model.id)
self.assertEqual(resp.status, 204)
def test_get_blacklist_404(self):
client = BlacklistClient.as_user('admin')
self._assert_exception(
exceptions.NotFound,
'blacklist_not_found',
404, client.get_blacklist,
str(uuid.uuid4()))
def test_update_blacklist_404(self):
model = datagen.random_blacklist_data()
client = BlacklistClient.as_user('admin')
self._assert_exception(
exceptions.NotFound,
'blacklist_not_found',
404,
client.patch_blacklist,
str(uuid.uuid4()), model)
def test_delete_blacklist_404(self):
client = BlacklistClient.as_user('admin')
self._assert_exception(
exceptions.NotFound,
'blacklist_not_found',
404,
client.delete_blacklist,
str(uuid.uuid4()))
def test_get_blacklist_invalid_uuid(self):
client = BlacklistClient.as_user('admin')
self._assert_invalid_uuid(client.get_blacklist, 'fooo')
def test_update_blacklist_invalid_uuid(self):
model = datagen.random_blacklist_data()
client = BlacklistClient.as_user('admin')
self._assert_invalid_uuid(client.patch_blacklist, 'fooo', model)
def test_delete_blacklist_invalid_uuid(self):
client = BlacklistClient.as_user('admin')
self._assert_invalid_uuid(client.get_blacklist, 'fooo')

View File

@ -16,9 +16,10 @@ limitations under the License.
import random import random
from functionaltests.api.v2.models.zone_model import ZoneModel from functionaltests.api.v2.models.blacklist_model import BlacklistModel
from functionaltests.api.v2.models.recordset_model import RecordsetModel
from functionaltests.api.v2.models.pool_model import PoolModel from functionaltests.api.v2.models.pool_model import PoolModel
from functionaltests.api.v2.models.recordset_model import RecordsetModel
from functionaltests.api.v2.models.zone_model import ZoneModel
def random_ip(): def random_ip():
@ -109,6 +110,13 @@ def random_mx_recordset(zone_name, pref=None, host=None, **kwargs):
return random_recordset_data('MX', zone_name, records=[data], **kwargs) return random_recordset_data('MX', zone_name, records=[data], **kwargs)
def random_blacklist_data():
data = {
"pattern": random_string()
}
return BlacklistModel.from_dict(data)
def random_pool_data(): def random_pool_data():
ns_zone = random_zone_data().name ns_zone = random_zone_data().name
data = { data = {