Пример #1
0
    def setUp(self):
        import tw2.core.command
        o = StdOut(sys.stdout)
        e = StdOut(sys.stderr)
        self._stdout = sys.stdout
        self._stderr = sys.stderr
        sys.stdout = o
        sys.stderr = e
        d = distutils.dist.Distribution()
        self.c = tw2.core.command.archive_tw2_resources(d)

        try:
            shutil.rmtree(OUT_DIR)
        except Exception as e:
            pass

        self.c.initialize_options()
        self.c.finalize_options()
        self.c.output = OUT_DIR
        self.c.force = True
        self.c.distributions = ['tw2.forms']
        os.mkdir(OUT_DIR)

        # Set up fake middleware with which widgets can register their resources
        core.request_local = tw2.core.command.request_local_fake
        core.request_local()['middleware'] = middleware.make_middleware()
        try:
            core.request_local()['resources'] = []
        except Exception as e:
            pass
Пример #2
0
class TestArchive(TestCase):
    def setUp(self):
        import tw2.core.command
        o = StdOut(sys.stdout)
        e = StdOut(sys.stderr)
        self._stdout = sys.stdout
        self._stderr = sys.stderr
        sys.stdout = o
        sys.stderr = e
        d = distutils.dist.Distribution()
        self.c = tw2.core.command.archive_tw2_resources(d)

        try:
            shutil.rmtree(OUT_DIR)
        except Exception, e:
            pass

        self.c.initialize_options()
        self.c.finalize_options()
        self.c.output = OUT_DIR
        self.c.force = True
        self.c.distributions = ['tw2.forms']
        os.mkdir(OUT_DIR)

        # Set up fake middleware with which widgets can register their resources
        core.request_local = tw2.core.command.request_local_fake
        core.request_local()['middleware'] = middleware.make_middleware()
        try:
            core.request_local()['resources'] = []
        except Exception, e:
            pass
Пример #3
0
 def _check_rendering_vs_expected(self, engine, attrs, params, expected):
     _request_id = None
     template.reset_engine_name_cache()
     mw = tmw.make_middleware(None, preferred_rendering_engines=[engine])
     self.request(1, mw)
     r = self.widget(_no_autoid=True, **attrs).display(**params)
     # reset the cache as not to affect other tests
     assert_eq_xml(r, expected, self.wrap)
Пример #4
0
 def setup(self):
     global _request_id, _request_local
     _request_local = {}
     _request_id = None
     if hasattr(super(ValidatorTest, self), 'setup'):
         super(ValidatorTest, self).setup()
     self.mw = tmw.make_middleware(None)
     return self.request(1)
Пример #5
0
 def setup(self):
     global _request_id, _request_local
     _request_local = {}
     _request_id = None
     if hasattr(super(WidgetTest, self), 'setup'):
         super(WidgetTest, self).setup()
     self.mw = tmw.make_middleware(None, default_engine=self.template_engine)
     if self.declarative:
         self.widget = TW2WidgetBuilder(self.widget, **self.attrs)
     return self.request(1)
Пример #6
0
    def setup(self):
        if tmw and request_local:
            rl = request_local()
            rl.clear()
            rl['middleware'] = tmw.make_middleware(None)

        self.session = session
        self.engine = engine
        try:
            self.user = setup_records(session)
        except:
            self.session.rollback()
Пример #7
0
    def setup(self):
        if tmw and request_local:
            rl = request_local()
            rl.clear()
            rl['middleware'] = tmw.make_middleware(None)

        self.session = session
        self.engine = engine
        try:
            self.user = setup_records(session)
        except:
            self.session.rollback()
Пример #8
0
    def setup(self):
        global _request_id, _request_local
        _request_local = {}
        _request_id = None
        if hasattr(super(WidgetTest, self), 'setup'):
            super(WidgetTest, self).setup()
        self.mw = tmw.make_middleware(
            None,
            default_engine=self.template_engine
        )
        if self.declarative:
            self.widget = TW2WidgetBuilder(self.widget, **self.attrs)

        return self.request(1)
