Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Merge "Add misc unit and functional tests"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 14, 2016
2 parents 80812a9 + a8b472c commit ae84ae6
Show file tree
Hide file tree
Showing 23 changed files with 776 additions and 19 deletions.
6 changes: 3 additions & 3 deletions poppy/provider/akamai/http_policy_queue/http_policy_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

AKAMAI_OPTIONS = [
# queue backend configs
cfg.StrOpt(
'queue_backend_type',
help='SAN Cert Queueing backend'),
# cfg.StrOpt(
# 'queue_backend_type',
# help='HTTP policy queueing backend'),
cfg.ListOpt(
'queue_backend_host',
default=['localhost'],
Expand Down
1 change: 1 addition & 0 deletions tests/api/admin/test_service_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_check_imposed_limit_on_services(self, limit):
self.assertEqual(json.loads(resp.content)['limit'], limit)

def tearDown(self):
super(TestServiceLimits, self).tearDown()
for service in self.service_list:
self.service_limit_user_client.delete_service(location=service)
self.service_limit_user_client.wait_for_service_delete(
Expand Down
21 changes: 21 additions & 0 deletions tests/functional/transport/pecan/controllers/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ def test_health_provider(self, mock_requests):
self.assertEqual(200, response.status_code)
self.assertIn('true', str(response.body))

@mock.patch('requests.get')
def test_health_dns(self, mock_requests):
response_object = util.dict2obj(
{'content': '', 'status_code': 200})
mock_requests.return_value = response_object

response = self.app.get('/v1.0/health',
headers={'X-Project-ID': self.project_id})
for name in response.json['dns']:
endpoint = '/v1.0/health/dns/{0}'.format(name)
response = self.app.get(endpoint,
headers={'X-Project-ID': self.project_id})
self.assertEqual(200, response.status_code)
self.assertIn('true', str(response.body))

def test_get_unknown_dns(self):
response = self.app.get('/v1.0/health/dns/unknown',
headers={'X-Project-ID': self.project_id},
expect_errors=True)
self.assertEqual(404, response.status_code)

def test_get_unknown_provider(self):
response = self.app.get('/v1.0/health/provider/unknown',
headers={'X-Project-ID': self.project_id},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_get_ssl_certificate_existing_domain_different_project_id(self):
self.assertEqual(200, response.status_code)

def test_create_with_invalid_json(self):
# create with errorenous data: invalid json data
# create with erroneous data: invalid json data
response = self.app.post('/v1.0/ssl_certificate',
params="{",
headers={
Expand All @@ -151,7 +151,7 @@ def test_create_with_invalid_json(self):

@ddt.file_data("data_create_ssl_certificate_bad_input_json.json")
def test_create_with_bad_input_json(self, ssl_certificate_json):
# create with errorenous data
# create with erroneous data
response = self.app.post('/v1.0/ssl_certificate',
params=json.dumps(ssl_certificate_json),
headers={'Content-Type': 'application/json',
Expand All @@ -160,14 +160,14 @@ def test_create_with_bad_input_json(self, ssl_certificate_json):
self.assertEqual(400, response.status_code)

def test_delete_cert(self):
# create with errorenous data: invalid json data
# create with erroneous data: invalid json data
response = self.app.delete('/v1.0/ssl_certificate/blog.test.com',
headers={'X-Project-ID': self.project_id}
)
self.assertEqual(202, response.status_code)

def test_delete_cert_non_exist(self):
# create with errorenous data: invalid json data
# create with erroneous data: invalid json data
response = self.app.delete('/v1.0/ssl_certificate/blog.non_exist.com',
headers={'X-Project-ID': self.project_id},
expect_errors=True)
Expand Down
56 changes: 56 additions & 0 deletions tests/unit/provider/akamai/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import ddt
import mock
from oslo_config import cfg
import requests

from poppy.provider.akamai import certificates
from poppy.provider.akamai import driver
from tests.unit import base

Expand Down Expand Up @@ -191,3 +193,57 @@ def test_cert_info_storage(self, mock_connect):
mock_connect.return_value = mock.Mock()
provider = driver.CDNProvider(self.conf)
self.assertNotEqual(None, provider.cert_info_storage)

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_certificate_controller(self):
provider = driver.CDNProvider(self.conf)
self.assertTrue(
isinstance(
provider.certificate_controller,
certificates.CertificateController
)
)

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_policy_api_client(self):
provider = driver.CDNProvider(self.conf)
self.assertTrue(
isinstance(provider.policy_api_client, requests.Session))

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_ccu_api_client(self):
provider = driver.CDNProvider(self.conf)
self.assertTrue(
isinstance(provider.ccu_api_client, requests.Session))

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_sps_api_client(self):
provider = driver.CDNProvider(self.conf)
self.assertTrue(
isinstance(provider.sps_api_client, requests.Session))

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_papi_api_client(self):
provider = driver.CDNProvider(self.conf)
self.assertTrue(
isinstance(provider.papi_api_client, requests.Session))

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_papi_property_id_positive(self):
provider = driver.CDNProvider(self.conf)

prop_id = provider.papi_property_id('akamai_http_config_number')
self.assertIsNotNone(prop_id)

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_papi_property_id_positive_spec_returns_list(self):
provider = driver.CDNProvider(self.conf)
prop_id = provider.papi_property_id('akamai_https_san_config_numbers')
self.assertIsNotNone(prop_id)

@mock.patch.object(driver, 'AKAMAI_OPTIONS', new=AKAMAI_OPTIONS)
def test_papi_property_id_invalid_spec(self):
provider = driver.CDNProvider(self.conf)

self.assertRaises(
ValueError, provider.papi_property_id, 'invalid_spec_name')
142 changes: 142 additions & 0 deletions tests/unit/provider/akamai/test_http_policy_queue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright (c) 2016 Rackspace, Inc.
#
# 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 json

import mock
from oslo_config import cfg
from zake import fake_client

from poppy.provider.akamai.http_policy_queue import http_policy_queue
from tests.unit import base


AKAMAI_OPTIONS = [
# queue backend configs
cfg.StrOpt(
'queue_backend_type',
help='HTTP policy queueing backend'),
cfg.ListOpt('queue_backend_host', default=['localhost'],
help='default queue backend server hosts'),
cfg.IntOpt('queue_backend_port', default=2181, help='default'
' default queue backend server port (e.g: 2181)'),
cfg.StrOpt(
'http_policy_queue_path',
default='/http_policy_queue',
help='Zookeeper path '
'for http_policy_queue'
),
]

AKAMAI_GROUP = 'drivers:provider:akamai'


class TestHTTPPolicyQueue(base.TestCase):

def setUp(self):
super(TestHTTPPolicyQueue, self).setUp()
self.http_policy_dict = {
"configuration_number": 1,
"policy_name": "www.abc.com",
"project_id": "12345"
}

# Need this fake class bc zake's fake client
# does not take any host parameters
class fake_kz_client(fake_client.FakeClient):
def __init__(self, hosts):
super(self.__class__, self).__init__()

zookeeper_client_patcher = mock.patch(
'kazoo.client.KazooClient',
fake_kz_client
)
zookeeper_client_patcher.start()
self.addCleanup(zookeeper_client_patcher.stop)

self.conf = cfg.ConfigOpts()
self.zk_queue = http_policy_queue.ZookeeperHttpPolicyQueue(self.conf)

def test_enqueue_http_policy(self):
self.zk_queue.enqueue_http_policy(
json.dumps(self.http_policy_dict).encode('utf-8'))
self.assertTrue(len(self.zk_queue.http_policy_queue_backend) == 1)
self.assertTrue(
json.loads(self.zk_queue.http_policy_queue_backend.get().
decode('utf-8')) == self.http_policy_dict)

def test_dequeue_http_policy(self):
self.zk_queue.enqueue_http_policy(
json.dumps(self.http_policy_dict).encode('utf-8'))
res = self.zk_queue.dequeue_http_policy(False).decode('utf-8')
self.assertTrue(len(self.zk_queue.http_policy_queue_backend) == 1)
self.assertTrue(json.loads(res) == self.http_policy_dict)

res = self.zk_queue.dequeue_http_policy().decode('utf-8')
self.assertTrue(len(self.zk_queue.http_policy_queue_backend) == 0)
self.assertTrue(json.loads(res) == self.http_policy_dict)

def test_traverse_queue(self):
self.zk_queue.enqueue_http_policy(
json.dumps(self.http_policy_dict).encode('utf-8'))
res = self.zk_queue.traverse_queue()
self.assertTrue(len(res) == 1)
res = [json.loads(r.decode('utf-8')) for r in res]
self.assertTrue(res == [self.http_policy_dict])

def test_traverse_queue_multiple_records(self):
# Get a list of records to enqueue
policy_obj_list = []
for i in range(10):
policy_object = {
"configuration_number": 1,
"policy_name": "www.abc{0}.com".format(i),
"project_id": "12345{0}".format(i),
}
policy_obj_list.append(policy_object)

for cert_obj in policy_obj_list:
self.zk_queue.enqueue_http_policy(
json.dumps(cert_obj).encode('utf-8'))
res = self.zk_queue.traverse_queue()
self.assertTrue(len(res) == 10)
res = [json.loads(r.decode('utf-8')) for r in res]
self.assertTrue(res == policy_obj_list)

def test_put_queue_data(self):
res = self.zk_queue.put_queue_data([])
self.assertTrue(len(res) == 0)

policy_obj_list = []
for i in range(10):
policy_object = {
"configuration_number": 1,
"policy_name": "www.abc{0}.com".format(i),
"project_id": "12345{0}".format(i),
}
policy_obj_list.append(policy_object)

self.zk_queue.put_queue_data(
[json.dumps(o).encode('utf-8') for o in policy_obj_list])
self.assertTrue(len(self.zk_queue.http_policy_queue_backend) == 10)
res = self.zk_queue.traverse_queue()
res = [json.loads(r.decode('utf-8')) for r in res]
self.assertTrue(res == policy_obj_list)

# test put data to non-empty queue
# should replace all items added above
self.zk_queue.put_queue_data(
[json.dumps(o).encode('utf-8') for o in policy_obj_list])
self.assertTrue(len(self.zk_queue.http_policy_queue_backend) == 10)
6 changes: 6 additions & 0 deletions tests/unit/provider/akamai/test_mod_san_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ def test_put_queue_data(self):
res = self.zk_queue.traverse_queue()
res = [json.loads(r.decode('utf-8')) for r in res]
self.assertTrue(res == cert_obj_list)

# test put data to non-empty queue
# should replace all items added above
self.zk_queue.put_queue_data(
[json.dumps(o).encode('utf-8') for o in cert_obj_list])
self.assertTrue(len(self.zk_queue.mod_san_queue_backend) == 10)

0 comments on commit ae84ae6

Please sign in to comment.