Add functional tests for TLDs
Change-Id: Ic5c25f40cf19d0f1915f89698468090bf6eb743b
This commit is contained in:
parent
37fdb05bd1
commit
5813493932
@ -14,19 +14,18 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
from tempest_lib import exceptions
|
||||
from oslo_config import cfg
|
||||
from tempest_lib import exceptions
|
||||
|
||||
from functionaltests.api.v2.clients.quotas_client import QuotasClient
|
||||
from functionaltests.api.v2.clients.tld_client import TLDClient
|
||||
from functionaltests.api.v2.models.quotas_model import QuotasModel
|
||||
from functionaltests.api.v2.models.tld_model import TLDModel
|
||||
from functionaltests.common.base import BaseDesignateTest
|
||||
|
||||
|
||||
class DesignateV2Test(BaseDesignateTest):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DesignateV2Test, self).__init__(*args, **kwargs)
|
||||
|
||||
def increase_quotas(self, user):
|
||||
if cfg.CONF.testconfig.no_admin_setup:
|
||||
return
|
||||
@ -39,6 +38,15 @@ class DesignateV2Test(BaseDesignateTest):
|
||||
'zone_records': 9999999,
|
||||
'zone_recordsets': 9999999}}))
|
||||
|
||||
def ensure_tld_exists(self, tld='com'):
|
||||
if cfg.CONF.testconfig.no_admin_setup:
|
||||
return
|
||||
try:
|
||||
tld_model = TLDModel.from_dict({'name': tld})
|
||||
TLDClient.as_user('admin').post_tld(tld_model)
|
||||
except exceptions.Conflict:
|
||||
pass
|
||||
|
||||
def _assert_invalid_uuid(self, method, *args, **kw):
|
||||
"""
|
||||
Test that UUIDs used in the URL is valid.
|
||||
|
53
functionaltests/api/v2/clients/tld_client.py
Normal file
53
functionaltests/api/v2/clients/tld_client.py
Normal 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.tld_model import TLDModel
|
||||
from functionaltests.api.v2.models.tld_model import TLDListModel
|
||||
from functionaltests.common.client import ClientMixin
|
||||
|
||||
|
||||
class TLDClient(ClientMixin):
|
||||
|
||||
@classmethod
|
||||
def tlds_uri(cls):
|
||||
return "/v2/tlds"
|
||||
|
||||
@classmethod
|
||||
def tld_uri(cls, tld_id):
|
||||
return "{0}/{1}".format(cls.tlds_uri(), tld_id)
|
||||
|
||||
def list_tlds(self, **kwargs):
|
||||
resp, body = self.client.get(self.tlds_uri(), **kwargs)
|
||||
return self.deserialize(resp, body, TLDListModel)
|
||||
|
||||
def get_tld(self, tld_id, **kwargs):
|
||||
resp, body = self.client.get(self.tld_uri(tld_id))
|
||||
return self.deserialize(resp, body, TLDModel)
|
||||
|
||||
def post_tld(self, tld_model, **kwargs):
|
||||
resp, body = self.client.post(
|
||||
self.tlds_uri(),
|
||||
body=tld_model.to_json(), **kwargs)
|
||||
return self.deserialize(resp, body, TLDModel)
|
||||
|
||||
def patch_tld(self, tld_id, tld_model, **kwargs):
|
||||
resp, body = self.client.patch(
|
||||
self.tld_uri(tld_id),
|
||||
body=tld_model.to_json(), **kwargs)
|
||||
return self.deserialize(resp, body, TLDModel)
|
||||
|
||||
def delete_tld(self, tld_id, **kwargs):
|
||||
return self.client.delete(self.tld_uri(tld_id), **kwargs)
|
@ -22,6 +22,7 @@ from tempest_lib.exceptions import NotFound
|
||||
from functionaltests.api.v2.clients.blacklist_client import BlacklistClient
|
||||
from functionaltests.api.v2.clients.pool_client import PoolClient
|
||||
from functionaltests.api.v2.clients.recordset_client import RecordsetClient
|
||||
from functionaltests.api.v2.clients.tld_client import TLDClient
|
||||
from functionaltests.api.v2.clients.zone_client import ZoneClient
|
||||
from functionaltests.api.v2.clients.zone_import_client import ZoneImportClient
|
||||
from functionaltests.api.v2.clients.zone_export_client import ZoneExportClient
|
||||
@ -233,3 +234,28 @@ class BlacklistFixture(fixtures.Fixture):
|
||||
client.delete_blacklist(blacklist_id)
|
||||
except NotFound:
|
||||
pass
|
||||
|
||||
|
||||
class TLDFixture(fixtures.Fixture):
|
||||
|
||||
def __init__(self, post_model=None, user='admin'):
|
||||
super(TLDFixture, self).__init__()
|
||||
self.post_model = post_model or datagen.random_tld_data()
|
||||
self.user = user
|
||||
|
||||
def _setUp(self):
|
||||
super(TLDFixture, self)._setUp()
|
||||
self._create_tld()
|
||||
|
||||
def _create_tld(self):
|
||||
client = TLDClient.as_user(self.user)
|
||||
self.post_resp, self.created_tld = client.post_tld(self.post_model)
|
||||
assert self.post_resp.status == 201
|
||||
self.addCleanup(self.cleanup_tld, client, self.created_tld.id)
|
||||
|
||||
@classmethod
|
||||
def cleanup_tld(cls, client, tld_id):
|
||||
try:
|
||||
client.delete_tld(tld_id)
|
||||
except NotFound:
|
||||
pass
|
||||
|
33
functionaltests/api/v2/models/tld_model.py
Normal file
33
functionaltests/api/v2/models/tld_model.py
Normal 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 TLDData(BaseModel):
|
||||
pass
|
||||
|
||||
|
||||
class TLDModel(EntityModel):
|
||||
ENTITY_NAME = 'tld'
|
||||
MODEL_TYPE = TLDData
|
||||
|
||||
|
||||
class TLDListModel(CollectionModel):
|
||||
COLLECTION_NAME = 'tlds'
|
||||
MODEL_TYPE = TLDData
|
@ -75,6 +75,7 @@ class RecordsetTest(DesignateV2Test):
|
||||
def setUp(self):
|
||||
super(RecordsetTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.ensure_tld_exists('com')
|
||||
self.zone = self.useFixture(ZoneFixture()).created_zone
|
||||
|
||||
def test_list_recordsets(self):
|
||||
@ -200,6 +201,7 @@ class RecordsetOwnershipTest(DesignateV2Test):
|
||||
super(RecordsetOwnershipTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.increase_quotas(user='alt')
|
||||
self.ensure_tld_exists('com')
|
||||
|
||||
def test_no_create_recordset_by_alt_tenant(self):
|
||||
zone = self.useFixture(ZoneFixture(user='default')).created_zone
|
||||
|
@ -29,6 +29,7 @@ class RecordsetTest(DesignateV2Test):
|
||||
def setUp(self):
|
||||
super(RecordsetTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.ensure_tld_exists('com')
|
||||
resp, self.zone = ZoneClient.as_user('default').post_zone(
|
||||
datagen.random_zone_data())
|
||||
ZoneClient.as_user('default').wait_for_zone(self.zone.id)
|
||||
|
95
functionaltests/api/v2/test_tld.py
Normal file
95
functionaltests/api/v2/test_tld.py
Normal file
@ -0,0 +1,95 @@
|
||||
# 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.tld_client import TLDClient
|
||||
from functionaltests.api.v2.fixtures import TLDFixture
|
||||
|
||||
|
||||
class TLDTest(DesignateV2Test):
|
||||
|
||||
def setUp(self):
|
||||
super(TLDTest, self).setUp()
|
||||
self.ensure_tld_exists('com')
|
||||
self.client = TLDClient.as_user('admin')
|
||||
self.fixture = self.useFixture(TLDFixture())
|
||||
|
||||
def test_list_tlds(self):
|
||||
resp, model = self.client.list_tlds()
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertGreater(len(model.tlds), 0)
|
||||
|
||||
def test_create_tld(self):
|
||||
self.assertEqual(self.fixture.post_resp.status, 201)
|
||||
resp, tld = self.client.get_tld(self.fixture.created_tld.id)
|
||||
self.assertEqual(resp.status, 200)
|
||||
|
||||
self.assertEqual(tld.name, self.fixture.created_tld.name)
|
||||
self.assertEqual(tld.id, self.fixture.created_tld.id)
|
||||
self.assertEqual(tld.created_at, self.fixture.created_tld.created_at)
|
||||
self.assertEqual(tld.updated_at, self.fixture.created_tld.updated_at)
|
||||
self.assertEqual(tld.description, self.fixture.created_tld.description)
|
||||
|
||||
def test_update_tld(self):
|
||||
old_model = self.fixture.created_tld
|
||||
|
||||
patch_model = datagen.random_tld_data()
|
||||
resp, new_model = self.client.patch_tld(old_model.id, patch_model)
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertEqual(new_model.id, old_model.id)
|
||||
self.assertEqual(new_model.name, patch_model.name)
|
||||
|
||||
resp, new_model = self.client.get_tld(new_model.id)
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertEqual(new_model.id, old_model.id)
|
||||
self.assertEqual(new_model.name, patch_model.name)
|
||||
|
||||
def test_delete_tld(self):
|
||||
resp, model = self.client.delete_tld(self.fixture.created_tld.id)
|
||||
self.assertEqual(resp.status, 204)
|
||||
self.assertRaises(exceptions.NotFound, self.client.get_tld,
|
||||
self.fixture.created_tld.id)
|
||||
|
||||
def test_get_tld_404(self):
|
||||
self._assert_exception(
|
||||
exceptions.NotFound, 'tld_not_found', 404, self.client.get_tld,
|
||||
str(uuid.uuid4()))
|
||||
|
||||
def test_update_tld_404(self):
|
||||
model = datagen.random_tld_data()
|
||||
self._assert_exception(
|
||||
exceptions.NotFound, 'tld_not_found', 404, self.client.patch_tld,
|
||||
str(uuid.uuid4()), model)
|
||||
|
||||
def test_delete_tld_404(self):
|
||||
self._assert_exception(
|
||||
exceptions.NotFound, 'tld_not_found', 404, self.client.delete_tld,
|
||||
str(uuid.uuid4()))
|
||||
|
||||
def test_get_tld_invalid_uuid(self):
|
||||
self._assert_invalid_uuid(self.client.get_tld, 'fooo')
|
||||
|
||||
def test_update_tld_invalid_uuid(self):
|
||||
model = datagen.random_tld_data()
|
||||
self._assert_invalid_uuid(self.client.patch_tld, 'fooo', model)
|
||||
|
||||
def test_delete_tld_invalid_uuid(self):
|
||||
self._assert_invalid_uuid(self.client.get_tld, 'fooo')
|
@ -35,6 +35,7 @@ class ZoneTest(DesignateV2Test):
|
||||
def setUp(self):
|
||||
super(ZoneTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.ensure_tld_exists('com')
|
||||
self.fixture = self.useFixture(ZoneFixture(user='default'))
|
||||
|
||||
def test_list_zones(self):
|
||||
@ -75,6 +76,7 @@ class ZoneOwnershipTest(DesignateV2Test):
|
||||
super(ZoneTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.increase_quotas(user='alt')
|
||||
self.ensure_tld_exists('com')
|
||||
|
||||
def test_no_create_duplicate_domain(self):
|
||||
post_model = self.useFixture(ZoneFixture(user='default')).post_model
|
||||
@ -105,6 +107,7 @@ class ZoneImportTest(DesignateV2Test):
|
||||
def setUp(self):
|
||||
super(ZoneImportTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.ensure_tld_exists('com')
|
||||
|
||||
def test_import_domain(self):
|
||||
user = 'default'
|
||||
@ -134,6 +137,7 @@ class ZoneExportTest(DesignateV2Test):
|
||||
def setUp(self):
|
||||
super(ZoneExportTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.ensure_tld_exists('com')
|
||||
|
||||
def test_export_domain(self):
|
||||
user = 'default'
|
||||
|
@ -34,6 +34,7 @@ class TransferZoneOwnerShipTest(DesignateV2Test):
|
||||
super(TransferZoneOwnerShipTest, self).setUp()
|
||||
self.increase_quotas(user='default')
|
||||
self.increase_quotas(user='alt')
|
||||
self.ensure_tld_exists('com')
|
||||
self.zone = self.useFixture(ZoneFixture()).created_zone
|
||||
|
||||
def test_list_transfer_requests(self):
|
||||
|
@ -24,6 +24,7 @@ from functionaltests.api.v2.models.transfer_accepts_model import \
|
||||
TransferAcceptsModel
|
||||
from functionaltests.api.v2.models.recordset_model import RecordsetModel
|
||||
from functionaltests.api.v2.models.zone_model import ZoneModel
|
||||
from functionaltests.api.v2.models.tld_model import TLDModel
|
||||
|
||||
|
||||
def random_ip():
|
||||
@ -213,3 +214,10 @@ def random_sshfp_recordset(zone_name, algorithm_number=None,
|
||||
def random_txt_recordset(zone_name, data=None, **kwargs):
|
||||
data = data or "v=spf1 +all"
|
||||
return random_recordset_data('TXT', zone_name, records=[data], **kwargs)
|
||||
|
||||
|
||||
def random_tld_data():
|
||||
data = {
|
||||
"name": random_string(prefix='tld')
|
||||
}
|
||||
return TLDModel.from_dict(data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user