diff --git a/plugins/soap/cafe/__init__.py b/plugins/soap/cafe/__init__.py new file mode 100644 index 0000000..7543775 --- /dev/null +++ b/plugins/soap/cafe/__init__.py @@ -0,0 +1,16 @@ +""" +Copyright 2014 Rackspace + +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__('pkg_resources').declare_namespace(__name__) diff --git a/plugins/soap/cafe/engine/__init__.py b/plugins/soap/cafe/engine/__init__.py new file mode 100644 index 0000000..52e3d4c --- /dev/null +++ b/plugins/soap/cafe/engine/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2014 Rackspace + +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. +""" diff --git a/plugins/soap/cafe/engine/soap/__init__.py b/plugins/soap/cafe/engine/soap/__init__.py new file mode 100644 index 0000000..52e3d4c --- /dev/null +++ b/plugins/soap/cafe/engine/soap/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2014 Rackspace + +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. +""" diff --git a/plugins/soap/cafe/engine/soap/client.py b/plugins/soap/cafe/engine/soap/client.py new file mode 100644 index 0000000..07a1e3a --- /dev/null +++ b/plugins/soap/cafe/engine/soap/client.py @@ -0,0 +1,60 @@ +""" +Copyright 2014 Rackspace + +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 logging +import suds +import suds.xsd.doctor as suds_doctor + +from cafe.engine.clients.base import BaseClient + + +class BaseSoapClient(BaseClient): + """Base SOAP Client + @summary: Provides a Basic SOAP client by wrapping the lightweight + suds client. + @see: https://fedorahosted.org/suds/ + """ + def __init__(self, wsdl, ns_import_location=None, location=None, + username=None, password=None, faults=False, plugins=None, + cache=None): + super(BaseSoapClient, self).__init__() + logging.getLogger('suds').setLevel(logging.CRITICAL) + + # Fix import for parsing most WSDLs + if ns_import_location is None: + ns_import_location = 'http://schemas.xmlsoap.org/soap/encoding/' + ns_import = suds_doctor.Import(ns_import_location) + doctor = suds_doctor.ImportDoctor(ns_import) + + if plugins is None: + plugins = [doctor] + else: + plugins.extend([doctor]) + self.client = suds.client.Client(wsdl, + location=location, + username=username, + password=password, + faults=faults, + plugins=plugins, + cache=cache) + + def get_service(self): + """ Get Service + @summary: Gets the service methods from the instantiated client. + @return: self.client.service + @rtype: Tuple + """ + return self.client.service diff --git a/plugins/soap/setup.py b/plugins/soap/setup.py new file mode 100644 index 0000000..9a7cad1 --- /dev/null +++ b/plugins/soap/setup.py @@ -0,0 +1,46 @@ +""" +Copyright 2013 Rackspace + +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 setuptools import setup, find_packages +import sys +from setuptools.command.test import test as TestCommand + + +# tox integration +class Tox(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = [] + self.test_suite = True + + def run_tests(self): + # import here, cause outside the eggs aren't loaded + import tox + errno = tox.cmdline(self.test_args) + sys.exit(errno) + +setup( + name='cafe_soap_plugin', + version='0.0.1', + description='The Common Automation Framework Engine', + author='Rackspace Cloud QE', + author_email='cloud-cafe@lists.rackspace.com', + url='http://rackspace.com', + packages=find_packages(), + namespace_packages=['cafe'], + install_requires=['suds'], + tests_require=['tox'], + cmdclass={'test': Tox}, + zip_safe=False) diff --git a/plugins/soap/test-requirements.txt b/plugins/soap/test-requirements.txt new file mode 100644 index 0000000..6e643c4 --- /dev/null +++ b/plugins/soap/test-requirements.txt @@ -0,0 +1,4 @@ +tox +mock +flake8 +nose \ No newline at end of file diff --git a/plugins/soap/tests/__init__.py b/plugins/soap/tests/__init__.py new file mode 100644 index 0000000..52e3d4c --- /dev/null +++ b/plugins/soap/tests/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2014 Rackspace + +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. +""" diff --git a/plugins/soap/tests/engine/__init__.py b/plugins/soap/tests/engine/__init__.py new file mode 100644 index 0000000..52e3d4c --- /dev/null +++ b/plugins/soap/tests/engine/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2014 Rackspace + +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. +""" diff --git a/plugins/soap/tests/engine/clients/__init__.py b/plugins/soap/tests/engine/clients/__init__.py new file mode 100644 index 0000000..52e3d4c --- /dev/null +++ b/plugins/soap/tests/engine/clients/__init__.py @@ -0,0 +1,15 @@ +""" +Copyright 2014 Rackspace + +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. +""" diff --git a/plugins/soap/tests/engine/clients/test_soap.py b/plugins/soap/tests/engine/clients/test_soap.py new file mode 100644 index 0000000..38e55d6 --- /dev/null +++ b/plugins/soap/tests/engine/clients/test_soap.py @@ -0,0 +1,49 @@ +""" +Copyright 2014 Rackspace + +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 mock import MagicMock +import unittest + +from cafe.engine.soap.client import BaseSoapClient + + +class SoapClientTests(unittest.TestCase): + + @classmethod + def setUpClass(cls): + super(SoapClientTests, cls).setUpClass() + + cls.wsdl = "http://fake.wsdl" + cls.endpoint = "http://fake.url.endpoint" + cls.username = "fake_username" + cls.password = "fakepassword12345" + cls.plugins = None + + def test_create_soap_client_object(self): + soap_client_object = BaseSoapClient + soap_client_object.__init__ = MagicMock() + soap_client_object.__init__( + wsdl=self.wsdl, + endpoint=self.endpoint, + username=self.username, + password=self.password, + plugins=self.plugins) + soap_client_object.__init__.assert_called_once_with( + wsdl=self.wsdl, + endpoint=self.endpoint, + username=self.username, + password=self.password, + plugins=self.plugins) diff --git a/plugins/soap/tox.ini b/plugins/soap/tox.ini new file mode 100644 index 0000000..d85c424 --- /dev/null +++ b/plugins/soap/tox.ini @@ -0,0 +1,17 @@ +[tox] +envlist=pep8,py27 + +[testenv] +setenv=VIRTUAL_ENV={envdir} + +deps=-r{toxinidir}/test-requirements.txt + +[testenv:py27] +commands=nosetests {toxinidir} + +[testenv:pep8] +commands=flake8 + +[flake8] +ignore=F401 +exclude=.git,.idea,docs,.tox,bin,dist,tools,*.egg-info \ No newline at end of file