diff options
| author | Chris McDonough <chrism@agendaless.com> | 2008-08-24 01:58:26 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2008-08-24 01:58:26 +0000 |
| commit | 2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7 (patch) | |
| tree | ee9557256044c720a71bb67341df5413dc0c21a6 /docs/narr/MyProject/myproject | |
| parent | 980db5f3a1b2e7c8f46136f42ea521ee6987da7c (diff) | |
| download | pyramid-2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7.tar.gz pyramid-2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7.tar.bz2 pyramid-2c647036d9ed5e5a27cb6b2a5700a8f0d3a7d2a7.zip | |
Second checkin using StudlyCaps version of MyProject.
Diffstat (limited to 'docs/narr/MyProject/myproject')
| -rw-r--r-- | docs/narr/MyProject/myproject/__init__.py | 2 | ||||
| -rw-r--r-- | docs/narr/MyProject/myproject/configure.zcml | 13 | ||||
| -rw-r--r-- | docs/narr/MyProject/myproject/models.py | 14 | ||||
| -rw-r--r-- | docs/narr/MyProject/myproject/run.py | 13 | ||||
| -rw-r--r-- | docs/narr/MyProject/myproject/templates/mytemplate.pt | 7 | ||||
| -rw-r--r-- | docs/narr/MyProject/myproject/tests.py | 45 | ||||
| -rw-r--r-- | docs/narr/MyProject/myproject/views.py | 5 |
7 files changed, 99 insertions, 0 deletions
diff --git a/docs/narr/MyProject/myproject/__init__.py b/docs/narr/MyProject/myproject/__init__.py new file mode 100644 index 000000000..cbdfd3ac6 --- /dev/null +++ b/docs/narr/MyProject/myproject/__init__.py @@ -0,0 +1,2 @@ +# A package + diff --git a/docs/narr/MyProject/myproject/configure.zcml b/docs/narr/MyProject/myproject/configure.zcml new file mode 100644 index 000000000..174b27354 --- /dev/null +++ b/docs/narr/MyProject/myproject/configure.zcml @@ -0,0 +1,13 @@ +<configure xmlns="http://namespaces.zope.org/zope" + xmlns:bfg="http://namespaces.repoze.org/bfg" + i18n_domain="repoze.bfg"> + + <!-- this must be included for the view declarations to work --> + <include package="repoze.bfg" /> + + <bfg:view + for=".models.IMyModel" + view=".views.my_view" + /> + +</configure> diff --git a/docs/narr/MyProject/myproject/models.py b/docs/narr/MyProject/myproject/models.py new file mode 100644 index 000000000..42efd9e0b --- /dev/null +++ b/docs/narr/MyProject/myproject/models.py @@ -0,0 +1,14 @@ +from zope.interface import Interface +from zope.interface import implements + +class IMyModel(Interface): + pass + +class MyModel(object): + implements(IMyModel) + pass + +root = MyModel() + +def get_root(environ): + return root diff --git a/docs/narr/MyProject/myproject/run.py b/docs/narr/MyProject/myproject/run.py new file mode 100644 index 000000000..eab4883f7 --- /dev/null +++ b/docs/narr/MyProject/myproject/run.py @@ -0,0 +1,13 @@ +from repoze.bfg import make_app +from repoze.bfg import get_options + +def app(global_config, **kw): + # paster app config callback + from myproject.models import get_root + import myproject + return make_app(get_root, myproject, options=get_options(kw)) + +if __name__ == '__main__': + from paste import httpserver + httpserver.serve(app(None), host='0.0.0.0', port='6543') + diff --git a/docs/narr/MyProject/myproject/templates/mytemplate.pt b/docs/narr/MyProject/myproject/templates/mytemplate.pt new file mode 100644 index 000000000..a7affedf9 --- /dev/null +++ b/docs/narr/MyProject/myproject/templates/mytemplate.pt @@ -0,0 +1,7 @@ +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:tal="http://xml.zope.org/namespaces/tal"> +<head></head> +<body> + <h1>Welcome to ${project}</h1> +</body> +</html> diff --git a/docs/narr/MyProject/myproject/tests.py b/docs/narr/MyProject/myproject/tests.py new file mode 100644 index 000000000..d3d4628ff --- /dev/null +++ b/docs/narr/MyProject/myproject/tests.py @@ -0,0 +1,45 @@ +import unittest + +class ViewTests(unittest.TestCase): + def setUp(self): + # This sets up the application registry with the registrations + # your application declares in its configure.zcml (including + # dependent registrations for repoze.bfg itself). This is a + # heavy-hammer way of making sure that your tests have enough + # context to run properly. But tests will run faster if you + # use only the registrations you need programmatically, so you + # should explore ways to do that rather than rely on ZCML (see + # the repoze.bfg tests for inspiration). + self._cleanup() + import myproject + import zope.configuration.xmlconfig + zope.configuration.xmlconfig.file('configure.zcml', + package=myproject) + + def tearDown(self): + self._cleanup() + + def _cleanup(self): + # this clears the application registry + from zope.testing.cleanup import cleanUp + cleanUp() + + def test_my_view(self): + from myproject.views import my_view + context = DummyContext() + request = DummyRequest() + result = my_view(context, request) + self.assertEqual(result.status, '200 OK') + body = result.app_iter[0] + self.failUnless('Welcome to myproject' in body) + self.assertEqual(len(result.headerlist), 2) + self.assertEqual(result.headerlist[0], + ('content-type', 'text/html; charset=UTF-8')) + self.assertEqual(result.headerlist[1], ('Content-Length', + str(len(body)))) + +class DummyContext: + pass + +class DummyRequest: + pass diff --git a/docs/narr/MyProject/myproject/views.py b/docs/narr/MyProject/myproject/views.py new file mode 100644 index 000000000..6e1be6190 --- /dev/null +++ b/docs/narr/MyProject/myproject/views.py @@ -0,0 +1,5 @@ +from repoze.bfg.template import render_template_to_response + +def my_view(context, request): + return render_template_to_response('templates/mytemplate.pt', + project = 'myproject') |
