allura
修訂 | 047b5d1abd2d9d561085d9d4d14952978115561b (tree) |
---|---|
時間 | 2011-04-30 02:08:35 |
作者 | Rick Copeland <rcopeland@geek...> |
Commiter | Rick Copeland |
[#1831] Still fixing tests
Signed-off-by: Rick Copeland <rcopeland@geek.net>
@@ -1,40 +0,0 @@ | ||
1 | -import webob | |
2 | -import tg.decorators | |
3 | -from pylons import request | |
4 | - | |
5 | -from allura.lib import helpers as h | |
6 | - | |
7 | -def apply(): | |
8 | - old_lookup_template_engine = tg.decorators.Decoration.lookup_template_engine | |
9 | - | |
10 | - @h.monkeypatch(tg.decorators.Decoration) | |
11 | - def lookup_template_engine(self, request): | |
12 | - '''Wrapper to handle totally borked-up HTTP-ACCEPT headers''' | |
13 | - try: | |
14 | - return old_lookup_template_engine(self, request) | |
15 | - except: | |
16 | - pass | |
17 | - environ = dict(request.environ, HTTP_ACCEPT='*/*') | |
18 | - request = webob.Request(environ) | |
19 | - return old_lookup_template_engine(self, request) | |
20 | - | |
21 | - @h.monkeypatch(tg, tg.decorators) | |
22 | - def override_template(controller, template): | |
23 | - '''Copy-pasted patch to allow multiple colons in a template spec''' | |
24 | - if hasattr(controller, 'decoration'): | |
25 | - decoration = controller.decoration | |
26 | - else: | |
27 | - return | |
28 | - if hasattr(decoration, 'engines'): | |
29 | - engines = decoration.engines | |
30 | - else: | |
31 | - return | |
32 | - | |
33 | - for content_type, content_engine in engines.iteritems(): | |
34 | - template = template.split(':', 1) | |
35 | - template.extend(content_engine[2:]) | |
36 | - try: | |
37 | - override_mapping = request._override_mapping | |
38 | - except AttributeError: | |
39 | - override_mapping = request._override_mapping = {} | |
40 | - override_mapping[controller.im_func] = {content_type: template} |
@@ -1,3 +1,3 @@ | ||
1 | -from shim import * | |
2 | -from tg_globals import c, g, response, request, config, session, environ | |
3 | -from decorators import expose, validate | |
1 | +from .tg_globals import c, g, response, request, config, session, environ | |
2 | +from .shim import redirect, url | |
3 | +from .decorators import expose, validate |
@@ -6,12 +6,13 @@ import urllib | ||
6 | 6 | import tg |
7 | 7 | import pkg_resources |
8 | 8 | import pyramid.response |
9 | -from webob import exc | |
10 | 9 | from formencode import Invalid |
10 | +from webob import exc | |
11 | 11 | |
12 | 12 | from decorators import Decoration |
13 | 13 | |
14 | 14 | from . import tg_globals |
15 | +from .traversal import Resource | |
15 | 16 | |
16 | 17 | __all__ = [ 'redirect', 'url' ] |
17 | 18 |
@@ -42,33 +43,6 @@ class RootFactory(object): | ||
42 | 43 | if hasattr(root_obj, '_cleanup_request'): |
43 | 44 | root_obj._cleanup_request() |
44 | 45 | |
45 | -class Resource(object): | |
46 | - | |
47 | - def __init__(self, controller): | |
48 | - self._controller = controller | |
49 | - sec = getattr(controller, '_check_security', lambda:None) | |
50 | - sec() | |
51 | - | |
52 | - def __getitem__(self, name): | |
53 | - name = name.encode('utf-8') | |
54 | - try: | |
55 | - remainder = [] | |
56 | - next = getattr(self._controller, name, None) | |
57 | - if next is None: | |
58 | - next, remainder = self._controller._lookup(name) | |
59 | - assert not remainder, 'Weird _lookup not supported' | |
60 | - return Resource(next) | |
61 | - except exc.HTTPNotFound: | |
62 | - return None | |
63 | - | |
64 | - def get_deco(self): | |
65 | - func = self._controller | |
66 | - deco = Decoration.get(func, False) | |
67 | - if deco is None: | |
68 | - func = getattr(func, 'index', None) | |
69 | - deco = Decoration.get(func, False) | |
70 | - return deco, func | |
71 | - | |
72 | 46 | def tg_view(context, request): |
73 | 47 | deco, func = context.get_deco() |
74 | 48 | try: |
@@ -0,0 +1,46 @@ | ||
1 | +'''Code to support pylons-style traversal on top of TG-style _lookup''' | |
2 | +from decorators import Decoration | |
3 | + | |
4 | +class Resource(object): | |
5 | + | |
6 | + def __init__(self, controller): | |
7 | + self._controller = controller | |
8 | + sec = getattr(controller, '_check_security', lambda:None) | |
9 | + sec() | |
10 | + | |
11 | + def __getitem__(self, name): | |
12 | + name = name.encode('utf-8') | |
13 | + remainder = [] | |
14 | + next = getattr(self._controller, name, None) | |
15 | + if next is None: | |
16 | + try: | |
17 | + next, remainder = self._controller._lookup(name) | |
18 | + except TypeError, te: | |
19 | + if 'takes at least' not in te.args[0]: raise | |
20 | + return CurriedResource(self._controller, [name]) | |
21 | + assert not remainder, 'Weird _lookup not supported' | |
22 | + return Resource(next) | |
23 | + | |
24 | + def get_deco(self): | |
25 | + func = self._controller | |
26 | + deco = Decoration.get(func, False) | |
27 | + if deco is None: | |
28 | + func = getattr(func, 'index', None) | |
29 | + deco = Decoration.get(func, False) | |
30 | + return deco, func | |
31 | + | |
32 | +class CurriedResource(object): | |
33 | + | |
34 | + def __init__(self, controller, path): | |
35 | + self._controller = controller | |
36 | + self._path = path | |
37 | + | |
38 | + def __getitem__(self, name): | |
39 | + new_path = self._path + [name] | |
40 | + try: | |
41 | + next, remainder = self._controller._lookup(*new_path) | |
42 | + assert not remainder, 'Weird _lookup not supported' | |
43 | + return Resource(next) | |
44 | + except TypeError, te: | |
45 | + if 'takes at least' not in te.args[0]: raise | |
46 | + return CurriedResource(self._controller, new_path) |
@@ -50,6 +50,8 @@ def test_pyflakes(): | ||
50 | 50 | |
51 | 51 | if error: |
52 | 52 | raise Exception('pyflakes failure, see stdout') |
53 | + if run(find_py + " | grep -v '/migrations/' | xargs pyflakes | grep -v '" + "' | grep -v '".join(skips) + "'") != 1: | |
54 | + raise Exception('pyflakes failure') | |
53 | 55 | |
54 | 56 | def test_no_now(): |
55 | 57 | if run(find_py + " | xargs grep '\.now(' ") not in [1,123]: |
@@ -56,8 +56,8 @@ class TestRootController(TestController): | ||
56 | 56 | # two revisions are shown |
57 | 57 | assert '2 by Test Admin' in response |
58 | 58 | assert '1 by Test Admin' in response |
59 | - self.app.get('/blog/2010/08/my-post?version=1') | |
60 | - self.app.get('/blog/2010/08/my-post?version=foo', status=404) | |
59 | + self.app.get('/blog/2010/08/my-post/?version=1') | |
60 | + self.app.get('/blog/2010/08/my-post/?version=foo', status=404) | |
61 | 61 | |
62 | 62 | def test_post_diff(self): |
63 | 63 | self._post() |
@@ -1,4 +1,4 @@ | ||
1 | -from pylons import c, g | |
1 | +from tg import c, g | |
2 | 2 | |
3 | 3 | from alluratest.controller import setup_basic_test, setup_global_objects |
4 | 4 | from allura import model as M |
@@ -6,7 +6,7 @@ from email.mime.image import MIMEImage | ||
6 | 6 | from email.mime.multipart import MIMEMultipart |
7 | 7 | |
8 | 8 | import pkg_resources |
9 | -from pylons import g, c | |
9 | +from tg import c | |
10 | 10 | from nose.tools import assert_equal |
11 | 11 | |
12 | 12 | from allura import model as M |
@@ -1,4 +1,4 @@ | ||
1 | -from pylons import c, g | |
1 | +from tg import c, g | |
2 | 2 | |
3 | 3 | from alluratest.controller import setup_basic_test, setup_global_objects |
4 | 4 | from allura import model as M |
@@ -1,6 +1,6 @@ | ||
1 | 1 | import tg |
2 | 2 | import pkg_resources |
3 | -from pylons import c | |
3 | +from tg import c | |
4 | 4 | from ming.orm import ThreadLocalORMSession |
5 | 5 | |
6 | 6 | from allura import model as M |
@@ -1,7 +1,7 @@ | ||
1 | 1 | import unittest |
2 | 2 | from nose.tools import assert_equals |
3 | 3 | |
4 | -from pylons import c, g | |
4 | +from tg import c | |
5 | 5 | from ming.orm import ThreadLocalORMSession |
6 | 6 | |
7 | 7 | from alluratest.controller import setup_basic_test, setup_global_objects |
@@ -1,7 +1,5 @@ | ||
1 | -import os | |
2 | - | |
3 | 1 | import pkg_resources |
4 | -from pylons import c | |
2 | +from tg import c | |
5 | 3 | from ming.orm import ThreadLocalORMSession |
6 | 4 | |
7 | 5 | from allura.lib import helpers as h |
@@ -1,7 +1,7 @@ | ||
1 | 1 | import unittest |
2 | 2 | from nose.tools import assert_equals |
3 | 3 | |
4 | -from pylons import c | |
4 | +from tg import c | |
5 | 5 | from ming.orm import ThreadLocalORMSession |
6 | 6 | |
7 | 7 | from alluratest.controller import setup_basic_test, setup_global_objects |
@@ -1,7 +1,5 @@ | ||
1 | 1 | import unittest |
2 | 2 | |
3 | -from pylons import c, g | |
4 | - | |
5 | 3 | from ming.orm import ThreadLocalORMSession |
6 | 4 | |
7 | 5 | from alluratest.controller import setup_basic_test, setup_global_objects |
@@ -2,7 +2,8 @@ | ||
2 | 2 | import logging |
3 | 3 | |
4 | 4 | # Non-stdlib imports |
5 | -from tg import c, session, expose, redirect | |
5 | +from tg import expose, redirect | |
6 | +from tg import c, session | |
6 | 7 | |
7 | 8 | # Pyforge-specific imports |
8 | 9 | from allura.app import Application, ConfigOption, SitemapEntry, DefaultAdminController |
@@ -1,7 +1,5 @@ | ||
1 | -import os | |
2 | - | |
3 | 1 | import pkg_resources |
4 | -from pylons import c | |
2 | +from tg import c | |
5 | 3 | from ming.orm import ThreadLocalORMSession |
6 | 4 | |
7 | 5 | from allura.lib import helpers as h |
@@ -3,8 +3,6 @@ import shutil | ||
3 | 3 | import unittest |
4 | 4 | import pkg_resources |
5 | 5 | |
6 | -from pylons import c | |
7 | - | |
8 | 6 | from ming.orm import ThreadLocalORMSession |
9 | 7 | |
10 | 8 | from alluratest.controller import setup_basic_test, setup_global_objects |
@@ -1,15 +1,11 @@ | ||
1 | -import os | |
2 | -import shutil | |
3 | 1 | import unittest |
4 | -import pkg_resources | |
5 | 2 | from nose.tools import assert_equals |
6 | 3 | |
7 | -from pylons import c, g | |
4 | +from tg import c | |
8 | 5 | from ming.orm import ThreadLocalORMSession |
9 | 6 | |
10 | 7 | from alluratest.controller import setup_basic_test, setup_global_objects |
11 | 8 | from allura.lib import helpers as h |
12 | -from forgesvn import model as SM | |
13 | 9 | |
14 | 10 | |
15 | 11 | class TestSVNApp(unittest.TestCase): |
@@ -1,11 +1,7 @@ | ||
1 | -from pylons import c | |
2 | -from ming.orm import session | |
1 | +from tg import c | |
3 | 2 | |
4 | -from allura import model as M | |
5 | 3 | from allura.lib import helpers as h |
6 | -from alluratest.controller import TestController, TestRestApiBase | |
7 | -from forgetracker import model as TM | |
8 | - | |
4 | +from alluratest.controller import TestRestApiBase | |
9 | 5 | |
10 | 6 | class TestTrackerApiBase(TestRestApiBase): |
11 | 7 |
@@ -1,4 +1,4 @@ | ||
1 | -from pylons import c, g | |
1 | +from tg import c, g | |
2 | 2 | |
3 | 3 | from alluratest.controller import setup_basic_test, setup_global_objects |
4 | 4 | from allura import model as M |
@@ -1,4 +1,4 @@ | ||
1 | -from pylons import c | |
1 | +from tg import c | |
2 | 2 | from ming.orm.ormsession import ThreadLocalORMSession |
3 | 3 | |
4 | 4 | from allura.websetup import bootstrap |
@@ -1,6 +1,6 @@ | ||
1 | 1 | from forgetracker.model import Globals |
2 | 2 | from forgetracker.tests.unit import TrackerTestWithModel |
3 | -from pylons import c | |
3 | +from tg import c | |
4 | 4 | from allura.lib import helpers as h |
5 | 5 | |
6 | 6 | from ming.orm.ormsession import ThreadLocalORMSession |
@@ -3,7 +3,7 @@ from ming.orm.ormsession import session | ||
3 | 3 | |
4 | 4 | from allura.lib import helpers as h |
5 | 5 | from allura.model import User |
6 | -from pylons import c | |
6 | +from tg import c | |
7 | 7 | from forgetracker.tests.unit import TrackerTestWithModel |
8 | 8 | from forgetracker.model import Ticket, Globals |
9 | 9 | from forgetracker import tracker_main |
@@ -1,7 +1,7 @@ | ||
1 | 1 | from ming.orm.ormsession import ThreadLocalORMSession |
2 | 2 | from ming.base import Object |
3 | 3 | |
4 | -from pylons import c | |
4 | +from tg import c | |
5 | 5 | |
6 | 6 | from forgetracker.tests.unit import TrackerTestWithModel |
7 | 7 | from forgetracker.widgets import ticket_form |
@@ -1,7 +1,7 @@ | ||
1 | 1 | from mock import patch |
2 | 2 | from ming.orm.ormsession import ThreadLocalORMSession |
3 | 3 | |
4 | -from pylons import c | |
4 | +from tg import c | |
5 | 5 | |
6 | 6 | from forgetracker.tests.unit import TrackerTestWithModel |
7 | 7 | from forgetracker.widgets import ticket_form |