diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pecantest/setup.cfg | 6 | ||||
-rw-r--r-- | tests/pecantest/setup.py | 22 | ||||
-rw-r--r-- | tests/pecantest/test/__init__.py | 0 | ||||
-rw-r--r-- | tests/pecantest/test/app.py | 15 | ||||
-rw-r--r-- | tests/pecantest/test/controllers/__init__.py | 0 | ||||
-rw-r--r-- | tests/pecantest/test/controllers/root.py | 21 | ||||
-rw-r--r-- | tests/pecantest/test/controllers/ws.py | 150 | ||||
-rw-r--r-- | tests/pecantest/test/model/__init__.py | 2 | ||||
-rw-r--r-- | tests/pecantest/test/tests/__init__.py | 22 | ||||
-rw-r--r-- | tests/pecantest/test/tests/config.py | 24 | ||||
-rw-r--r-- | tests/pecantest/test/tests/test_ws.py | 247 | ||||
-rw-r--r-- | tests/rest/test_args.py | 20 | ||||
-rw-r--r-- | tests/sphinxexample/conf.py | 232 | ||||
-rw-r--r-- | tests/sphinxexample/document.rst | 43 | ||||
-rw-r--r-- | tests/sphinxexample/index.rst | 3 | ||||
-rw-r--r-- | tests/test_cornice.py | 183 | ||||
-rw-r--r-- | tests/test_flask.py | 216 | ||||
-rw-r--r-- | tests/test_sphinxext.py | 51 | ||||
-rw-r--r-- | tests/test_tg1.py | 196 | ||||
-rw-r--r-- | tests/test_tg15.py | 177 |
20 files changed, 0 insertions, 1630 deletions
diff --git a/tests/pecantest/setup.cfg b/tests/pecantest/setup.cfg deleted file mode 100644 index 00ca220..0000000 --- a/tests/pecantest/setup.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[nosetests] -match=^test -where=test -nocapture=1 -cover-package=test -cover-erase=1 diff --git a/tests/pecantest/setup.py b/tests/pecantest/setup.py deleted file mode 100644 index b901f62..0000000 --- a/tests/pecantest/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- -try: - from setuptools import setup, find_packages -except ImportError: - from ez_setup import use_setuptools - use_setuptools() - from setuptools import setup, find_packages - -setup( - name = 'test', - version = '0.1', - description = '', - author = '', - author_email = '', - install_requires = [ - "pecan", - ], - test_suite = 'test', - zip_safe = False, - include_package_data = True, - packages = find_packages(exclude=['ez_setup']) -) diff --git a/tests/pecantest/test/__init__.py b/tests/pecantest/test/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tests/pecantest/test/__init__.py +++ /dev/null diff --git a/tests/pecantest/test/app.py b/tests/pecantest/test/app.py deleted file mode 100644 index 727c357..0000000 --- a/tests/pecantest/test/app.py +++ /dev/null @@ -1,15 +0,0 @@ -from pecan import make_app -from test import model - -def setup_app(config): - - model.init_model() - - return make_app( - config.app.root, - static_root = config.app.static_root, - template_path = config.app.template_path, - logging = getattr(config, 'logging', {}), - debug = getattr(config.app, 'debug', False), - force_canonical = getattr(config.app, 'force_canonical', True) - ) diff --git a/tests/pecantest/test/controllers/__init__.py b/tests/pecantest/test/controllers/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tests/pecantest/test/controllers/__init__.py +++ /dev/null diff --git a/tests/pecantest/test/controllers/root.py b/tests/pecantest/test/controllers/root.py deleted file mode 100644 index 6e87267..0000000 --- a/tests/pecantest/test/controllers/root.py +++ /dev/null @@ -1,21 +0,0 @@ -from pecan import expose -from webob.exc import status_map -from .ws import AuthorsController -from wsmeext.pecan import wsexpose - - -class RootController(object): - authors = AuthorsController() - - @expose('error.html') - def error(self, status): - try: - status = int(status) - except ValueError: # pragma: no cover - status = 500 - message = getattr(status_map.get(status), 'explanation', '') - return dict(status=status, message=message) - - @wsexpose() - def divide_by_zero(self): - 1 / 0 diff --git a/tests/pecantest/test/controllers/ws.py b/tests/pecantest/test/controllers/ws.py deleted file mode 100644 index b35a0c6..0000000 --- a/tests/pecantest/test/controllers/ws.py +++ /dev/null @@ -1,150 +0,0 @@ -# encoding=utf8 -from pecan.rest import RestController - -from wsme.types import Base, text, wsattr - -import wsme -import wsmeext.pecan - -import six - - -class Author(Base): - id = int - firstname = text - books = wsattr(['Book']) - - @staticmethod - def validate(author): - if author.firstname == 'Robert': - raise wsme.exc.ClientSideError("I don't like this author!") - return author - - -class Book(Base): - id = int - name = text - author = wsattr('Author') - - -class BookNotFound(Exception): - message = "Book with ID={id} Not Found" - code = 404 - - def __init__(self, id): - message = self.message.format(id=id) - super(BookNotFound, self).__init__(message) - - -class NonHttpException(Exception): - message = "Internal Exception for Book ID={id}" - code = 684 - - def __init__(self, id): - message = self.message.format(id=id) - super(NonHttpException, self).__init__(message) - - -class BooksController(RestController): - - @wsmeext.pecan.wsexpose(Book, int, int) - def get(self, author_id, id): - book = Book( - name=u"Les Confessions d’un révolutionnaire pour servir à " - u"l’histoire de la révolution de février", - author=Author(lastname=u"Proudhon") - ) - return book - - @wsmeext.pecan.wsexpose(Book, int, int, body=Book) - def put(self, author_id, id, book=None): - book.id = id - book.author = Author(id=author_id) - return book - - -class Criterion(Base): - op = text - attrname = text - value = text - - -class AuthorsController(RestController): - - _custom_actions = { - 'json_only': ['GET'], - 'xml_only': ['GET'] - } - - books = BooksController() - - @wsmeext.pecan.wsexpose([Author], [six.text_type], [Criterion]) - def get_all(self, q=None, r=None): - if q: - return [ - Author(id=i, firstname=value) - for i, value in enumerate(q) - ] - if r: - return [ - Author(id=i, firstname=c.value) - for i, c in enumerate(r) - ] - return [ - Author(id=1, firstname=u'FirstName') - ] - - @wsmeext.pecan.wsexpose(Author, int) - def get(self, id): - if id == 999: - raise wsme.exc.ClientSideError('Wrong ID') - - if id == 998: - raise BookNotFound(id) - - if id == 997: - raise NonHttpException(id) - - if id == 996: - raise wsme.exc.ClientSideError('Disabled ID', status_code=403) - - if id == 911: - return wsme.api.Response(Author(), - status_code=401) - if id == 912: - return wsme.api.Response(None, status_code=204) - - if id == 913: - return wsme.api.Response('foo', status_code=200, return_type=text) - - author = Author() - author.id = id - author.firstname = u"aname" - author.books = [ - Book( - name=u"Les Confessions d’un révolutionnaire pour servir à " - u"l’histoire de la révolution de février", - ) - ] - return author - - @wsmeext.pecan.wsexpose(Author, body=Author, status_code=201) - def post(self, author): - author.id = 10 - return author - - @wsmeext.pecan.wsexpose(None, int) - def delete(self, author_id): - print("Deleting", author_id) - - @wsmeext.pecan.wsexpose(Book, int, body=Author) - def put(self, author_id, author=None): - return author - - @wsmeext.pecan.wsexpose([Author], rest_content_types=('json',)) - def json_only(self): - return [Author(id=1, firstname=u"aname", books=[])] - - @wsmeext.pecan.wsexpose([Author], rest_content_types=('xml',)) - def xml_only(self): - return [Author(id=1, firstname=u"aname", books=[])] diff --git a/tests/pecantest/test/model/__init__.py b/tests/pecantest/test/model/__init__.py deleted file mode 100644 index ab4be6a..0000000 --- a/tests/pecantest/test/model/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -def init_model(): - pass diff --git a/tests/pecantest/test/tests/__init__.py b/tests/pecantest/test/tests/__init__.py deleted file mode 100644 index 04fa0a6..0000000 --- a/tests/pecantest/test/tests/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -import os -from unittest import TestCase -from pecan import set_config -from pecan import testing - -__all__ = ['FunctionalTest'] - - -class FunctionalTest(TestCase): - """ - Used for functional tests where you need to test your - literal application and its integration with the framework. - """ - - def setUp(self): - self.app = testing.load_test_app(os.path.join( - os.path.dirname(__file__), - 'config.py' - )) - - def tearDown(self): - set_config({}, overwrite=True) diff --git a/tests/pecantest/test/tests/config.py b/tests/pecantest/test/tests/config.py deleted file mode 100644 index 3f35dcf..0000000 --- a/tests/pecantest/test/tests/config.py +++ /dev/null @@ -1,24 +0,0 @@ -# Server Specific Configurations -server = { - 'port' : '8080', - 'host' : '0.0.0.0' -} - -# Pecan Application Configurations -app = { - 'root' : 'test.controllers.root.RootController', - 'modules' : ['test'], - 'static_root' : '%(confdir)s/../../public', - 'template_path' : '%(confdir)s/../templates', - '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 diff --git a/tests/pecantest/test/tests/test_ws.py b/tests/pecantest/test/tests/test_ws.py deleted file mode 100644 index ae06650..0000000 --- a/tests/pecantest/test/tests/test_ws.py +++ /dev/null @@ -1,247 +0,0 @@ -from six.moves import http_client -from test.tests import FunctionalTest -import json -import pecan -import six - - -used_status_codes = [400, 401, 403, 404, 500] -http_response_messages = {} -for code in used_status_codes: - http_response_messages[code] = '%s %s' % (code, http_client.responses[code]) - -class TestWS(FunctionalTest): - - def test_get_all(self): - self.app.get('/authors') - - def test_optional_array_param(self): - r = self.app.get('/authors?q=a&q=b') - l = json.loads(r.body.decode('utf-8')) - assert len(l) == 2 - assert l[0]['firstname'] == 'a' - assert l[1]['firstname'] == 'b' - - def test_optional_indexed_array_param(self): - r = self.app.get('/authors?q[0]=a&q[1]=b') - l = json.loads(r.body.decode('utf-8')) - assert len(l) == 2 - assert l[0]['firstname'] == 'a' - assert l[1]['firstname'] == 'b' - - def test_options_object_array_param(self): - r = self.app.get('/authors?r.value=a&r.value=b') - l = json.loads(r.body.decode('utf-8')) - assert len(l) == 2 - assert l[0]['firstname'] == 'a' - assert l[1]['firstname'] == 'b' - - def test_options_indexed_object_array_param(self): - r = self.app.get('/authors?r[0].value=a&r[1].value=b') - l = json.loads(r.body.decode('utf-8')) - assert len(l) == 2 - assert l[0]['firstname'] == 'a' - assert l[1]['firstname'] == 'b' - - def test_get_author(self): - a = self.app.get( - '/authors/1.json', - ) - a = json.loads(a.body.decode('utf-8')) - - assert a['id'] == 1 - assert a['firstname'] == 'aname' - - a = self.app.get( - '/authors/1.xml', - ) - body = a.body.decode('utf-8') - assert '<id>1</id>' in body - assert '<firstname>aname</firstname>' in body - - def test_post_body_parameter_validation(self): - res = self.app.post( - '/authors', '{"firstname": "Robert"}', - headers={"Content-Type": "application/json"}, - expect_errors=True - ) - self.assertEqual(res.status_int, 400) - a = json.loads(res.body.decode('utf-8')) - self.assertEqual(a['faultcode'], 'Client') - self.assertEqual(a['faultstring'], "I don't like this author!") - - def test_post_body_parameter(self): - res = self.app.post( - '/authors', '{"firstname": "test"}', - headers={"Content-Type": "application/json"} - ) - assert res.status_int == 201 - a = json.loads(res.body.decode('utf-8')) - assert a['id'] == 10 - assert a['firstname'] == 'test' - - def test_put_parameter_validate(self): - res = self.app.put( - '/authors/foobar', '{"firstname": "test"}', - headers={"Content-Type": "application/json"}, - expect_errors=True - ) - self.assertEqual(res.status_int, 400) - a = json.loads(res.body.decode('utf-8')) - self.assertEqual( - a['faultstring'], - "Invalid input for field/attribute author_id. " - "Value: 'foobar'. unable to convert to int. Error: invalid " - "literal for int() with base 10: 'foobar'") - - def test_clientsideerror(self): - expected_status_code = 400 - expected_status = http_response_messages[expected_status_code] - res = self.app.get( - '/authors/999.json', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - a = json.loads(res.body.decode('utf-8')) - assert a['faultcode'] == 'Client' - - res = self.app.get( - '/authors/999.xml', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - assert '<faultcode>Client</faultcode>' in res.body.decode('utf-8') - - def test_custom_clientside_error(self): - expected_status_code = 404 - expected_status = http_response_messages[expected_status_code] - res = self.app.get( - '/authors/998.json', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - a = json.loads(res.body.decode('utf-8')) - assert a['faultcode'] == 'Client' - - res = self.app.get( - '/authors/998.xml', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - assert '<faultcode>Client</faultcode>' in res.body.decode('utf-8') - - def test_custom_non_http_clientside_error(self): - expected_status_code = 500 - expected_status = http_response_messages[expected_status_code] - res = self.app.get( - '/authors/997.json', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - a = json.loads(res.body.decode('utf-8')) - assert a['faultcode'] == 'Server' - - res = self.app.get( - '/authors/997.xml', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - assert '<faultcode>Server</faultcode>' in res.body.decode('utf-8') - - def test_clientsideerror_status_code(self): - expected_status_code = 403 - expected_status = http_response_messages[expected_status_code] - res = self.app.get( - '/authors/996.json', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - a = json.loads(res.body.decode('utf-8')) - assert a['faultcode'] == 'Client' - - res = self.app.get( - '/authors/996.xml', - expect_errors=True - ) - self.assertEqual(res.status, expected_status) - assert '<faultcode>Client</faultcode>' in res.body.decode('utf-8') - - def test_non_default_response(self): - expected_status_code = 401 - expected_status = http_response_messages[expected_status_code] - res = self.app.get( - '/authors/911.json', - expect_errors=True - ) - self.assertEqual(res.status_int, expected_status_code) - self.assertEqual(res.status, expected_status) - - def test_non_default_response_return_type(self): - res = self.app.get( - '/authors/913', - ) - self.assertEqual(res.status_int, 200) - self.assertEqual(res.body, b'"foo"') - self.assertEqual(res.content_length, 5) - - def test_non_default_response_return_type_no_content(self): - res = self.app.get( - '/authors/912', - ) - self.assertEqual(res.status_int, 204) - self.assertEqual(res.body, b'') - self.assertEqual(res.content_length, 0) - - def test_serversideerror(self): - expected_status_code = 500 - expected_status = http_response_messages[expected_status_code] - res = self.app.get('/divide_by_zero.json', expect_errors=True) - self.assertEqual(res.status, expected_status) - a = json.loads(res.body.decode('utf-8')) - assert a['faultcode'] == 'Server' - assert a['debuginfo'] is None - - def test_serversideerror_with_debug(self): - expected_status_code = 500 - expected_status = http_response_messages[expected_status_code] - pecan.set_config({'wsme': {'debug': True}}) - res = self.app.get('/divide_by_zero.json', expect_errors=True) - self.assertEqual(res.status, expected_status) - a = json.loads(res.body.decode('utf-8')) - assert a['faultcode'] == 'Server' - assert a['debuginfo'].startswith('Traceback (most recent call last):') - - def test_json_only(self): - res = self.app.get('/authors/json_only.json') - assert res.status_int == 200 - body = json.loads(res.body.decode('utf-8')) - assert len(body) == 1 - assert body[0]['firstname'] == u"aname" - assert body[0]['books'] == [] - assert body[0]['id'] == 1 - res = self.app.get('/authors/json_only.xml', expect_errors=True) - - def test_xml_only(self): - res = self.app.get('/authors/xml_only.xml') - assert res.status_int == 200 - assert '<id>1</id>' in res.body.decode('utf-8') - assert '<firstname>aname</firstname>' in res.body.decode('utf-8') - assert '<books />' in res.body.decode('utf-8') - res = self.app.get('/authors/xml_only.json', expect_errors=True) - - def test_body_parameter(self): - res = self.app.put( - '/authors/1/books/2.json', - '{"name": "Alice au pays des merveilles"}', - headers={"Content-Type": "application/json"} - ) - book = json.loads(res.body.decode('utf-8')) - assert book['id'] == 2 - assert book['author']['id'] == 1 - - def test_no_content_type_if_no_return_type(self): - if six.PY3: - self.skipTest( - "This test does not work in Python 3 until https://review.openstack.org/#/c/48439/ is merged") - res = self.app.delete('/authors/4') - assert "Content-Type" not in res.headers, res.headers['Content-Type'] diff --git a/tests/rest/test_args.py b/tests/rest/test_args.py deleted file mode 100644 index 4ae3246..0000000 --- a/tests/rest/test_args.py +++ /dev/null @@ -1,20 +0,0 @@ -import mock -import unittest - -from wsme import exc -from wsme.rest import args -from wsme.rest import json - - -class TestArgs(unittest.TestCase): - - def test_args_from_body(self): - - funcdef = mock.MagicMock() - body = mock.MagicMock() - mimetype = "application/json" - funcdef.ignore_extra_args = True - json.parse = mock.MagicMock() - json.parse.side_effect = (exc.UnknownArgument("")) - resp = args.args_from_body(funcdef, body, mimetype) - self.assertEqual(resp, ((), {})) diff --git a/tests/sphinxexample/conf.py b/tests/sphinxexample/conf.py deleted file mode 100644 index ec478dd..0000000 --- a/tests/sphinxexample/conf.py +++ /dev/null @@ -1,232 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Web Services Made Easy documentation build configuration file, created by -# sphinx-quickstart on Sun Oct 2 20:27:45 2011. -# -# This file is execfile()d with the current directory set to its containing dir. -# -# Note that not all possible configuration values are present in this -# autogenerated file. -# -# All configuration values have a default; values that are commented out -# serve to show the default. - -import sys, os - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('..')) - -# -- General configuration ----------------------------------------------------- - -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - -# Add any Sphinx extension module names here, as strings. They can be extensions -# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'wsmeext.sphinxext'] - -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - -# The suffix of source filenames. -source_suffix = '.rst' - -# The encoding of source files. -#source_encoding = 'utf-8-sig' - -# The master toctree document. -master_doc = 'index' - -# General information about the project. -project = u'wsmeext.sphinxext Test' -copyright = u'2011, Christophe de Vienne' - -# The version info for the project you're documenting, acts as replacement for -# |version| and |release|, also used in various other places throughout the -# built documents. -# -import pkg_resources -dist = pkg_resources.require('WSME')[0] - -# The short X.Y version. -version = '.'.join(dist.version[:2]) -# The full version, including alpha/beta/rc tags. -release = dist.version - -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to some -# non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - -# List of patterns, relative to source directory, that match files and -# directories to ignore when looking for source files. -exclude_patterns = ['_build'] - -# The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - - -# -- Options for HTML output --------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'agogo' -html_theme_options = { - "pagewidth": "60em", - "documentwidth": "40em", -} - -html_style = 'wsme.css' - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - -# The name for this set of Sphinx documents. If None, it defaults to -# "<project> v<release> documentation". -html_title = "WSME %s" % release - -# A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None - -# The name of an image file (relative to this directory) to place at the top -# of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon of the -# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 -# pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] - -# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, -# using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names to -# template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages will -# contain a <link> tag referring to it. The value of this option must be the -# base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - -# Output file base name for HTML help builder. -htmlhelp_basename = 'WebServicesMadeEasydoc' - - -# -- Options for LaTeX output -------------------------------------------------- - -# The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' - -# The font size ('10pt', '11pt' or '12pt'). -#latex_font_size = '10pt' - -# Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). -latex_documents = [ - ('index', 'WebServicesMadeEasy.tex', u'Web Services Made Easy Documentation', - u'Christophe de Vienne', 'manual'), -] - -# The name of an image file (relative to this directory) to place at the top of -# the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False - -# If true, show page references after internal links. -#latex_show_pagerefs = False - -# If true, show URL addresses after external links. -#latex_show_urls = False - -# Additional stuff for the LaTeX preamble. -#latex_preamble = '' - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_domain_indices = True - - -# -- Options for manual page output -------------------------------------------- - -# One entry per manual page. List of tuples -# (source start file, name, description, authors, manual section). -man_pages = [ - ('index', 'webservicesmadeeasy', u'Web Services Made Easy Documentation', - [u'Christophe de Vienne'], 1) -] - - -autodoc_member_order = 'bysource' - -wsme_protocols = [ - 'restjson', 'restxml' -] diff --git a/tests/sphinxexample/document.rst b/tests/sphinxexample/document.rst deleted file mode 100644 index 41af798..0000000 --- a/tests/sphinxexample/document.rst +++ /dev/null @@ -1,43 +0,0 @@ -API Documentation test -====================== - -Example -~~~~~~~ - -.. wsme:root:: wsmeext.sphinxext.SampleService - :webpath: /api - -.. wsme:type:: MyType - - .. wsme:attribute:: test - - :type: int - -.. wsme:service:: name/space/SampleService - - .. wsme:function:: getType - - Returns a :wsme:type:`MyType <MyType>` - - -.. default-domain:: wsme - -.. type:: int - - An integer - -.. autotype:: wsmeext.sphinxext.SampleType - :members: - -.. autoservice:: wsmeext.sphinxext.SampleService - :members: - - -.. autotype:: test_sphinxext.ASampleType - :members: - -.. autotype:: wsme.types.bytes - -.. autotype:: wsme.types.text - -.. _Sphinx: http://sphinx.pocoo.org/ diff --git a/tests/sphinxexample/index.rst b/tests/sphinxexample/index.rst deleted file mode 100644 index 76d9c55..0000000 --- a/tests/sphinxexample/index.rst +++ /dev/null @@ -1,3 +0,0 @@ -.. toctree:: - - document diff --git a/tests/test_cornice.py b/tests/test_cornice.py deleted file mode 100644 index 77a55e0..0000000 --- a/tests/test_cornice.py +++ /dev/null @@ -1,183 +0,0 @@ -import unittest -import json - -import webtest - -from cornice import Service -from cornice import resource -from pyramid.config import Configurator -from pyramid.httpexceptions import HTTPUnauthorized - -from wsme.types import text, Base, HostRequest -from wsmeext.cornice import signature - - -class User(Base): - id = int - name = text - -users = Service(name='users', path='/users') - - -@users.get() -@signature([User]) -def users_get(): - return [User(id=1, name='first')] - - -@users.post() -@signature(User, body=User) -def users_create(data): - data.id = 2 - return data - - -secret = Service(name='secrets', path='/secret') - - -@secret.get() -@signature() -def secret_get(): - raise HTTPUnauthorized() - - -divide = Service(name='divide', path='/divide') - - -@divide.get() -@signature(int, int, int) -def do_divide(a, b): - return a / b - -needrequest = Service(name='needrequest', path='/needrequest') - - -@needrequest.get() -@signature(bool, HostRequest) -def needrequest_get(request): - assert request.path == '/needrequest', request.path - return True - - -class Author(Base): - authorId = int - name = text - - -@resource.resource(collection_path='/author', path='/author/{authorId}') -class AuthorResource(object): - def __init__(self, request): - self.request = request - - @signature(Author, int) - def get(self, authorId): - return Author(authorId=authorId, name="Author %s" % authorId) - - @signature(Author, int, body=Author) - def post(self, authorId, data): - data.authorId = authorId - return data - - @signature([Author], text) - def collection_get(self, where=None): - return [ - Author(authorId=1, name="Author 1"), - Author(authorId=2, name="Author 2"), - Author(authorId=3, name="Author 3") - ] - - -def make_app(): - config = Configurator() - config.include("cornice") - config.include("wsmeext.cornice") - config.scan("test_cornice") - return config.make_wsgi_app() - - -class WSMECorniceTestCase(unittest.TestCase): - def setUp(self): - self.app = webtest.TestApp(make_app()) - - def test_get_json_list(self): - resp = self.app.get('/users') - self.assertEqual( - resp.body, - b'[{"id": 1, "name": "first"}]' - ) - - def test_get_xml_list(self): - resp = self.app.get('/users', headers={"Accept": "text/xml"}) - self.assertEqual( - resp.body, - b'<result><item><id>1</id><name>first</name></item></result>' - ) - - def test_post_json_data(self): - data = json.dumps({"name": "new"}) - resp = self.app.post( - '/users', data, - headers={"Content-Type": "application/json"} - ) - self.assertEqual( - resp.body, - b'{"id": 2, "name": "new"}' - ) - - def test_post_xml_data(self): - data = '<data><name>new</name></data>' - resp = self.app.post( - '/users', data, - headers={"Content-Type": "text/xml"} - ) - self.assertEqual( - resp.body, - b'<result><id>2</id><name>new</name></result>' - ) - - def test_pass_request(self): - resp = self.app.get('/needrequest') - assert resp.json is True - - def test_resource_collection_get(self): - resp = self.app.get('/author') - assert len(resp.json) == 3 - assert resp.json[0]['name'] == 'Author 1' - assert resp.json[1]['name'] == 'Author 2' - assert resp.json[2]['name'] == 'Author 3' - - def test_resource_get(self): - resp = self.app.get('/author/5') - assert resp.json['name'] == 'Author 5' - - def test_resource_post(self): - resp = self.app.post( - '/author/5', - json.dumps({"name": "Author 5"}), - headers={"Content-Type": "application/json"} - ) - assert resp.json['authorId'] == 5 - assert resp.json['name'] == 'Author 5' - - def test_server_error(self): - resp = self.app.get('/divide?a=1&b=0', expect_errors=True) - self.assertEqual(resp.json['faultcode'], 'Server') - self.assertEqual(resp.status_code, 500) - - def test_client_error(self): - resp = self.app.get( - '/divide?a=1&c=0', - headers={'Accept': 'application/json'}, - expect_errors=True - ) - self.assertEqual(resp.json['faultcode'], 'Client') - self.assertEqual(resp.status_code, 400) - - def test_runtime_error(self): - resp = self.app.get( - '/secret', - headers={'Accept': 'application/json'}, - expect_errors=True - ) - self.assertEqual(resp.json['faultcode'], 'Client') - self.assertEqual(resp.status_code, 401) diff --git a/tests/test_flask.py b/tests/test_flask.py deleted file mode 100644 index f039f45..0000000 --- a/tests/test_flask.py +++ /dev/null @@ -1,216 +0,0 @@ -# encoding=utf8 -import unittest -from flask import Flask, json, abort -import flask_restful as restful - -from wsmeext.flask import signature -from wsme.api import Response -from wsme.types import Base, text - - -class Model(Base): - id = int - name = text - - -class Criterion(Base): - op = text - attr = text - value = text - -test_app = Flask(__name__) -api = restful.Api(test_app) - - -@test_app.route('/multiply') -@signature(int, int, int) -def multiply(a, b): - return a * b - - -@test_app.route('/divide_by_zero') -@signature(None) -def divide_by_zero(): - return 1 / 0 - - -@test_app.route('/models') -@signature([Model], [Criterion]) -def list_models(q=None): - if q: - name = q[0].value - else: - name = 'first' - return [Model(name=name)] - - -@test_app.route('/models/<name>') -@signature(Model, text) -def get_model(name): - return Model(name=name) - - -@test_app.route('/models/<name>/secret') -@signature(Model, text) -def model_secret(name): - abort(403) - - -@test_app.route('/models/<name>/custom-error') -@signature(Model, text) -def model_custom_error(name): - class CustomError(Exception): - code = 412 - raise CustomError("FOO!") - - -@test_app.route('/models', methods=['POST']) -@signature(Model, body=Model) -def post_model(body): - return Model(name=body.name) - - -@test_app.route('/status_sig') -@signature(int, status_code=201) -def get_status_sig(): - return 1 - - -@test_app.route('/status_response') -@signature(int) -def get_status_response(): - return Response(1, status_code=201) - - -class RestFullApi(restful.Resource): - @signature(Model) - def get(self): - return Model(id=1, name=u"Gérard") - - @signature(int, body=Model) - def post(self, model): - return model.id - -api.add_resource(RestFullApi, '/restful') - - -class FlaskrTestCase(unittest.TestCase): - - def setUp(self): - test_app.config['TESTING'] = True - self.app = test_app.test_client() - - def tearDown(self): - pass - - def test_multiply(self): - r = self.app.get('/multiply?a=2&b=5') - assert r.data == b'10', r.data - - def test_get_model(self): - resp = self.app.get('/models/test') - assert resp.status_code == 200 - - def test_list_models(self): - resp = self.app.get('/models') - assert resp.status_code == 200 - - def test_array_parameter(self): - resp = self.app.get('/models?q.op=%3D&q.attr=name&q.value=second') - assert resp.status_code == 200 - self.assertEqual( - resp.data, b'[{"name": "second"}]' - ) - - def test_post_model(self): - resp = self.app.post('/models', data={"body.name": "test"}) - assert resp.status_code == 200 - resp = self.app.post( - '/models', - data=json.dumps({"name": "test"}), - content_type="application/json" - ) - assert resp.status_code == 200 - - def test_get_status_sig(self): - resp = self.app.get('/status_sig') - assert resp.status_code == 201 - - def test_get_status_response(self): - resp = self.app.get('/status_response') - assert resp.status_code == 201 - - def test_custom_clientside_error(self): - r = self.app.get( - '/models/test/secret', - headers={'Accept': 'application/json'} - ) - assert r.status_code == 403, r.status_code - assert '403 Forbidden:' in json.loads(r.data)['faultstring'] - - r = self.app.get( - '/models/test/secret', - headers={'Accept': 'application/xml'} - ) - assert r.status_code == 403, r.status_code - assert r.data == (b"<error><faultcode>Client</faultcode>" - b"<faultstring>403 Forbidden: You don't have the " - b"permission to access the requested resource. It " - b"is either read-protected or not readable by the " - b"server." - b"</faultstring><debuginfo /></error>") - - # NOTE(cdent): For reasons unclear, 'r' here has no value on data - # even though it does earlier in the stack. If works with Werkzeug - # <0.14.0 but not after. As WSME does not have test-requirement, nor - # pinning, so not a lot to do here. - @unittest.expectedFailure - def test_custom_non_http_clientside_error(self): - r = self.app.get( - '/models/test/custom-error', - headers={'Accept': 'application/json'} - ) - assert r.status_code == 412, r.status_code - assert json.loads(r.data)['faultstring'] == 'FOO!' - - r = self.app.get( - '/models/test/custom-error', - headers={'Accept': 'application/xml'} - ) - assert r.status_code == 412, r.status_code - assert r.data == (b'<error><faultcode>Client</faultcode>' - b'<faultstring>FOO!</faultstring>' - b'<debuginfo /></error>') - - def test_serversideerror(self): - r = self.app.get('/divide_by_zero') - assert r.status_code == 500 - data = json.loads(r.data) - self.assertEqual(data['debuginfo'], None) - self.assertEqual(data['faultcode'], 'Server') - self.assertIn('by zero', data['faultstring']) - - def test_restful_get(self): - r = self.app.get('/restful', headers={'Accept': 'application/json'}) - self.assertEqual(r.status_code, 200) - - data = json.loads(r.data) - - self.assertEqual(data['id'], 1) - self.assertEqual(data['name'], u"Gérard") - - def test_restful_post(self): - r = self.app.post( - '/restful', - data=json.dumps({'id': 5, 'name': u'Huguette'}), - headers={ - 'Accept': 'application/json', - 'Content-Type': 'application/json'}) - self.assertEqual(r.status_code, 200) - - data = json.loads(r.data) - - self.assertEqual(data, 5) - -if __name__ == '__main__': - test_app.run() diff --git a/tests/test_sphinxext.py b/tests/test_sphinxext.py deleted file mode 100644 index 78f80dd..0000000 --- a/tests/test_sphinxext.py +++ /dev/null @@ -1,51 +0,0 @@ -import unittest -import sphinx -import os.path - -import wsme.types -from wsmeext import sphinxext - -docpath = os.path.join( - os.path.dirname(__file__), - 'sphinxexample') - - -class ASampleType(object): - somebytes = wsme.types.bytes - sometext = wsme.types.text - someint = int - - -class TestSphinxExt(unittest.TestCase): - def test_buildhtml(self): - if not os.path.exists('.test_sphinxext/'): - os.makedirs('.test_sphinxext/') - try: - sphinx.main([ - '', - '-b', 'html', - '-d', '.test_sphinxext/doctree', - docpath, - '.test_sphinxext/html' - ]) - assert Exception("Should raise SystemExit 0") - except SystemExit as e: - assert e.code == 0 - - -class TestDataTypeName(unittest.TestCase): - def test_user_type(self): - self.assertEqual(sphinxext.datatypename(ASampleType), - 'ASampleType') - - def test_dict_type(self): - d = wsme.types.DictType(str, str) - self.assertEqual(sphinxext.datatypename(d), 'dict(str: str)') - d = wsme.types.DictType(str, ASampleType) - self.assertEqual(sphinxext.datatypename(d), 'dict(str: ASampleType)') - - def test_array_type(self): - d = wsme.types.ArrayType(str) - self.assertEqual(sphinxext.datatypename(d), 'list(str)') - d = wsme.types.ArrayType(ASampleType) - self.assertEqual(sphinxext.datatypename(d), 'list(ASampleType)') diff --git a/tests/test_tg1.py b/tests/test_tg1.py deleted file mode 100644 index 3a61827..0000000 --- a/tests/test_tg1.py +++ /dev/null @@ -1,196 +0,0 @@ -import wsmeext.tg11 -from wsme import WSRoot -from wsmeext.tg11 import wsexpose, wsvalidate -import wsmeext.tg1 - -from turbogears.controllers import RootController -import cherrypy - -import unittest - -import simplejson - - -from wsmeext.tests import test_soap - - -class WSController(WSRoot): - pass - - -class Subcontroller(object): - @wsexpose(int, int, int) - def add(self, a, b): - return a + b - - -class Root(RootController): - class UselessSubClass: - # This class is here only to make sure wsmeext.tg1.scan_api - # does its job properly - pass - - ws = WSController(webpath='/ws') - ws.addprotocol( - 'soap', - tns=test_soap.tns, - typenamespace=test_soap.typenamespace, - baseURL='/ws/' - ) - ws = wsmeext.tg11.adapt(ws) - - @wsexpose(int) - @wsvalidate(int, int) - def multiply(self, a, b): - return a * b - - @wsexpose(int) - @wsvalidate(int, int) - def divide(self, a, b): - if b == 0: - raise cherrypy.HTTPError(400, 'Cannot divide by zero!') - return a / b - - sub = Subcontroller() - -from turbogears import testutil, config, startup - - -class TestController(unittest.TestCase): - root = Root - - def setUp(self): - "Tests the output of the index method" - self.app = testutil.make_app(self.root) - testutil.start_server() - - def tearDown(self): - # implementation copied from turbogears.testutil.stop_server. - # The only change is that cherrypy.root is set to None - # AFTER stopTurbogears has been called so that wsmeext.tg11 - # can correctly uninstall its filter. - if config.get("cp_started"): - cherrypy.server.stop() - config.update({"cp_started": False}) - - if config.get("server_started"): - startup.stopTurboGears() - config.update({"server_started": False}) - - def test_restcall(self): - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json'} - ) - print response - assert simplejson.loads(response.body) == 50 - - response = self.app.post("/sub/add", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json'} - ) - print response - assert simplejson.loads(response.body) == 15 - - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json', 'Accept': 'application/json'} - ) - print response - assert simplejson.loads(response.body) == 50 - - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json', 'Accept': 'text/javascript'} - ) - print response - assert simplejson.loads(response.body) == 50 - - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json', - 'Accept': 'text/xml'} - ) - print response - assert response.body == "<result>50</result>" - - def test_custom_clientside_error(self): - response = self.app.post( - "/divide", - simplejson.dumps({'a': 5, 'b': 0}), - {'Content-Type': 'application/json', 'Accept': 'application/json'}, - expect_errors=True - ) - assert response.status_int == 400 - assert simplejson.loads(response.body) == { - "debuginfo": None, - "faultcode": "Server", - "faultstring": "(400, 'Cannot divide by zero!')" - } - - response = self.app.post( - "/divide", - simplejson.dumps({'a': 5, 'b': 0}), - {'Content-Type': 'application/json', 'Accept': 'text/xml'}, - expect_errors=True - ) - assert response.status_int == 400 - assert response.body == ("<error><faultcode>Server</faultcode>" - "<faultstring>(400, 'Cannot divide by zero!')" - "</faultstring><debuginfo /></error>") - - def test_soap_wsdl(self): - ts = test_soap.TestSOAP('test_wsdl') - ts.app = self.app - ts.ws_path = '/ws/' - ts.run() - #wsdl = self.app.get('/ws/api.wsdl').body - #print wsdl - #assert 'multiply' in wsdl - - def test_soap_call(self): - ts = test_soap.TestSOAP('test_wsdl') - ts.app = self.app - ts.ws_path = '/ws/' - - print ts.ws_path - assert ts.call('multiply', a=5, b=10, _rt=int) == 50 - - def test_scan_api_loops(self): - class MyRoot(object): - pass - - MyRoot.loop = MyRoot() - - root = MyRoot() - - api = list(wsmeext.tg1._scan_api(root)) - print(api) - - self.assertEqual(len(api), 0) - - def test_scan_api_maxlen(self): - class ARoot(object): - pass - - def make_subcontrollers(n): - c = type('Controller%s' % n, (object,), {}) - return c - - c = ARoot - for n in range(55): - subc = make_subcontrollers(n) - c.sub = subc() - c = subc - root = ARoot() - self.assertRaises(ValueError, list, wsmeext.tg1._scan_api(root)) - - def test_templates_content_type(self): - self.assertEqual( - "application/json", - wsmeext.tg1.AutoJSONTemplate().get_content_type('dummy') - ) - self.assertEqual( - "text/xml", - wsmeext.tg1.AutoXMLTemplate().get_content_type('dummy') - ) diff --git a/tests/test_tg15.py b/tests/test_tg15.py deleted file mode 100644 index 91609d2..0000000 --- a/tests/test_tg15.py +++ /dev/null @@ -1,177 +0,0 @@ -import wsmeext.tg15 -from wsme import WSRoot - -from turbogears.controllers import RootController -import cherrypy - -from wsmeext.tests import test_soap - -import simplejson - - -class Subcontroller(object): - @wsmeext.tg15.wsexpose(int, int, int) - def add(self, a, b): - return a + b - - -class Root(RootController): - class UselessSubClass: - # This class is here only to make sure wsmeext.tg1.scan_api - # does its job properly - pass - - sub = Subcontroller() - - ws = WSRoot(webpath='/ws') - ws.addprotocol('soap', - tns=test_soap.tns, - typenamespace=test_soap.typenamespace, - baseURL='/ws/' - ) - ws = wsmeext.tg15.adapt(ws) - - @wsmeext.tg15.wsexpose(int) - @wsmeext.tg15.wsvalidate(int, int) - def multiply(self, a, b): - return a * b - - @wsmeext.tg15.wsexpose(int) - @wsmeext.tg15.wsvalidate(int, int) - def divide(self, a, b): - if b == 0: - raise cherrypy.HTTPError(400, 'Cannot divide by zero!') - return a / b - - -from turbogears import testutil - - -class TestController(testutil.TGTest): - root = Root - -# def setUp(self): -# "Tests the output of the index method" -# self.app = testutil.make_app(self.root) -# #print cherrypy.root -# testutil.start_server() - -# def tearDown(self): -# # implementation copied from turbogears.testutil.stop_server. -# # The only change is that cherrypy.root is set to None -# # AFTER stopTurbogears has been called so that wsmeext.tg15 -# # can correctly uninstall its filter. -# if config.get("cp_started"): -# cherrypy.server.stop() -# config.update({"cp_started": False}) -# -# if config.get("server_started"): -# startup.stopTurboGears() -# config.update({"server_started": False}) - - def test_restcall(self): - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json'} - ) - print response - assert simplejson.loads(response.body) == 50 - - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json', 'Accept': 'application/json'} - ) - print response - assert simplejson.loads(response.body) == 50 - - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json', 'Accept': 'text/javascript'} - ) - print response - assert simplejson.loads(response.body) == 50 - - response = self.app.post("/multiply", - simplejson.dumps({'a': 5, 'b': 10}), - {'Content-Type': 'application/json', - 'Accept': 'text/xml'} - ) - print response - assert response.body == "<result>50</result>" - - def test_custom_clientside_error(self): - response = self.app.post( - "/divide", - simplejson.dumps({'a': 5, 'b': 0}), - {'Content-Type': 'application/json', 'Accept': 'application/json'}, - expect_errors=True - ) - assert response.status_int == 400 - assert simplejson.loads(response.body) == { - "debuginfo": None, - "faultcode": "Client", - "faultstring": "(400, 'Cannot divide by zero!')" - } - - response = self.app.post( - "/divide", - simplejson.dumps({'a': 5, 'b': 0}), - {'Content-Type': 'application/json', 'Accept': 'text/xml'}, - expect_errors=True - ) - assert response.status_int == 400 - assert response.body == ("<error><faultcode>Client</faultcode>" - "<faultstring>(400, 'Cannot divide by zero!')" - "</faultstring><debuginfo /></error>") - - def test_soap_wsdl(self): - wsdl = self.app.get('/ws/api.wsdl').body - print wsdl - assert 'multiply' in wsdl - - def test_soap_call(self): - ts = test_soap.TestSOAP('test_wsdl') - ts.app = self.app - ts.ws_path = '/ws/' - - print ts.ws_path - assert ts.call('multiply', a=5, b=10, _rt=int) == 50 - - def test_scan_api_loops(self): - class MyRoot(object): - pass - - MyRoot.loop = MyRoot() - - root = MyRoot() - - api = list(wsmeext.tg1._scan_api(root)) - print(api) - - self.assertEqual(len(api), 0) - - def test_scan_api_maxlen(self): - class ARoot(object): - pass - - def make_subcontrollers(n): - c = type('Controller%s' % n, (object,), {}) - return c - - c = ARoot - for n in range(55): - subc = make_subcontrollers(n) - c.sub = subc() - c = subc - root = ARoot() - self.assertRaises(ValueError, list, wsmeext.tg1._scan_api(root)) - - def test_templates_content_type(self): - self.assertEqual( - "application/json", - wsmeext.tg1.AutoJSONTemplate().get_content_type('dummy') - ) - self.assertEqual( - "text/xml", - wsmeext.tg1.AutoXMLTemplate().get_content_type('dummy') - ) |