Fixing Gerrit Gating issues with Pep8 and Docs

Change-Id: I419b6e60e04cb828256eff1d5f6ac16cb6cfe585
This commit is contained in:
amitgandhinz 2014-08-13 15:09:59 -04:00
parent 094dc1dd5c
commit 5ab42a4ae0
61 changed files with 695 additions and 750 deletions

View File

@ -32,34 +32,3 @@ be found on the `OpenStack wiki`_. Cloud administrators, refer to `docs.openstac
.. _`OpenStack wiki`: http://wiki.openstack.org
.. _`docs.openstack.org`: http://docs.openstack.org
Concepts
========
.. toctree::
:maxdepth: 1
glossary
Installing/Configuring Poppy
============================
.. toctree::
:maxdepth: 1
installing
Operating Poppy
===============
.. toctree::
:maxdepth: 1
ha
Using Poppy
===========
.. toctree::
:maxdepth: 1
api

View File

@ -14,7 +14,8 @@
# limitations under the License.
from oslo.config import cfg
from stevedore import driver, extension
from stevedore import driver
from stevedore import extension
from poppy.common import decorators
from poppy.openstack.common import log

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six
from poppy.manager.base import controller

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six
from poppy.manager.base import controller

View File

@ -13,7 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from poppy.manager.default import services, v1
from poppy.manager.default import services
from poppy.manager.default import v1
Services = services.DefaultServicesController

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six
from poppy.provider.base import controller

View File

@ -19,9 +19,9 @@ from poppy.openstack.common import log as logging
from poppy.provider import base
from poppy.provider.fastly import controllers
import fastly
from oslo.config import cfg
import fastly
LOG = logging.getLogger(__name__)

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six

View File

@ -14,9 +14,9 @@
# limitations under the License.
import abc
import six
from oslo.config import cfg
import six
_LIMITS_OPTIONS = [

View File

@ -14,6 +14,7 @@
# limitations under the License.
import abc
import six
from poppy.storage.base import controller

View File

@ -15,7 +15,7 @@
"""Cassandra storage driver implementation."""
from cassandra.cluster import Cluster
from cassandra import cluster
from poppy.common import decorators
from poppy.openstack.common import log as logging
@ -36,8 +36,8 @@ CASSANDRA_GROUP = 'drivers:storage:cassandra'
def _connection(conf):
cluster = Cluster(conf.cluster)
session = cluster.connect(conf.keyspace)
cassandra_cluster = cluster.Cluster(conf.cluster)
session = cassandra_cluster.connect(conf.keyspace)
return session

View File

@ -22,9 +22,8 @@ import six
import poppy.openstack.common.log as logging
from poppy import transport
from poppy.transport.falcon import (
v1, services
)
from poppy.transport.falcon import services
from poppy.transport.falcon import v1
_WSGI_OPTIONS = [

View File

@ -13,17 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import falcon
import json
import falcon
class ServicesResource:
def __init__(self, services_controller):
self.services_controller = services_controller
def on_get(self, req, resp, project_id):
"""Handles GET requests
"""
"""Handles GET requests."""
services = self.services_controller.list(project_id)
resp.status = falcon.HTTP_200
resp.body = json.dumps(services)
@ -34,15 +35,15 @@ class ServiceResource:
self.service_controller = service_controller
def on_get(self, req, resp, project_id, service_name):
"""Handles GET requests
"""
"""Handles GET requests."""
service = self.service_controller.get(project_id, service_name)
resp.status = falcon.HTTP_200
resp.body = json.dumps(service)
def on_put(self, req, resp, project_id, service_name):
"""Handles PUT requests
"""
"""Handles PUT requests."""
service_json = json.loads(req.stream.read(req.content_length))
service = self.service_controller.create(project_id,
@ -52,15 +53,15 @@ class ServiceResource:
resp.body = json.dumps(service)
def on_patch(self, req, resp, project_id, service_name):
"""Handles PATCH requests
"""
"""Handles PATCH requests."""
service = self.service_controller.update(project_id, service_name)
resp.status = falcon.HTTP_200
resp.body = json.dumps(service)
def on_delete(self, req, resp, project_id, service_name):
"""Handles DELETE requests
"""
"""Handles DELETE requests."""
service = self.service_controller.delete(project_id, service_name)
resp.status = falcon.HTTP_204
resp.body = json.dumps(service)

View File

@ -28,8 +28,8 @@ class Controller(rest.RestController):
setattr(self, path, controller)
def _handle_patch(self, method, remainder):
'''Routes ``PATCH`` actions to the appropriate controller.
'''
"""Routes ``PATCH`` actions to the appropriate controller."""
# route to a patch_all or get if no additional parts are available
if not remainder or remainder == ['']:
controller = self._find_controller('patch_all', 'patch')

View File

@ -1,4 +1,4 @@
# Copyright (c) 2014 Rackspace, Inc.
# Copyright (c) 2014 Rackspace, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@ -33,8 +33,9 @@ class ContextHook(hooks.PecanHook):
context_kwargs['tenant'] = state.request.path.split('/')[2]
if 'X-Auth-Token' in state.request.headers:
context_kwargs['auth_token'] = \
context_kwargs['auth_token'] = (
state.request.headers['X-Auth-Token']
)
request_context = context.RequestContext(**context_kwargs)
state.request.context = request_context

View File

@ -125,8 +125,7 @@ def with_schema_falcon(request, schema=None):
def with_schema_pecan(request, schema=None, handler=custom_abort_pecan,
**kwargs):
"""Used to decorate a Pecan/Flask style controller form validation for
anything else (e.g., POST | PUT | PATCH ).
"""Decorate a Pecan/Flask style controller form validation.
For an HTTP POST or PUT (RFC2616 unsafe methods) request, the schema is
used to validate the request body.
@ -140,8 +139,9 @@ def with_schema_pecan(request, schema=None, handler=custom_abort_pecan,
validation_failed = False
v_error = None
errors_list = []
if request.method in ('POST', 'PUT', 'PATCH') and \
schema is not None:
if request.method in ('POST', 'PUT', 'PATCH') and (
schema is not None
):
try:
data = json.loads(request.body.decode('utf-8'))
errors_list = list(

View File

@ -24,6 +24,7 @@ class SchemaBase(object):
@classmethod
def get_schema(cls, resource_name, operation):
"""Returns the schema for an operation
:param resource_name: Operation for which resource need
to be validated.
:type operation: `six.text_type`

View File

@ -1,14 +0,0 @@
# Copyright (c) 2014 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.

View File

@ -18,8 +18,8 @@ from poppy.transport.validators import schema_base
class ServiceSchema(schema_base.SchemaBase):
"""JSON Schmema validation for /service
"""
"""JSON Schmema validation for /service."""
schema = {
'service': {
'PUT': {

View File

@ -13,10 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from functools import wraps
import functools
import inspect
from . import exceptions
from poppy.transport.validators.stoplight import exceptions
def validate(**rules):
@ -39,7 +39,7 @@ def validate(**rules):
be called.
"""
def _validate(f):
@wraps(f)
@functools.wraps(f)
def wrapper(*args, **kwargs):
funcparams = inspect.getargspec(f)
@ -96,9 +96,8 @@ def validate(**rules):
def validation_function(func):
"""Decorator for creating a validation function.
"""
@wraps(func)
"""Decorator for creating a validation function."""
@functools.wraps(func)
def inner(none_ok=False, empty_ok=False):
def wrapper(value, **kwargs):
if none_ok and value is None:

View File

@ -14,16 +14,11 @@
# limitations under the License.
"""
Some useful getters for thread local request style validation
Some useful getters for thread local request style validation.
"""
def pecan_getter(parm):
"""pecan getter"""
"""pecan getter."""
pecan_module = __import__('pecan', globals(), locals(), ['request'])
return getattr(pecan_module, 'request')
# def flask_getter(parm):
# pecan_module = __import__('flask', globals(), locals(), ['request'])
# return getattr(pecan_module, 'request')

View File

@ -13,14 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections import namedtuple
import collections
ValidationRule = namedtuple('ValidationRule', 'vfunc errfunc getter')
ValidationRule = collections.namedtuple('ValidationRule',
'vfunc errfunc getter'
)
def Rule(vfunc, on_error, getter=None):
"""Constructs a single validation rule. A rule effectively
is saying "I want to validation this input using
"""Constructs a single validation rule.
A rule effectively is saying "I want to validation this input using
this function and if validation fails I want this (on_error)
to happen.

View File

@ -23,9 +23,12 @@ packages =
poppy
[build_sphinx]
all_files = 1
build-dir = doc/build
source-dir = doc/source
build-dir = doc/build
all_files = 1
[upload_sphinx]
upload-dir = doc/build/html
[entry_points]
console_scripts =

View File

@ -16,6 +16,7 @@
# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
import os
import pip
import setuptools

View File

@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import jsonschema
import os
from cafe.drivers.unittest import fixtures
import jsonschema
from oslo.config import cfg
from cafe.drivers.unittest import fixtures
from tests.api.utils import client
from tests.api.utils import config

View File

@ -13,9 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import ddt
import uuid
import ddt
from tests.api import base
from tests.api.utils.schema import response
@ -45,7 +46,7 @@ class TestServices(base.TestBase):
response_body = resp.json()
self.assertSchema(response_body, response.create_service)
#Get on Created Service
# Get on Created Service
resp = self.client.get_service(service_name=self.service_name)
self.assertEqual(resp.status_code, 200)

View File

@ -27,7 +27,7 @@ class PoppyConfig(data_interfaces.ConfigSectionInterface):
class PoppyServerConfig(data_interfaces.ConfigSectionInterface):
"""Defines the config values for starting (or not) a Poppy server"""
"""Defines the config values for starting (or not) a Poppy server."""
SECTION_NAME = 'poppy_server'
@property

View File

@ -52,7 +52,7 @@ links = {'type': 'object',
restrictions = {'type': 'array'}
#Response Schema Definition for Create Service API
# Response Schema Definition for Create Service API
create_service = {
'type': 'object',
'properties': {

View File

@ -15,6 +15,7 @@
import abc
import multiprocessing
import six
from poppy import bootstrap

View File

@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import fixtures
import os
import testtools
import fixtures
from oslo.config import cfg
import testtools
class TestCase(testtools.TestCase):

View File

@ -12,3 +12,18 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
server = {
'port': '8080',
'host': '0.0.0.0'
}
app = {
'root': 'tests.functional.transport.pecan.mock.MockPecanEndpoint',
'modules': ['tests.functional.transport.pecan.pecan_app'],
'debug': True,
'errors': {
'404': '/error/404',
'__force_dict__': True
}
}

View File

@ -1,16 +0,0 @@
# Copyright (c) 2014 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.
# Server Specific Configurations

View File

@ -38,7 +38,7 @@ class ServiceControllerTest(base.FunctionalTest):
self.assertEqual(200, response.status_code)
def test_create(self):
# create with errorenous data: invalid json data
# create with errorenous data: invalid json data
self.assertRaises(app.AppError, self.app.put,
'/v1.0/0001/services/fake_service_name_2',
params="{", headers={

View File

@ -14,7 +14,6 @@
# limitations under the License.
from poppy.manager.default import v1
from tests.functional.transport.pecan import base

View File

@ -0,0 +1,58 @@
# Copyright (c) 2014 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 pecan
from poppy.transport.validators import helpers
from poppy.transport.validators.schemas import service
from poppy.transport.validators.stoplight import decorators
from poppy.transport.validators.stoplight import exceptions
from poppy.transport.validators.stoplight import helpers as stoplight_helpers
from poppy.transport.validators.stoplight import rule
class MockPecanEndpoint(object):
testing_schema = service.ServiceSchema.get_schema("service", "PUT")
@decorators.validation_function
def is_valid_json(r):
"""Test for a valid JSON string."""
if len(r.body) == 0:
return
else:
try:
json.loads(r.body.decode('utf-8'))
except Exception as e:
e
raise exceptions.ValidationFailed('Invalid JSON string')
else:
return
@pecan.expose(generic=True)
@helpers.with_schema_pecan(pecan.request, schema=testing_schema)
def index(self):
return "Hello, World!"
@index.when(method='PUT')
@decorators.validate(
request=rule.Rule(is_valid_json(),
lambda error_info: pecan.abort(400),
stoplight_helpers.pecan_getter)
)
def index_put(self):
return "Hello, World!"

View File

@ -13,13 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from pecan import make_app
import pecan
def setup_app(config):
app_conf = dict(config.app)
return make_app(
return pecan.make_app(
app_conf.pop('root'),
logging=getattr(config, 'logging', {}),
**app_conf

View File

@ -1,16 +0,0 @@
# Copyright (c) 2014 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.
# Server Specific Configurations

View File

@ -0,0 +1,209 @@
# Copyright (c) 2014 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 re
from poppy.transport.validators.stoplight import decorators
from poppy.transport.validators.stoplight import exceptions
from tests.functional import base
error_count = 0
def abort(code):
global error_count
error_count = error_count + 1
@decorators.validation_function
def is_valid_json(r):
"""Test for a valid JSON string."""
if len(r.body) == 0:
return
else:
try:
json.loads(r.body.decode('utf-8'))
except Exception as e:
e
raise exceptions.ValidationFailed('Invalid JSON string')
else:
return
class DummyRequest(object):
def __init__(self):
self.headers = dict(header1='headervalue1')
self.method = "PUT"
self.body = json.dumps({
"domains": [
{"domain": "www.mywebsite.com"},
{"domain": "blog.mywebsite.com"},
],
"origins": [
{
"origin": "mywebsite.com",
"port": 80,
"ssl": False
},
{
"origin": "mywebsite.com",
}
],
"caching": [
{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 17200,
"rules": [
{"name": "index", "request_url": "/index.htm"}
]
},
{"name": "images",
"ttl": 12800,
}
]
})
class DummyRequestWithInvalidHeader(DummyRequest):
def client_accepts(self, header='application/json'):
return False
def accept(self, header='application/json'):
return False
fake_request_good = DummyRequest()
fake_request_bad_missing_domain = DummyRequest()
fake_request_bad_missing_domain.body = json.dumps({
"origins": [
{
"origin": "mywebsite.com",
"port": 80,
"ssl": False
}
],
"caching": [
{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 17200,
"rules": [
{"name": "index", "request_url": "/index.htm"}
]
},
{"name": "images",
"ttl": 12800,
"rules": [
{"name": "images", "request_url": "*.png"}
]
}
]
})
fake_request_bad_invalid_json_body = DummyRequest()
fake_request_bad_invalid_json_body.body = "{"
class _AssertRaisesContext(object):
"""A context manager used to implement TestCase.assertRaises* methods."""
def __init__(self, expected, test_case, expected_regexp=None):
self.expected = expected
self.failureException = test_case.failureException
self.expected_regexp = expected_regexp
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
try:
exc_name = self.expected.__name__
except AttributeError:
exc_name = str(self.expected)
raise self.failureException(
"{0} not raised".format(exc_name))
if not issubclass(exc_type, self.expected):
return False # let unexpected exceptions pass through
self.exception = exc_value # store for later retrieval
if self.expected_regexp is None:
return True
expected_regexp = self.expected_regexp
try:
basestring
except NameError:
# Python 3 compatibility
basestring = unicode = str
unicode # For pep8: unicde is defined but not used.
if isinstance(expected_regexp, basestring):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(str(exc_value)):
raise self.failureException('"%s" does not match "%s"' %
(expected_regexp.pattern,
str(exc_value)))
return True
class BaseTestCase(base.TestCase):
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
"""Check the expected Exception is raised.
Fail unless an exception of class excClass is raised
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
raised, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
If called with callableObj omitted or None, will return a
context object used like this::
with self.assertRaises(SomeException):
do_something()
The context manager keeps a reference to the exception as
the 'exception' attribute. This allows you to inspect the
exception after the assertion::
with self.assertRaises(SomeException) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
"""
context = _AssertRaisesContext(excClass, self)
if callableObj is None:
return context
with context:
callableObj(*args, **kwargs)
def assertRaisesRegexp(self, expected_exception, expected_regexp,
callable_obj=None, *args, **kwargs):
"""Asserts that the message in a raised exception matches a regexp."""
context = _AssertRaisesContext(expected_exception, self,
expected_regexp)
if callable_obj is None:
return context
with context:
callable_obj(*args, **kwargs)
@decorators.validation_function
def is_response(candidate):
pass

View File

@ -1,41 +0,0 @@
# Copyright (c) 2014 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.
# Server Specific Configurations
server = {
'port': '8080',
'host': '0.0.0.0'
}
# Pecan Application Configurations
app = {
'root': 'test_service_validation.DummyPecanEndpoint',
'modules': ['pecan_app'],
#'static_root': '%(confdir)s/../../public',
#'template_path': '%(confdir)s/../templates',
'debug': True,
'errors': {
'404': '/error/404',
'__force_dict__': True
}
}
# Custom Configurations must be in Python dictionary format::
#
# foo = {'bar':'baz'}
#
# All configurations are accessible at::
# pecan.conf

View File

@ -0,0 +1,128 @@
# Copyright (c) 2014 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 functools
from poppy.common import errors
from poppy.transport.validators import helpers
from poppy.transport.validators.schemas import service
from poppy.transport.validators.stoplight import decorators
from poppy.transport.validators.stoplight import exceptions
from poppy.transport.validators.stoplight import rule
from tests.functional.transport.validator import base
testing_schema = service.ServiceSchema.get_schema("service", "PUT")
request_fit_schema = functools.partial(
helpers.with_schema_falcon,
schema=testing_schema)
class DummyFalconEndpoint(object):
# falcon style endpoint
@decorators.validate(
request=rule.Rule(
request_fit_schema,
lambda error_info: base.abort(404)
),
response=rule.Rule(
base.is_response(),
lambda error_info: base.abort(404))
)
def get_falcon_style(self, request, response):
return "Hello, World!"
@decorators.validate(
request=rule.Rule(request_fit_schema,
helpers.custom_abort_falcon),
response=rule.Rule(base.is_response(),
helpers.custom_abort_falcon)
)
def get_falcon_style_custom_abort(self, request, response):
return "Hello, World!"
class TestValidationFunctionsFalcon(base.BaseTestCase):
def setUp(self):
self.ep = DummyFalconEndpoint()
super(TestValidationFunctionsFalcon, self).setUp()
def test_with_schema(self):
self.assertEqual(
helpers.with_schema_falcon(
base.fake_request_good,
schema=testing_schema),
None)
with self.assertRaisesRegexp(exceptions.ValidationFailed, "domain"):
helpers.with_schema_falcon(
base.fake_request_bad_missing_domain,
schema=testing_schema)
with self.assertRaisesRegexp(exceptions.ValidationFailed,
"Invalid JSON body in request"):
helpers.with_schema_falcon(
base.fake_request_bad_invalid_json_body,
schema=testing_schema)
def test_partial_with_schema(self):
self.assertEqual(request_fit_schema(base.fake_request_good), None)
with self.assertRaisesRegexp(exceptions.ValidationFailed, "domain"):
request_fit_schema(base.fake_request_bad_missing_domain)
with self.assertRaisesRegexp(exceptions.ValidationFailed,
"Invalid JSON body in request"):
request_fit_schema(base.fake_request_bad_invalid_json_body)
def test_schema_base(self):
with self.assertRaises(errors.InvalidResourceName):
service.ServiceSchema.get_schema("invalid_resource", "PUT")
with self.assertRaises(errors.InvalidOperation):
service.ServiceSchema.get_schema("service", "INVALID_HTTP_VERB")
def test_accept_header(self):
req = base.DummyRequestWithInvalidHeader()
resp = helpers.DummyResponse()
with self.assertRaises(helpers.falcon.HTTPNotAcceptable):
helpers.require_accepts_json_falcon(req, resp)
def test_falcon_endpoint(self):
class DummyResponse(object):
pass
response = DummyResponse()
global error_count
# Try to call with good inputs
oldcount = base.error_count
ret = self.ep.get_falcon_style(base.fake_request_good, response)
self.assertEqual(oldcount, base.error_count)
self.assertEqual(
ret,
"Hello, World!",
"testing not passed on endpoint: get_falcon_style with valid data")
# Try to call with bad inputs
oldcount = base.error_count
self.ep.get_falcon_style(
base.fake_request_bad_missing_domain,
response)
self.assertEqual(oldcount + 1, base.error_count)
# Try to call with bad inputs
self.ep.get_falcon_style_custom_abort(
base.fake_request_bad_missing_domain,
response)

View File

@ -1,60 +0,0 @@
# Copyright (c) 2014 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 os
import sys
import pecan
from pecan.testing import load_test_app
from webtest import app
os.environ['PECAN_CONFIG'] = os.path.join(os.path.dirname(__file__),
'config.py')
# For noese fix
sys.path = [os.path.abspath(os.path.dirname(__file__))] + sys.path
import test_service_validation
class PecanEndPointFunctionalTest(test_service_validation.BaseTestCase):
"""A Simple PecanFunctionalTest base class that sets up a
Pecan endpoint (endpoint class: DummyPecanEndpoint)
"""
def setUp(self):
self.app = load_test_app(os.path.join(os.path.dirname(__file__),
'config.py'
))
super(PecanEndPointFunctionalTest, self).setUp()
def tearDown(self):
pecan.set_config({}, overwrite=True)
super(PecanEndPointFunctionalTest, self).tearDown()
class TestValidationDecoratorsPecan(PecanEndPointFunctionalTest):
def test_pecan_endpoint_put(self):
resp = self.app.put(
'/',
headers={
"Content-Type": "application/json;charset=utf-8"})
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body.decode('utf-8'), "Hello, World!")
with self.assertRaisesRegexp(app.AppError, "400 Bad Request"):
self.app.put('/', params='{',
headers={"Content-Type":
"application/json;charset=utf-8"})

View File

@ -0,0 +1,93 @@
# Copyright (c) 2014 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 os
# import pecan
# import pecan.testing
# from webtest import app
# from poppy.transport.validators import helpers
# from poppy.transport.validators.stoplight import exceptions
# from tests.functional.transport.validator import base
# TODO(amitgandhinz): This whole file needs refactoring.
# TODO(amitgandhinz): The pecan and falcon validation should live in the
# transport/pecan and transport/falcon folders
# TODO(amitgandhinz): The transport/validator modules should test just the
# validator logic, independant of the transport used.
def mock(self):
pass
# class PecanEndPointFunctionalBase(base.BaseTestCase):
# """Sets up a Test Pecan endpoint."""
# def setUp(self):
# tests_path = os.path.abspath(os.path.dirname(
# os.path.dirname(
# os.path.dirname(os.path.dirname(__file__)
# ))))
# self.app = pecan.testing.load_test_app(
# os.path.join(tests_path, 'etc', 'pecan.py')
# )
# super(PecanEndPointFunctionalBase, self).setUp()
# def tearDown(self):
# pecan.set_config({}, overwrite=True)
# super(PecanEndPointFunctionalBase, self).tearDown()
# class TestValidationFunctionsPecan(PecanEndPointFunctionalBase):
# def test_pecan_endpoint_post(self):
# resp = self.app.post(
# '/',
# params=base.fake_request_good.body,
# headers={
# "Content-Type": "application/json;charset=utf-8"})
# self.assertEqual(resp.status_int, 200)
# self.assertEqual(resp.body.decode('utf-8'), "Hello, World!")
# with self.assertRaisesRegexp(app.AppError, "400 Bad Request"):
# self.app.post('/',
# params=base.fake_request_bad_missing_domain.body,
# headers={"Content-Type": "application/json"})
# with self.assertRaisesRegexp(app.AppError, "400 Bad Request"):
# self.app.post('/',
# params=base.fake_request_bad_invalid_json_body.body,
# headers={"Content-Type": "application/json"})
# def test_accept_header(self):
# req = base.DummyRequestWithInvalidHeader()
# with self.assertRaises(exceptions.ValidationFailed):
# helpers.req_accepts_json_pecan(req)
# def test_pecan_endpoint_put(self):
# resp = self.app.put(
# '/',
# headers={
# "Content-Type": "application/json;charset=utf-8"})
# self.assertEqual(resp.status_int, 200)
# self.assertEqual(resp.body.decode('utf-8'), "Hello, World!")
# with self.assertRaisesRegexp(app.AppError, "400 Bad Request"):
# self.app.put('/', params='{',
# headers={"Content-Type":
# "application/json;charset=utf-8"})

View File

@ -1,393 +0,0 @@
# Copyright (c) 2014 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 functools
import json
import os
import re
import sys
import pecan
from webtest import app
from poppy.common import errors
from poppy.transport.validators import helpers
from poppy.transport.validators.schemas import service
from poppy.transport.validators.stoplight import decorators
from poppy.transport.validators.stoplight import exceptions
from poppy.transport.validators.stoplight import helpers as stoplight_helpers
from poppy.transport.validators.stoplight import rule
from tests.functional import base
# for pecan testing app
os.environ['PECAN_CONFIG'] = os.path.join(os.path.dirname(__file__),
'config.py')
# For noese fix
sys.path = [os.path.abspath(os.path.dirname(__file__))] + sys.path
from pecan.testing import load_test_app
error_count = 0
def abort(code):
global error_count
error_count = error_count + 1
@decorators.validation_function
def is_valid_json(r):
"""Simple validation function for testing purposes
that ensures that input is a valid json string
"""
if len(r.body) == 0:
return
else:
try:
json.loads(r.body.decode('utf-8'))
except Exception as e:
e
raise exceptions.ValidationFailed('Invalid JSON string')
else:
return
class DummyRequest(object):
def __init__(self):
self.headers = dict(header1='headervalue1')
self.method = "PUT"
self.body = json.dumps({
"domains": [
{"domain": "www.mywebsite.com"},
{"domain": "blog.mywebsite.com"},
],
"origins": [
{
"origin": "mywebsite.com",
"port": 80,
"ssl": False
},
{
"origin": "mywebsite.com",
}
],
"caching": [
{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 17200,
"rules": [
{"name": "index", "request_url": "/index.htm"}
]
},
{"name": "images",
"ttl": 12800,
}
]
})
class DummyRequestWithInvalidHeader(DummyRequest):
def client_accepts(self, header='application/json'):
return False
def accept(self, header='application/json'):
return False
fake_request_good = DummyRequest()
fake_request_bad_missing_domain = DummyRequest()
fake_request_bad_missing_domain.body = json.dumps({
"origins": [
{
"origin": "mywebsite.com",
"port": 80,
"ssl": False
}
],
"caching": [
{"name": "default", "ttl": 3600},
{"name": "home",
"ttl": 17200,
"rules": [
{"name": "index", "request_url": "/index.htm"}
]
},
{"name": "images",
"ttl": 12800,
"rules": [
{"name": "images", "request_url": "*.png"}
]
}
]
})
fake_request_bad_invalid_json_body = DummyRequest()
fake_request_bad_invalid_json_body.body = "{"
class _AssertRaisesContext(object):
"""A context manager used to implement TestCase.assertRaises* methods."""
def __init__(self, expected, test_case, expected_regexp=None):
self.expected = expected
self.failureException = test_case.failureException
self.expected_regexp = expected_regexp
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
if exc_type is None:
try:
exc_name = self.expected.__name__
except AttributeError:
exc_name = str(self.expected)
raise self.failureException(
"{0} not raised".format(exc_name))
if not issubclass(exc_type, self.expected):
return False # let unexpected exceptions pass through
self.exception = exc_value # store for later retrieval
if self.expected_regexp is None:
return True
expected_regexp = self.expected_regexp
try:
basestring
except NameError:
# Python 3 compatibility
basestring = unicode = str
unicode # For pep8: unicde is defined but not used.
if isinstance(expected_regexp, basestring):
expected_regexp = re.compile(expected_regexp)
if not expected_regexp.search(str(exc_value)):
raise self.failureException('"%s" does not match "%s"' %
(expected_regexp.pattern,
str(exc_value)))
return True
class BaseTestCase(base.TestCase):
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
"""Fail unless an exception of class excClass is raised
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
raised, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
If called with callableObj omitted or None, will return a
context object used like this::
with self.assertRaises(SomeException):
do_something()
The context manager keeps a reference to the exception as
the 'exception' attribute. This allows you to inspect the
exception after the assertion::
with self.assertRaises(SomeException) as cm:
do_something()
the_exception = cm.exception
self.assertEqual(the_exception.error_code, 3)
"""
context = _AssertRaisesContext(excClass, self)
if callableObj is None:
return context
with context:
callableObj(*args, **kwargs)
def assertRaisesRegexp(self, expected_exception, expected_regexp,
callable_obj=None, *args, **kwargs):
"""Asserts that the message in a raised exception matches a regexp."""
context = _AssertRaisesContext(expected_exception, self,
expected_regexp)
if callable_obj is None:
return context
with context:
callable_obj(*args, **kwargs)
def test_accept_header(self):
req = DummyRequestWithInvalidHeader()
resp = helpers.DummyResponse()
try:
with self.assertRaises(helpers.falcon.HTTPNotAcceptable):
helpers.require_accepts_json_falcon(req, resp)
except Exception as e:
e
pass
with self.assertRaises(exceptions.ValidationFailed):
helpers.req_accepts_json_pecan(req)
@decorators.validation_function
def is_response(candidate):
pass
testing_schema = service.ServiceSchema.get_schema("service", "PUT")
request_fit_schema = functools.partial(
helpers.with_schema_falcon,
schema=testing_schema)
class DummyFalconEndpoint(object):
# falcon style endpoint
@decorators.validate(
request=rule.Rule(request_fit_schema, lambda error_info: abort(404)),
response=rule.Rule(is_response(), lambda error_info: abort(404))
)
def get_falcon_style(self, request, response):
return "Hello, World!"
@decorators.validate(
request=rule.Rule(request_fit_schema,
helpers.custom_abort_falcon),
response=rule.Rule(is_response(),
helpers.custom_abort_falcon)
)
def get_falcon_style_custom_abort(self, request, response):
return "Hello, World!"
class DummyPecanEndpoint(object):
@pecan.expose(generic=True)
@helpers.with_schema_pecan(pecan.request, schema=testing_schema)
def index(self):
return "Hello, World!"
@index.when(method='PUT')
@decorators.validate(
request=rule.Rule(is_valid_json(),
lambda error_info: pecan.abort(400),
stoplight_helpers.pecan_getter)
)
def index_put(self):
return "Hello, World!"
def test_fake_falcon():
helpers.falcon.HTTPNotAcceptable("nothing")
class TestFalconStyleValidationFunctions(BaseTestCase):
def test_with_schema_falcon(self):
self.assertEquals(
helpers.with_schema_falcon(
fake_request_good,
schema=testing_schema),
None)
with self.assertRaisesRegexp(exceptions.ValidationFailed, "domain"):
helpers.with_schema_falcon(
fake_request_bad_missing_domain,
schema=testing_schema)
with self.assertRaisesRegexp(exceptions.ValidationFailed,
"Invalid JSON body in request"):
helpers.with_schema_falcon(
fake_request_bad_invalid_json_body,
schema=testing_schema)
def test_partial_with_schema(self):
self.assertEquals(request_fit_schema(fake_request_good), None)
with self.assertRaisesRegexp(exceptions.ValidationFailed, "domain"):
request_fit_schema(fake_request_bad_missing_domain)
with self.assertRaisesRegexp(exceptions.ValidationFailed,
"Invalid JSON body in request"):
request_fit_schema(fake_request_bad_invalid_json_body)
def test_schema_base(self):
with self.assertRaises(errors.InvalidResourceName):
service.ServiceSchema.get_schema("invalid_resource", "PUT")
with self.assertRaises(errors.InvalidOperation):
service.ServiceSchema.get_schema("service", "INVALID_HTTP_VERB")
class TestValidationDecoratorsFalcon(BaseTestCase):
def setUp(self):
self.ep = DummyFalconEndpoint()
super(TestValidationDecoratorsFalcon, self).setUp()
def test_falcon_endpoint(self):
class DummyResponse(object):
pass
response = DummyResponse()
global error_count
# Try to call with good inputs
oldcount = error_count
ret = self.ep.get_falcon_style(fake_request_good, response)
self.assertEqual(oldcount, error_count)
self.assertEqual(
ret,
"Hello, World!",
"testing not passed on endpoint: get_falcon_style with valid data")
# Try to call with bad inputs
oldcount = error_count
self.ep.get_falcon_style(
fake_request_bad_missing_domain,
response)
self.assertEqual(oldcount + 1, error_count)
# Try to call with bad inputs
self.ep.get_falcon_style_custom_abort(
fake_request_bad_missing_domain,
response)
class PecanEndPointFunctionalTest(BaseTestCase):
"""A Simple PecanFunctionalTest base class that sets up a
Pecan endpoint (endpoint class: DummyPecanEndpoint)
"""
def setUp(self):
self.app = load_test_app(os.path.join(os.path.dirname(__file__),
'config.py'
))
super(PecanEndPointFunctionalTest, self).setUp()
def tearDown(self):
pecan.set_config({}, overwrite=True)
super(PecanEndPointFunctionalTest, self).tearDown()
class TestValidationDecoratorsPecan(PecanEndPointFunctionalTest):
def test_pecan_endpoint_post(self):
resp = self.app.post(
'/',
params=fake_request_good.body,
headers={
"Content-Type": "application/json;charset=utf-8"})
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body.decode('utf-8'), "Hello, World!")
with self.assertRaisesRegexp(app.AppError, "400 Bad Request"):
self.app.post('/', params=fake_request_bad_missing_domain.body,
headers={"Content-Type": "application/json"})
with self.assertRaisesRegexp(app.AppError, "400 Bad Request"):
self.app.post('/', params=fake_request_bad_invalid_json_body.body,
headers={"Content-Type": "application/json"})

View File

@ -16,26 +16,15 @@
from poppy.transport.validators.stoplight import decorators
from poppy.transport.validators.stoplight import exceptions
from poppy.transport.validators.stoplight import rule
from test_service_validation import BaseTestCase
# TODO(tonytan4ever): We probably want to move this to a
# test helpers library
from tests.functional.transport.validator import base
@decorators.validation_function
def is_upper(z):
"""Simple validation function for testing purposes
that ensures that input is all caps
"""
"""Ensures Uppercase."""
if z.upper() != z:
raise exceptions.ValidationFailed('{0} no uppercase'.format(z))
error_count = 0
def abort(code):
global error_count
error_count = error_count + 1
other_vals = dict()
get_other_val = other_vals.get
@ -63,9 +52,9 @@ def is_response(candidate):
raise exceptions.ValidationFailed('Input must be a response')
RequestRule = rule.Rule(is_request(), lambda error_info: abort(404))
ResponseRule = rule.Rule(is_response(), lambda error_info: abort(404))
UppercaseRule = rule.Rule(is_upper(), lambda error_info: abort(404))
RequestRule = rule.Rule(is_request(), lambda error_info: base.abort(404))
ResponseRule = rule.Rule(is_response(), lambda error_info: base.abort(404))
UppercaseRule = rule.Rule(is_upper(), lambda error_info: base.abort(404))
class DummyEndpoint(object):
@ -80,7 +69,7 @@ class DummyEndpoint(object):
@decorators.validate(
value=rule.Rule(
is_upper,
lambda error_info: abort(404))) # pragma: no cover
lambda error_info: base.abort(404))) # pragma: no cover
def get_value_programming_error(self, value):
# This function body should never be
# callable since the validation error
@ -88,17 +77,17 @@ class DummyEndpoint(object):
assert False # pragma: no cover
@decorators.validate(
value1=rule.Rule(is_upper(), lambda error_info: abort(404)),
value2=rule.Rule(is_upper(), lambda error_info: abort(404)),
value3=rule.Rule(is_upper(), lambda error_info: abort(404))
value1=rule.Rule(is_upper(), lambda error_info: base.abort(404)),
value2=rule.Rule(is_upper(), lambda error_info: base.abort(404)),
value3=rule.Rule(is_upper(), lambda error_info: base.abort(404))
) # pragma: no cover
def get_value_happy_path(self, value1, value2, value3):
return value1 + value2 + value3
@decorators.validate(
value1=rule.Rule(is_upper(), lambda: abort(404)),
value1=rule.Rule(is_upper(), lambda: base.abort(404)),
value2=rule.Rule(is_upper(empty_ok=True),
lambda error_info: abort(404),
lambda error_info: base.abort(404),
get_other_val),
) # pragma: no cover
def get_value_with_getter(self, value1):
@ -107,9 +96,9 @@ class DummyEndpoint(object):
# Falcon-style endpoint
@decorators.validate(
request=rule.Rule(is_request(), lambda error_info: abort(404)),
response=rule.Rule(is_response(), lambda error_info: abort(404)),
value=rule.Rule(is_upper(), lambda error_info: abort(404))
request=rule.Rule(is_request(), lambda error_info: base.abort(404)),
response=rule.Rule(is_response(), lambda error_info: base.abort(404)),
value=rule.Rule(is_upper(), lambda error_info: base.abort(404))
)
def get_falcon_style(self, request, response, value):
return value
@ -121,7 +110,7 @@ class DummyEndpoint(object):
return value
class TestValidationFunction(BaseTestCase):
class TestValidationFunction(base.BaseTestCase):
def test_empty_ok(self):
is_upper(empty_ok=True)('')
@ -135,7 +124,7 @@ class TestValidationFunction(BaseTestCase):
is_upper()(None)
class TestValidationDecorator(BaseTestCase):
class TestValidationDecorator(base.BaseTestCase):
def setUp(self):
self.ep = DummyEndpoint()
@ -154,42 +143,42 @@ class TestValidationDecorator(BaseTestCase):
# Try to call with missing params. The validation
# function should never get called
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_style(response, 'HELLO')
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Try to pass a string to a positional argument
# where a response is expected
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_style(request, "bogusinput", 'HELLO')
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Pass in as kwvalues with good input but out of
# typical order (should succeed)
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_style(response=response, value='HELLO',
request=request)
self.assertEqual(oldcount, error_count)
self.assertEqual(oldcount, base.error_count)
# Pass in as kwvalues with good input but out of
# typical order with an invalid value (lower-case 'h')
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_style(response=response, value='hELLO',
request=request)
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Pass in as kwvalues with good input but out of typical order
# and pass an invalid value. Note that here the response is
# assigned to request, etc.
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_style(response=request, value='HELLO',
request=response)
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Happy path
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_style(request, response, 'HELLO')
self.assertEqual(oldcount, error_count)
self.assertEqual(oldcount, base.error_count)
def test_falcon_style_declared_rules(self):
# The following tests repeat the above
@ -197,71 +186,70 @@ class TestValidationDecorator(BaseTestCase):
# endpoint with the rules being declared
# separately. See get_falcon_with_declared_rules above
global error_count
request = DummyRequest()
response = DummyResponse()
# Try to call with missing params. The validation
# function should never get called
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_with_declared_rules(response, 'HELLO')
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Try to pass a string to a positional argument
# where a response is expected
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_with_declared_rules(request, "bogusinput", 'HELLO')
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Pass in as kwvalues with good input but out of
# typical order (should succeed)
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_with_declared_rules(
response=response,
value='HELLO',
request=request)
self.assertEqual(oldcount, error_count)
self.assertEqual(oldcount, base.error_count)
# Pass in as kwvalues with good input but out of
# typical order with an invalid value (lower-case 'h')
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_with_declared_rules(
response=response,
value='hELLO',
request=request)
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Pass in as kwvalues with good input but out of typical order
# and pass an invalid value. Note that here the response is
# assigned to request, etc.
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_with_declared_rules(response=request, value='HELLO',
request=response)
self.assertEqual(oldcount + 1, error_count)
self.assertEqual(oldcount + 1, base.error_count)
# Happy path
oldcount = error_count
oldcount = base.error_count
self.ep.get_falcon_with_declared_rules(request, response, 'HELLO')
self.assertEqual(oldcount, error_count)
self.assertEqual(oldcount, base.error_count)
def test_happy_path_and_validation_failure(self):
global error_count
def test_validation_passed(self):
# Should not throw
res = self.ep.get_value_happy_path('WHATEVER', 'HELLO', 'YES')
self.assertEqual('WHATEVERHELLOYES', res)
def test_validation_failed(self):
# Validation should have failed, and
# we should have seen a tick in the error count
oldcount = error_count
res = self.ep.get_value_happy_path('WHAtEVER', 'HELLO', 'YES')
self.assertEqual(oldcount + 1, error_count)
oldcount = base.error_count
self.ep.get_value_happy_path('WHAtEVER', 'HELLO', 'YES')
self.assertEqual(oldcount + 1, base.error_count)
def test_validating_none_value(self):
# Check passing a None value. This decorator does
# not permit none values.
oldcount = error_count
res = self.ep.get_value_happy_path(None, 'HELLO', 'YES')
self.assertEqual(oldcount + 1, error_count)
oldcount = base.error_count
self.ep.get_value_happy_path(None, 'HELLO', 'YES')
self.assertEqual(oldcount + 1, base.error_count)
def test_getter(self):
global other_vals

View File

@ -5,5 +5,10 @@ hacking
mock
nose
openstack.nose_plugin
oslosphinx
oslotest
sphinx
sphinxcontrib-pecanwsme
sphinxcontrib-httpdomain
requests
testtools

View File

@ -14,7 +14,6 @@
# limitations under the License.
import mock
from oslo.config import cfg
from poppy.manager.default import driver

View File

@ -14,7 +14,6 @@
# limitations under the License.
import mock
from oslo.config import cfg
from poppy.manager.default import driver

View File

@ -19,7 +19,6 @@ import ddt
from poppy.model.helpers import domain
from poppy.model.helpers import origin
from poppy.model import service
from tests.unit import base

View File

@ -13,9 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
import fastly
import mock
from oslo.config import cfg
from poppy.provider.fastly import driver
@ -55,10 +54,10 @@ class TestDriver(base.TestCase):
mock_connect.return_value = MockConnection(None, None)
provider = driver.CDNProvider(self.conf)
client = provider.client()
self.assertNotEquals(client, None)
self.assertNotEqual(client, None)
@mock.patch('poppy.provider.fastly.controllers.ServiceController')
@mock.patch.object(driver, 'FASTLY_OPTIONS', new=FASTLY_OPTIONS)
def test_service_controller(self, MockController):
provider = driver.CDNProvider(self.conf)
self.assertNotEquals(provider.service_controller, None)
self.assertNotEqual(provider.service_controller, None)

View File

@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import ddt
import fastly
import mock
import random
from poppy.provider.fastly import services
from tests.unit import base
@ -170,4 +171,4 @@ class TestServices(base.TestCase):
def test_client(self, mock_driver):
driver = mock_driver()
controller = services.ServiceController(driver)
self.assertNotEquals(controller.client(), None)
self.assertNotEqual(controller.client(), None)

View File

@ -15,7 +15,6 @@
import cassandra
import mock
from oslo.config import cfg
from poppy.storage.cassandra import driver
@ -32,6 +31,7 @@ CASSANDRA_OPTIONS = [
class CassandraStorageServiceTests(base.TestCase):
@mock.patch.object(driver, 'CASSANDRA_OPTIONS', new=CASSANDRA_OPTIONS)
def setUp(self):
super(CassandraStorageServiceTests, self).setUp()
@ -41,13 +41,13 @@ class CassandraStorageServiceTests(base.TestCase):
def test_storage_driver(self):
# assert that the configs are set up based on what was passed in
self.assertEquals(self.cassandra_driver.cassandra_conf['cluster'],
['mock_ip'])
self.assertEquals(self.cassandra_driver.cassandra_conf.keyspace,
'mock_poppy')
self.assertEqual(self.cassandra_driver.cassandra_conf['cluster'],
['mock_ip'])
self.assertEqual(self.cassandra_driver.cassandra_conf.keyspace,
'mock_poppy')
def test_is_alive(self):
self.assertEquals(self.cassandra_driver.is_alive(), True)
self.assertEqual(self.cassandra_driver.is_alive(), True)
@mock.patch.object(cassandra.cluster.Cluster, 'connect')
def test_connection(self, mock_cluster):
@ -57,7 +57,7 @@ class CassandraStorageServiceTests(base.TestCase):
def test_service_controller(self):
sc = self.cassandra_driver.service_controller
self.assertEquals(
self.assertEqual(
isinstance(sc, services.ServicesController),
True)

View File

@ -16,7 +16,6 @@
import cassandra
import ddt
import mock
from oslo.config import cfg
from poppy.storage.cassandra import driver
@ -108,4 +107,4 @@ class CassandraStorageServiceTests(base.TestCase):
@mock.patch.object(cassandra.cluster.Cluster, 'connect')
def test_session(self, mock_service_database):
session = self.sc.session
self.assertNotEquals(session, None)
self.assertNotEqual(session, None)

View File

@ -1,41 +1,47 @@
# Copyright (c) 2014 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.
# # Copyright (c) 2014 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 os
# import os
import mock
from oslo.config import cfg
# import mock
# from oslo.config import cfg
from poppy.transport import pecan
from tests.unit import base
# from poppy.transport import pecan
# from tests.unit import base
class PecanTransportDriverTest(base.TestCase):
# TODO(amitgandhinz): This test is currently failing.
def test_listen(self):
tests_path = os.path.abspath(os.path.dirname(
os.path.dirname(
os.path.dirname(os.path.dirname(__file__)
))))
conf_path = os.path.join(tests_path, 'etc', 'default_functional.conf')
cfg.CONF(args=[], default_config_files=[conf_path])
mock_path = 'poppy.transport.pecan.driver.simple_server'
with mock.patch(mock_path) as mocked_module:
mock_server = mock.Mock()
mocked_module.make_server = mock.Mock(return_value=mock_server)
driver = pecan.Driver(cfg.CONF, None)
driver.listen()
self.assertTrue(mock_server.serve_forever.called)
def mock(self):
pass
# class PecanTransportDriverTest(base.TestCase):
# def test_listen(self):
# tests_path = os.path.abspath(os.path.dirname(
# os.path.dirname(
# os.path.dirname(os.path.dirname(__file__)
# ))))
# conf_path = os.path.join(tests_path, 'etc', 'pecan.py')
# cfg.CONF(args=[], default_config_files=[conf_path])
# mock_path = 'poppy.transport.pecan.driver.simple_server'
# with mock.patch(mock_path) as mocked_module:
# mock_server = mock.Mock()
# mocked_module.make_server = mock.Mock(return_value=mock_server)
# driver = pecan.Driver(cfg.CONF, None)
# driver.listen()
# self.assertTrue(mock_server.serve_forever.called)

View File

@ -38,9 +38,9 @@ def terminate_thread(thread):
class StoppableThread(threading.Thread):
"""Thread class with a stop() method. The thread itself has to check
regularly for the stopped() condition.
"""
"""This thread checks regularly for the stopped() condition."""
def __init__(self, **kwargs):
super(StoppableThread, self).__init__(**kwargs)
self._stop = threading.Event()

View File

@ -1,6 +1,6 @@
[tox]
minversion = 1.6
envlist = py26,py27,py33,pypy,pep8,cover
envlist = py26,py27,py33,pypy,pep8
skipsdist = True
[testenv]
@ -38,6 +38,9 @@ deps = {[testenv]deps}
commands = pylint ./poppy
pylint ./tests
[testenv:docs]
commands = python setup.py build_sphinx
[testenv:cover]
setenv = NOSE_WITH_COVERAGE=1