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
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
def test_render_entry_points(self): self.skipTest("Skipping until we don't require tw2.forms for testing.") self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) import pprint print pprint.pformat(rl_resources)
def _get_link(self): rl = request_local() mw = rl["middleware"] external = self.external if isinstance(external, Deferred): external = external.fn() if not self._link: if external: link = self.external_link else: link = ( "/" + "/".join( ( mw.config.script_name.strip("/"), mw.config.res_prefix.strip("/"), self.modname, "static", self.dirname, self.core_filename, ) ) ).replace("//", "/") self._link = link return self._link % self.substitutions
def prepare(self): if not self.is_external: self.modname or self.__module__ rl = request_local() resources = rl["middleware"].resources resources.register(self.modname, os.path.dirname(self.filename), whole_dir=True) super(AltLinkMixin, self).prepare()
def request(self, requestid, mw=None): if mw is None: mw = self.mw global _request_id _request_id = requestid rl = request_local() rl.clear() rl['middleware'] = mw return request_local_tst()
def test_load_widgets(self): import tw2.forms.widgets import tw2.core self.c._load_widgets(tw2.forms.widgets) rl_resources = core.request_local().setdefault('resources', []) target = tw2.core.CSSLink(link="/resources/tw2.forms/static/forms.css").req() assert(any([ target.link == getattr(r, 'link', None) for r in rl_resources ]))
def prepare(self): if not self.is_external: self.modname or self.__module__ rl = request_local() resources = rl['middleware'].resources resources.register(self.modname, os.path.dirname(self.filename), whole_dir=True) super(AltLinkMixin, self).prepare()
def request(self, requestid, mw=None): if mw is None: mw = self.mw global _request_id _request_id = requestid rl = request_local() rl.clear() rl['middleware'] = mw return request_local_tst()
def test_load_entry_points(self): if HAS_SKIP: self.skipTest("Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) assert(len(rl_resources) != 0)
def test_load_no_widgets(self): if HAS_SKIP: self.skipTest("Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return import tw2.core.widgets self.c._load_widgets(tw2.core.widgets) rl_resources = core.request_local().setdefault('resources', []) assert(len(rl_resources) == 0)
def test_load_entry_points(self): if HAS_SKIP: self.skipTest( "Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) assert (len(rl_resources) != 0)
def test_load_widgets(self): self.skipTest("Skipping until we don't require tw2.forms for testing.") import tw2.forms.widgets import tw2.core self.c._load_widgets(tw2.forms.widgets) rl_resources = core.request_local().setdefault('resources', []) target = tw2.core.CSSLink(link="/resources/tw2.forms/static/forms.css").req() assert(any([ target.link == getattr(r, 'link', None) for r in rl_resources ]))
def test_load_no_widgets(self): if HAS_SKIP: self.skipTest( "Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return import tw2.core.widgets self.c._load_widgets(tw2.core.widgets) rl_resources = core.request_local().setdefault('resources', []) assert (len(rl_resources) == 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
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()
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
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()
def _get_link(self): rl = core.request_local() mw = rl['middleware'] if not self._link: if self.external: link = self.external_link else: link = ('/' + '/'.join( (mw.config.script_name.strip('/'), mw.config.res_prefix.strip('/'), self.modname, 'static', self.dirname, self.core_filename))).replace('//', '/') self._link = link return self._link % self.substitutions
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
def test_load_widgets(self): if HAS_SKIP: self.skipTest( "Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return import tw2.forms.widgets import tw2.core self.c._load_widgets(tw2.forms.widgets) rl_resources = core.request_local().setdefault('resources', []) target = tw2.core.CSSLink( link="/resources/tw2.forms/static/forms.css").req() assert (any( [target.link == getattr(r, 'link', None) for r in rl_resources]))
def _get_link(self): rl = core.request_local() mw = rl['middleware'] if not self._link: if self.external: link = self.external_link else: link = ('/' + '/'.join(( mw.config.script_name.strip('/'), mw.config.res_prefix.strip('/'), self.modname, 'static', self.dirname, self.core_filename ))).replace('//', '/') self._link = link return self._link % self.substitutions
def test_copy_tree(self): import tw2.core.command self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) self.c.writer = tw2.core.command.FileWriter(self.c, TMP_DIR) self.c._copy_resource_tree( rl_resources[-1].modname, rl_resources[-1].filename.split('/')[0], ) assert(os.path.isdir(TMP_DIR)) assert(os.path.isdir( '/'.join([TMP_DIR, 'tw2.forms']) )) assert(os.path.isdir( '/'.join([TMP_DIR, 'tw2.forms', 'static']) )) assert(os.path.isfile( '/'.join([TMP_DIR, 'tw2.forms', 'static', 'edit-undo.png']) ))
def test_copy_tree(self): if HAS_SKIP: self.skipTest( "Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return import tw2.core.command self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) self.c.writer = tw2.core.command.FileWriter(self.c, TMP_DIR) self.c._copy_resource_tree( rl_resources[-1].modname, rl_resources[-1].filename.split('/')[0], ) assert (os.path.isdir(TMP_DIR)) assert (os.path.isdir('/'.join([TMP_DIR, 'tw2.forms']))) assert (os.path.isdir('/'.join([TMP_DIR, 'tw2.forms', 'static']))) assert (os.path.isfile('/'.join( [TMP_DIR, 'tw2.forms', 'static', 'edit-undo.png'])))
def generate_output(self, displays_on): global genshi_tag if not displays_on: mw = request_local().get('middleware') displays_on = self._get_default_displays_on(mw) if displays_on == 'genshi': if not genshi_tag: import genshi.builder genshi_tag = genshi.builder.tag retval = getattr(genshi_tag, self.tag)(**self.attrs).generate() else: retval = "<{tag}{attrs}></{tag}>".format( tag=self.tag, attrs=self._render_attrs(self.attrs)) if displays_on == 'kajiki': global kajiki_literal if not kajiki_literal: import kajiki.util kajiki_literal = kajiki.util.literal retval = kajiki_literal(retval) return retval
def test_copy_tree(self): if HAS_SKIP: self.skipTest("Skipping until we don't require tw2.forms for testing.") else: # Just pretend like we passed... :/ return import tw2.core.command self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) self.c.writer = tw2.core.command.FileWriter(self.c, TMP_DIR) self.c._copy_resource_tree( rl_resources[-1].modname, rl_resources[-1].filename.split('/')[0], ) assert(os.path.isdir(TMP_DIR)) assert(os.path.isdir( '/'.join([TMP_DIR, 'tw2.forms']) )) assert(os.path.isdir( '/'.join([TMP_DIR, 'tw2.forms', 'static']) )) assert(os.path.isfile( '/'.join([TMP_DIR, 'tw2.forms', 'static', 'edit-undo.png']) ))
def prepare(self): super(CookieConsentWidget, self).prepare() if self.options: cfg = self.options else: cfg = self.default_options # always use full URLs for themes theme = cfg.get('theme', 'light-floating') rl = request_local() cfg['theme'] = ( rl['middleware'].config.res_prefix + 'tw2.cookieconsent/static/' + theme + ".css") # evaluate any lazy strings for key, value in cfg.items(): if is_lazy_string(value): cfg[key] = str(value) self.add_call(js_function( "(function(window,cfg){window.cookieconsent_options=cfg;})" )(js_symbol("window"), cfg), location='head') inject_resources()
def setup(): core.request_local = request_local_tst core.request_local().setdefault('middleware', middleware.make_middleware())
def test_load_entry_points(self): self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) assert(len(rl_resources) == 3)
def test_load_no_widgets(self): import tw2.core.widgets self.c._load_widgets(tw2.core.widgets) rl_resources = core.request_local().setdefault('resources', []) assert(len(rl_resources) == 0)
def test_load_no_widgets(self): self.skipTest("Skipping until we don't require tw2.forms for testing.") import tw2.core.widgets self.c._load_widgets(tw2.core.widgets) rl_resources = core.request_local().setdefault('resources', []) assert(len(rl_resources) == 0)
def test_load_entry_points(self): self.skipTest("Skipping until we don't require tw2.forms for testing.") self.c._load_widget_entry_points('tw2.forms') rl_resources = core.request_local().setdefault('resources', []) assert(len(rl_resources) != 0)