Пример #9
0
 def _check_rendering_vs_expected(self, engine, attrs, params, expected):
     if self.engines and engine not in self.engines:
         raise SkipTest("%r not in engines %r" % (engine, self.engines))
     _request_id = None
     templating.engine_name_cache = {}
     mw = tmw.make_middleware(None, preferred_rendering_engines=[engine])
     self.request(1, mw)
     try:
         r = self.widget(_no_autoid=True, **attrs).display(**params)
     except ValueError, e:
         if str(e).startswith("Could not find engine name"):
             raise SkipTest("No template for engine %r" % engine)
         else:
             raise
Пример #10
0
    def setup(self):
        if tmw and request_local:
            rl = request_local()
            rl.clear()
            rl['middleware'] = tmw.make_middleware(None)

        self.session = session
        self.engine = engine
        try:
            self.user = setup_records(session)
        except Exception as ex:
            try:
                self.session.close()
            except: pass
            raise ex
Пример #11
0
    def setUp(self):
        global _request_id, _request_local
        _request_local = {}
        _request_id = None

        # Clean up the cache
        templating.engine_name_cache = {}

        super(WidgetTest, self).setUp()

        self.mw = tmw.make_middleware(None,
                                      default_engine=self.template_engine)
        if self.declarative:
            self.widget = TW2WidgetBuilder(self.widget, **self.attrs)

        return self.request(1)
Пример #12
0
    def setUp(self):
        global _request_id, _request_local
        _request_local = {}
        _request_id = None

        # Clean up the cache
        templating.engine_name_cache = {}

        super(WidgetTest, self).setUp()

        self.mw = tmw.make_middleware(
            None,
            default_engine=self.template_engine
        )
        if self.declarative:
            self.widget = TW2WidgetBuilder(self.widget, **self.attrs)

        return self.request(1)
Пример #13
0
    def _copy_resources(self):

        # Set up fake middleware with which widgets can register their resources
        core.request_local = request_local_fake
        core.request_local()['middleware'] = middleware.make_middleware()

        # Load widgets and have them prepare their resources
        map(self._load_widget_entry_points, self.distributions)

        rl_resources = core.request_local().setdefault('resources', [])

        for resource in rl_resources:
            try:
                modname = resource.modname
                fbase = resource.filename.split('/')[0]
                self.execute(self._copy_resource_tree, (modname, fbase),
                             "Copying %s recursively into %s" %
                             (modname, self.writer.base))
            except AttributeError, e:
                pass
Пример #14
0
    def _copy_resources(self):

        # Set up fake middleware with which widgets can register their
        # resources
        core.request_local = request_local_fake
        core.request_local()['middleware'] = middleware.make_middleware()

        # Load widgets and have them prepare their resources
        map(self._load_widget_entry_points, self.distributions)

        rl_resources = core.request_local().setdefault('resources', [])

        for resource in rl_resources:
            try:
                modname = resource.modname
                fbase = resource.filename.split('/')[0]
                self.execute(self._copy_resource_tree, (modname, fbase),
                             "Copying %s recursively into %s" %
                             (modname, self.writer.base))
            except AttributeError, e:
                pass
Пример #15
0
    def _check_rendering_vs_expected(self, engine, attrs, params, expected):
        if self.engines and engine not in self.engines:
            raise SkipTest("%r not in engines %r" % (engine, self.engines))

        if engine == 'genshi':
            # Since version 0.7.x genshi doesn't add empty attributes like in
            # the other templating systems we remove the empty value
            expected = expected.replace(' value=""', '')

        _request_id = None
        templating.engine_name_cache = {}
        mw = tmw.make_middleware(None, preferred_rendering_engines=[engine])
        self.request(1, mw)
        try:
            r = self.widget(_no_autoid=True, **attrs).display(**params)
        except ValueError as e:
            if str(e).startswith("Could not find engine name"):
                raise SkipTest("No template for engine %r" % engine)
            else:
                raise

        # reset the cache as not to affect other tests
        assert_eq_xml(r, expected, self.wrap)
