Added test cases for designate v1 client
This patch adds test cases for domains and records modules of designate v1 client. Change-Id: I4b4d8671041193ddbaccb10947bb21f5d626fb92
This commit is contained in:
parent
86d988d56f
commit
9d3da6c31f
@ -13,8 +13,41 @@
|
||||
# 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 designateclient.tests import base
|
||||
|
||||
|
||||
class CrudMixin(object):
|
||||
path_prefix = None
|
||||
|
||||
def new_ref(self, **kwargs):
|
||||
kwargs.setdefault('id', uuid.uuid4().hex)
|
||||
return kwargs
|
||||
|
||||
def stub_entity(self, method, parts=None, entity=None, id=None, **kwargs):
|
||||
if entity:
|
||||
kwargs['json'] = entity
|
||||
|
||||
if not parts:
|
||||
parts = [self.RESOURCE]
|
||||
|
||||
if self.path_prefix:
|
||||
parts.insert(0, self.path_prefix)
|
||||
|
||||
if id:
|
||||
if not parts:
|
||||
parts = []
|
||||
|
||||
parts.append(id)
|
||||
|
||||
self.stub_url(method, parts=parts, **kwargs)
|
||||
|
||||
def assertList(self, expected, actual):
|
||||
self.assertEqual(len(expected), len(actual))
|
||||
for i in expected:
|
||||
self.assertTrue(i in actual)
|
||||
|
||||
|
||||
class APIV1TestCase(base.APITestCase):
|
||||
VERSION = "1"
|
||||
|
102
designateclient/tests/test_v1/test_domain.py
Normal file
102
designateclient/tests/test_v1/test_domain.py
Normal file
@ -0,0 +1,102 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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 mock import patch
|
||||
|
||||
from designateclient.tests import test_v1
|
||||
from designateclient import utils
|
||||
from designateclient.v1 import domains
|
||||
from designateclient import warlock
|
||||
|
||||
Domain = warlock.model_factory(utils.load_schema('v1', 'domain'))
|
||||
|
||||
|
||||
class TestDomain(test_v1.APIV1TestCase, test_v1.CrudMixin):
|
||||
RESOURCE = 'domains'
|
||||
|
||||
def new_ref(self, **kwargs):
|
||||
ref = super(TestDomain, self).new_ref(**kwargs)
|
||||
ref.setdefault("name", uuid.uuid4().hex)
|
||||
ref.setdefault("email", "abc@example.com.")
|
||||
ref.setdefault("ttl", 3600)
|
||||
return ref
|
||||
|
||||
def test_create(self):
|
||||
ref = {"id": "89acac79-38e7-497d-807c-a011e1310438",
|
||||
"name": "domain1.com.",
|
||||
"email": "nsadmin@example.org",
|
||||
"ttl": 60}
|
||||
self.stub_url("POST", parts=[self.RESOURCE], json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.domains.create(values["name"])
|
||||
|
||||
def test_list(self):
|
||||
items = [
|
||||
self.new_ref(email="abc@example.org",
|
||||
id="89acac79-38e7-497d-807c-a011e1310438"),
|
||||
self.new_ref(email="root@example.org",
|
||||
id="89acac79-38e7-497d-807c-a011e1310435")
|
||||
]
|
||||
|
||||
self.stub_url("GET", parts=[self.RESOURCE], json={"domains": items})
|
||||
|
||||
listed = self.client.domains.list()
|
||||
self.assertList(items, listed)
|
||||
self.assertQueryStringIs("")
|
||||
|
||||
def test_get(self):
|
||||
ref = self.new_ref(email="abc@example.org",
|
||||
id="89acac79-38e7-497d-807c-a011e1310438")
|
||||
|
||||
self.stub_entity("GET", entity=ref, id=ref["id"])
|
||||
|
||||
response = self.client.domains.get(ref["id"])
|
||||
self.assertEqual(ref, response)
|
||||
|
||||
def test_delete(self):
|
||||
ref = self.new_ref(email="abc@example.org",
|
||||
id="89acac79-38e7-497d-807c-a011e1310438")
|
||||
|
||||
self.stub_entity("DELETE", entity=ref, id=ref["id"])
|
||||
|
||||
self.client.domains.delete(ref["id"])
|
||||
self.assertRequestBodyIs(None)
|
||||
|
||||
def test_update(self):
|
||||
ref = self.new_ref(id="89acac79-38e7-497d-807c-a011e1310438")
|
||||
|
||||
self.stub_entity("PUT", entity=ref, id=ref["id"])
|
||||
|
||||
values = ref.copy()
|
||||
|
||||
self.client.domains.update(Domain(values))
|
||||
|
||||
@patch.object(domains.DomainsController, "list_domain_servers")
|
||||
def test_list_domain_servers(self, domains_get):
|
||||
domains_get.return_value = [{"id": "foo", "name": "ns1.example.com."}]
|
||||
|
||||
ref = [{
|
||||
"id": "foo",
|
||||
"name": "ns1.example.com.",
|
||||
}]
|
||||
parts = ["domains", "foo", "servers"]
|
||||
self.stub_url("GET", parts=parts, json={"servers": ref})
|
||||
|
||||
response = self.client.domains.list_domain_servers("foo")
|
||||
self.assertEqual(ref, response)
|
222
designateclient/tests/test_v1/test_records.py
Normal file
222
designateclient/tests/test_v1/test_records.py
Normal file
@ -0,0 +1,222 @@
|
||||
# Copyright 2015 NEC Corporation. All rights reserved.
|
||||
#
|
||||
# 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 designateclient.tests import test_v1
|
||||
from designateclient import utils
|
||||
from designateclient import warlock
|
||||
|
||||
|
||||
Record = warlock.model_factory(utils.load_schema('v1', 'record'))
|
||||
|
||||
DOMAIN = {
|
||||
"id": str(uuid.uuid4()),
|
||||
"name": "example.com."
|
||||
}
|
||||
|
||||
|
||||
class TestRecords(test_v1.APIV1TestCase, test_v1.CrudMixin):
|
||||
RESOURCE = 'records'
|
||||
|
||||
def new_ref(self, **kwargs):
|
||||
ref = super(TestRecords, self).new_ref(**kwargs)
|
||||
ref.setdefault("name", uuid.uuid4().hex)
|
||||
ref.setdefault("type", "A")
|
||||
ref.setdefault("data", "10.0.0.1")
|
||||
return ref
|
||||
|
||||
def test_create_record(self):
|
||||
ref = self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_AAAA_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778888",
|
||||
type="AAAA",
|
||||
data="2001:db8:0:1234:0:5678:9:12")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_MX_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778989",
|
||||
type="MX",
|
||||
data="mail.example.com.",
|
||||
priority=10)
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_CNAME_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778890",
|
||||
type="CNAME",
|
||||
data="example.com.")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_TXT_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778889",
|
||||
type="TXT",
|
||||
data="This is a TXT record")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_SRV_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778888",
|
||||
type="SRV",
|
||||
data="0 5060 sip.example.com.",
|
||||
priority=30)
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_NS_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677779999",
|
||||
type="NS",
|
||||
data="ns1.example.com.")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_PTR_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778891",
|
||||
type="PTR",
|
||||
data="www.example.com.")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_SPF_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778899",
|
||||
type="SPF",
|
||||
data="v=spf1 +mx a:colo.example.com/28 -all")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_create_SSHFP_record(self):
|
||||
ref = self.new_ref(id="11112222-3333-4444-5555-666677778888",
|
||||
type="SSHFP",
|
||||
data="2 1 6c3c958af43d953f91f40e0d84157f4fe7b4a898")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("POST", parts=parts, json=ref)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.create(DOMAIN['id'], Record(values))
|
||||
self.assertRequestBodyIs(json=values)
|
||||
|
||||
def test_get(self):
|
||||
ref = self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_entity("GET", entity=ref, id=ref["id"], parts=parts)
|
||||
|
||||
response = self.client.records.get(DOMAIN["id"], ref["id"])
|
||||
self.assertEqual(ref, response)
|
||||
|
||||
def test_list(self):
|
||||
items = [
|
||||
self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad"),
|
||||
self.new_ref(id="11112222-3333-4444-5555-666677778888")
|
||||
]
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_url("GET", parts=parts, json={"records": items})
|
||||
|
||||
listed = self.client.records.list(DOMAIN["id"])
|
||||
self.assertList(items, listed)
|
||||
self.assertQueryStringIs("")
|
||||
|
||||
def test_update(self):
|
||||
ref = self.new_ref(id="2e32e609-3a4f-45ba-bdef-e50eacd345ad",
|
||||
type="A",
|
||||
data="192.0.2.5")
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_entity("PUT", entity=ref, id=ref["id"], parts=parts)
|
||||
|
||||
values = ref.copy()
|
||||
del values["id"]
|
||||
|
||||
self.client.records.update(DOMAIN["id"], Record(ref))
|
||||
|
||||
def test_delete(self):
|
||||
ref = self.new_ref()
|
||||
|
||||
parts = ["domains", DOMAIN["id"], self.RESOURCE]
|
||||
self.stub_entity("DELETE", id=ref["id"], parts=parts)
|
||||
|
||||
self.client.records.delete(DOMAIN["id"], ref["id"])
|
||||
self.assertRequestBodyIs(None)
|
Loading…
Reference in New Issue
Block a user