class TestPUT(TestCase):

    layer = BrowserLayer(zope.app.file)

    def test_put(self):
        # PUT something for the first time
        response = http(r"""PUT /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw
Content-Length: 20
Content-Type: text/plain

This is just a test.""")

        self.assertEquals(response.getStatus(), 201)
        self.assertEquals(response.getHeader("Location"),
                          "http://localhost/testfile.txt")

        response = http(r"""GET /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw""")
        self.assertEquals(response.getBody(), "This is just a test.")

        # now modify it
        response = http(r"""PUT /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw
Content-Length: 23
Content-Type: text/plain

And now it is modified.""")
        self.assertEquals(response.getStatus(), 200)
        self.assertEquals(response.getBody(), "")

        response = http(r"""GET /testfile.txt HTTP/1.1
Authorization: Basic globalmgr:globalmgrpw""")
        self.assertEquals(response.getBody(), "And now it is modified.")
示例#2
0
import re
import unittest, doctest
import grok

from pkg_resources import resource_listdir
from zope.testing import renormalizing
from zope.app.wsgi.testlayer import BrowserLayer, http

FunctionalLayer = BrowserLayer(grok)

checker = renormalizing.RENormalizing([
    # Accommodate to exception wrapping in newer versions of mechanize
    (re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
    ])

def http_call(method, path, data=None, **kw):
    """Function to help make RESTful calls.

    method - HTTP method to use
    path - testbrowser style path
    data - (body) data to submit
    kw - any request parameters
    """

    if path.startswith('http://localhost'):
        path = path[len('http://localhost'):]
    request_string = '%s %s HTTP/1.1\n' % (method, path)
    for key, value in kw.items():
        request_string += '%s: %s\n' % (key, value)
    if data is not None:
        request_string += '\r\n'
示例#3
0
##############################################################################
#
# Copyright (c) 2007 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""zope.app.file common test related classes/functions/objects.

"""

__docformat__ = "reStructuredText"

from zope.app.wsgi.testlayer import BrowserLayer

import zope.app.file

AppFileLayer = BrowserLayer(zope.app.file, allowTearDown=True)
示例#4
0
def setUp(test):
    root = zope.site.testing.siteSetUp(True)
    zope.traversing.testing.setUp()
    test.globs['root'] = root
    provideAdapter(UnconsumedURL, (Interface, IHTTPRequest),
                   Interface,
                   name='unconsumed_url')


def tearDown(test):
    zope.site.testing.siteTearDown()


browser_layer = BrowserLayer(z3c.traverser.stackinfo,
                             'ftesting.zcml',
                             allowTearDown=True)


def setUpBrowser(test):
    test.globs['wsgi_app'] = browser_layer.make_wsgi_app()


def test_suite():
    flags = doctest.NORMALIZE_WHITESPACE|\
            doctest.ELLIPSIS|\
            doctest.IGNORE_EXCEPTION_DETAIL
    suite = unittest.TestSuite((doctest.DocFileSuite('README.rst',
                                                     setUp=setUp,
                                                     tearDown=tearDown,
                                                     optionflags=flags,
示例#5
0
    root = zope.site.testing.siteSetUp(True)
    zope.traversing.testing.setUp()
    test.globs['root'] = root

    browserView(None, 'absolute_url', AbsoluteURL)
    browserView(IContainmentRoot, 'absolute_url', SiteAbsoluteURL)
    browserView(None, '', AbsoluteURL, providing=IAbsoluteURL)
    browserView(IContainmentRoot, '', SiteAbsoluteURL, providing=IAbsoluteURL)


def tearDown(test):
    zope.site.testing.siteTearDown()


browser_layer = BrowserLayer(z3c.traverser.viewlet,
                             'ftesting.zcml',
                             allowTearDown=True)


def setUpBrowser(test):
    test.globs['wsgi_app'] = browser_layer.make_wsgi_app()


def test_suite():
    flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
    suite = unittest.TestSuite((doctest.DocFileSuite('README.rst',
                                                     setUp=setUp,
                                                     tearDown=tearDown,
                                                     optionflags=flags), ))
    browser_suite = doctest.DocFileSuite('BROWSER.rst',
                                         setUp=setUpBrowser,
示例#6
0
import re
import unittest
import doctest
import uvc.layout
from pkg_resources import resource_listdir
from zope.testing import cleanup, renormalizing
import zope.component.eventtesting

from zope.app.wsgi.testlayer import BrowserLayer

FunctionalLayer = BrowserLayer(uvc.layout)


def setUpZope(test):
    zope.component.eventtesting.setUp(test)

def cleanUpZope(test):
    cleanup.cleanUp()


def suiteFromPackage(name):
    files = resource_listdir(__name__, name)
    suite = unittest.TestSuite()
    for filename in files:
        if not filename.endswith('.py'):
            continue
        if filename.endswith('_fixture.py'):
            continue
        if filename == '__init__.py':
            continue
示例#7
0
文件: tests.py 项目: gyst/groktoolkit
import os.path
import z3c.testsetup
from zope.app.wsgi.testlayer import BrowserLayer

import sample

browser_layer = BrowserLayer(sample)

test_suite = z3c.testsetup.register_all_tests(
    'sample', globs={'getRootFolder': browser_layer.getRootFolder})
示例#8
0
import re
import doctest
import unittest
import grokcore.security

from pkg_resources import resource_listdir
from zope.testing import renormalizing
from zope.app.wsgi.testlayer import BrowserLayer, http

FunctionalLayer = BrowserLayer(grokcore.security)

checker = renormalizing.RENormalizing([
    # Accommodate to exception wrapping in newer versions of mechanize
    (re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
    ])

def suiteFromPackage(name):
    files = resource_listdir(__name__, name)
    suite = unittest.TestSuite()
    for filename in files:
        if not filename.endswith('.py'):
            continue
        if filename == '__init__.py':
            continue
        dottedname = 'grokcore.security.ftests.%s.%s' % (name, filename[:-3])
        test = doctest.DocTestSuite(
            dottedname,
            checker=checker,
            extraglobs=dict(
                http=http,
                getRootFolder=FunctionalLayer.getRootFolder),
示例#9
0
from zope.app.wsgi.testlayer import BrowserLayer
import gocept.patch_keyreferences

PatchedAppCatalogLayer = BrowserLayer(gocept.patch_keyreferences,
                                      allowTearDown=True)
示例#10
0
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""zope.app.publication common test related classes/functions/objects.

$Id: testing.py 110812 2010-04-13 16:30:31Z thefunny42 $
"""

__docformat__ = "reStructuredText"

from zope.app.wsgi.testlayer import BrowserLayer
from zope.publisher.browser import BrowserPage
import zope.app.publication


class DefaultTestView(BrowserPage):
    def __call__(self):
        self.request.response.setHeader('Content-Type',
                                        'text/html;charset=utf-8')
        return "<html><body>Test</body></html>"


PublicationLayer = BrowserLayer(zope.app.publication, name='PublicationLayer')
示例#11
0
import re
import unittest
import os.path
import grokcore.view

from pkg_resources import resource_listdir

from zope.app.wsgi.testlayer import BrowserLayer, http
from zope.testing import doctest, renormalizing

FunctionalLayer = BrowserLayer(grokcore.view)

checker = renormalizing.RENormalizing([
    # Accommodate to exception wrapping in newer versions of mechanize
    (re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
])


def suiteFromPackage(name):
    files = resource_listdir(__name__, name)
    suite = unittest.TestSuite()
    getRootFolder = FunctionalLayer.getRootFolder
    globs = dict(http=http, getRootFolder=getRootFolder)
    optionflags = (doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE +
                   doctest.REPORT_NDIFF)

    for filename in files:
        if filename == '__init__.py':
            continue

        test = None
##############################################################################
#
# Copyright (c) 2007 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""zope.app.onlinehelp common test related classes/functions/objects.

"""

__docformat__ = "reStructuredText"

from zope.app.wsgi.testlayer import BrowserLayer
import zope.app.onlinehelp

OnlineHelpLayer = BrowserLayer(zope.app.onlinehelp, allowTearDown=True)
import doctest
import re
import unittest
import grokcore.traverser

from pkg_resources import resource_listdir
from zope.testing import renormalizing
from zope.app.wsgi.testlayer import BrowserLayer, http

FunctionalLayer = BrowserLayer(grokcore.traverser)

checker = renormalizing.RENormalizing([
    # Accommodate to exception wrapping in newer versions of mechanize
    (re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
])


def http_call(method, path, data=None, **kw):
    """Function to help make RESTful calls.

    method - HTTP method to use
    path - testbrowser style path
    data - (body) data to submit
    kw - any request parameters
    """

    if path.startswith('http://localhost'):
        path = path[len('http://localhost'):]
    request_string = '%s %s HTTP/1.1\n' % (method, path)
    for key, value in kw.items():
        request_string += '%s: %s\n' % (key, value)