[z3-checkins] r37214 - in z3/deliverance/DeliveranceVHoster/trunk/tests: . test-static test-static/blah
ianb at codespeak.net
ianb at codespeak.net
Tue Jan 23 17:29:36 CET 2007
Author: ianb
Date: Tue Jan 23 17:29:34 2007
New Revision: 37214
Added:
z3/deliverance/DeliveranceVHoster/trunk/tests/
z3/deliverance/DeliveranceVHoster/trunk/tests/conftest.py
z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/
z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/blah/
z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/blah/foo.html
z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/index.html
z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/theme.html
z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py
Log:
Added functional test
Added: z3/deliverance/DeliveranceVHoster/trunk/tests/conftest.py
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/conftest.py Tue Jan 23 17:29:34 2007
@@ -0,0 +1,4 @@
+import os, sys
+sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
+import pkg_resources
+pkg_resources.require('DeliveranceVHoster')
Added: z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/blah/foo.html
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/blah/foo.html Tue Jan 23 17:29:34 2007
@@ -0,0 +1,9 @@
+<html>
+<head>
+<title>foo</title>
+</head>
+
+<body>
+<h1>foo</h1>
+
+</body> </html>
Added: z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/index.html
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/index.html Tue Jan 23 17:29:34 2007
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
+<title>Test Content</title>
+</head>
+
+<body>
+
+Unthemed stuff
+
+<div id="portal-content">
+This is some content
+ </div>
+</body> </html>
Added: z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/theme.html
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/test-static/theme.html Tue Jan 23 17:29:34 2007
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>Test Theme</title>
+</head>
+
+<body>
+<h1>Test Theme</h1>
+
+<div id="content">replace me</div>
+
+<div>This is a theme</div>
+
+</body> </html>
Added: z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py
==============================================================================
--- (empty file)
+++ z3/deliverance/DeliveranceVHoster/trunk/tests/test_functional_api.py Tue Jan 23 17:29:34 2007
@@ -0,0 +1,120 @@
+from paste.fixture import TestApp
+from paste.urlparser import StaticURLParser
+from dvhoster.wsgiapp import make_app
+import wsgi_intercept
+
+wsgi_app = make_app(
+ {},
+ data_dir=os.path.join(os.path.dirname(__file__), 'test-data'))
+app = TestApp(wsgi_app)
+
+def put(uri, data):
+ app.post(uri, data, extra_environ={'REQUEST_METHOD': 'PUT'})
+
+rule_data = '''
+<?xml version="1.0" encoding="UTF-8"?>
+ <rules xmlns="http://www.plone.org/deliverance">
+ <append-or-replace theme="//head" content="//head/title" />
+ <append theme="//head" content="//head/link" />
+ <append theme="//head" content="//head/script" onerror="ignore"/>
+ <append theme="//head" content="//head/style" onerror="ignore"/>
+ <append theme="//head" content="//head/meta" onerror="ignore"/>
+ <copy theme="//div[@id='content']" content="//div[@id='portal-content']" />
+ </rules>
+'''
+
+static_app = StaticURLParser(os.path.join(os.path.dirname(__file__),
+ 'test-static'))
+def make_static_app():
+ return static_app
+
+wsgi_intercept.add_wsgi_intercept('wsgify.org', 80, make_static_app)
+
+
+def test_everything():
+ yield (create_api,)
+ yield (use_api, 'localhost')
+ yield (rename_site,)
+ yield (use_api, 'localhost2')
+
+def create_api():
+ app = make_test_app()
+
+ # Theme:
+ uri = 'http://wsgify.org/theme.html'
+ put('/.deliverance/theme_uri', uri)
+ res = app.get('/.deliverance/theme_uri')
+ assert res.body == uri
+
+ # Rules:
+ put('/.deliverance/rules/rules.xml', rule_data)
+
+ # Domain (no rename test):
+ res = app.get('/.deliverance/domain')
+ assert res.body == 'localhost'
+
+ # Aliases:
+ data = "localhost.localhost\nexample.com"
+ put('/.deliverance/aliases', data)
+ assert app.get('/.deliverance/aliases').body == data
+
+ data = '''
+ [{"path": "/", "remote_uri": "http://wsgify.org/"},
+ {"path": "/bar", "remote_uri": "http://wsgify.org/blah", comment="x"}]
+ '''
+
+ put('/.deliverance/remote_uris', data)
+ #assert app.get('/.deliverance/remote_uris').body == data
+
+ data = '''
+ [{"path": "/test1.html", "rewrite": "/test1"},
+ {"prefix": "/test2", "rewrite": "/test3", "comment": "rename"},
+ {"path": "/other.html", "rewrite": "http://otherexample.com/other.html"}]
+ '''
+ put('/.deliverance/redirects', data)
+
+ data = '<html>some data!</html>'
+ put('/.deliverance/static/data.html', data)
+ res = app.get('/.deliverance/static/data.html')
+ assert res.data == data
+ app.get('/.deliverance/static/subdir',
+ extra_environ={'REQUEST_METHOD', 'MKCOL'})
+ put('/.deliverance/static/subdir/foo.html', 'blah')
+ res = app.get('/.deliverance/static/subdir/foo.html')
+ assert res.body == 'blah'
+ res = app.get('/subdir/foo.html')
+ assert res.body == 'blah'
+ # Directories don't shadow like files:
+ res = app.get('/subdir/', status=404)
+
+def use_api(hostname):
+ app.extra_environ['HTTP_HOST'] = hostname
+ res = app.get('/index.html')
+ res.mustcontain(
+ # From the theme:
+ 'This is a theme',
+ # From the content:
+ 'This is some content')
+ # Should be dropped from theme:
+ assert 'replace' not in res
+ # Should be lost from content:
+ assert 'unthemed' not in res
+ # Redirect non-canonical domains:
+ res = app.get('/index.html', extra_environ=dict(HTTP_HOST='example.com'),
+ status=303)
+ assert res.header('location') == 'http://%s/index.html' % hostname
+ # Test the path backend redirect:
+ res = app.get('/bar/foo.html')
+ res.mustcontain('foo')
+ res = app.get('/test1.html', status=303)
+ assert res.header('location') == 'http://%s/test1' % hostname
+ res = app.get('/test2/other/stuff.html', status=303)
+ assert res.header('location') == 'http://%s/test3/other/stuff.html' % hostname
+ res = app.get('/test1.html/foo/bar', status=404)
+ res = app.get('/data.html')
+ res.mustcontain('some data!')
+ assert 'Test Theme' not in res
+ res = app.get('/subdir/foo.html')
+ assert res.body == 'blah'
+
+
More information about the z3-checkins
mailing list