Пример #16
0
    def _check_rendering_vs_expected(self, engine, attrs, params, expected):
        if self.engines and engine not in self.engines:
            raise SkipTest("%r not in engines %r" % (engine, self.engines))

        if engine == 'genshi':
            # Since version 0.7.x genshi doesn't add empty attributes like in
            # the other templating systems we remove the empty value
            expected = expected.replace(' value=""', '')

        _request_id = None
        templating.engine_name_cache = {}
        mw = tmw.make_middleware(None, preferred_rendering_engines=[engine])
        self.request(1, mw)
        try:
            r = self.widget(_no_autoid=True, **attrs).display(**params)
        except ValueError as e:
            if str(e).startswith("Could not find engine name"):
                raise SkipTest("No template for engine %r" % engine)
            else:
                raise

        # reset the cache as not to affect other tests
        assert_eq_xml(r, expected, self.wrap)
Пример #17
0
 def setUp(self):
     self.mw = make_middleware(None, {})
Пример #18
0
except ImportError:
    from ming import datastore as DS
    def create_ming_datastore():
        return DS.DataStore(master=os.environ.get('MONGOURL', 'mongodb://127.0.0.1:27017/'), database='test_db')

try:
    from tw import framework
    framework.default_view = 'mako'
except ImportError:
    pass

try:
    import tw2.core.core
    import tw2.core.middleware as tmw

    _request_local = {'middleware':tmw.make_middleware(None)}
    def request_local_tst():
        return _request_local

    tw2.core.core.request_local = request_local_tst
    from tw2.core.core import request_local
except ImportError:
    tmw = None
    request_local = None

#try:
import xml.etree.ElementTree as etree
#except ImportError:
#    import cElementTree as etree

session = None
Пример #19
0
    def create_ming_datastore():
        return DS.DataStore(master=os.environ.get("MONGOURL", "mongodb://127.0.0.1:27017/"), database="test_db")


try:
    from tw import framework

    framework.default_view = "mako"
except ImportError:
    pass

try:
    import tw2.core.core
    import tw2.core.middleware as tmw

    _request_local = {"middleware": tmw.make_middleware(None)}

    def request_local_tst():
        return _request_local

    tw2.core.core.request_local = request_local_tst
    from tw2.core.core import request_local
except ImportError:
    tmw = None
    request_local = None

# try:
import xml.etree.ElementTree as etree

# except ImportError:
#    import cElementTree as etree
Пример #20
0
 def testMakeMiddelware(self):
     from tw2.core.middleware import make_middleware
     make_middleware(None)
Пример #21
0
import math
import uuid

import geojson
import flask
import tw2.polymaps
import yaml
import fastkml
import shapely.geometry

from tw2.polymaps.geojsonify import geojsonify
from tw2.core.middleware import make_middleware


app = flask.Flask(__name__)
app.wsgi_app = make_middleware(app.wsgi_app)

template = """
<html>
<head>
<style type="text/css">
svg {
        width: 100%;
        height: 100%;
}

.midnight-commander-extras {
        width: 100%;
        height: 100%;
}
Пример #22
0
def setup():
    core.request_local = request_local_tst
    core.request_local().setdefault('middleware',
                                    middleware.make_middleware())
Пример #23
0
 def setUp(self):
     self.widget = TW2WidgetBuilder(self.widget, **self.attrs)
     self.mw = make_middleware(None, {})
Пример #24
0
 def setUp(self):
     self.mw = make_middleware(None, {})
Пример #25
0
    def testMakeMiddelware(self):
        from tw2.core.middleware import make_middleware

        make_middleware(None)