def make_test_env():
    try:
        shutil.rmtree('test_instance')
    except OSError:
        pass
    spawn('test_instance', init_config, instance_module)
    os.chdir('test_instance')
Example #2
0
    def test_create_bag_policies(self):
        spawn(instance_dir, config, instance_module)
        os.chdir(instance_dir)
        store = Store(config['server_store'][0],
                config['server_store'][1], environ=self.env)

        bag = Bag('system')
        system_policy = store.get(bag).policy
        bag = Bag('common')
        common_policy = store.get(bag).policy

        assert system_policy.read == []
        assert system_policy.write == ['R:ADMIN']
        assert system_policy.create == ['R:ADMIN']
        assert system_policy.manage == ['R:ADMIN']
        assert system_policy.accept == ['R:ADMIN']
        assert system_policy.delete == ['R:ADMIN']

        assert common_policy.read == []
        assert common_policy.write == []
        assert common_policy.create == []
        assert common_policy.manage == ['R:ADMIN']
        assert common_policy.accept == []
        assert common_policy.delete == []
        os.chdir('..')
Example #3
0
def _initialize_app(tmpdir): # XXX: side-effecty and inscrutable
    instance_dir = os.path.join(tmpdir, 'instance')

    spawn(instance_dir, init_config, instance)
    old_cwd = os.getcwd()
    os.chdir(instance_dir)
    # force loading of instance's `tiddlywebconfig.py`
    while old_cwd in sys.path:
        sys.path.remove(old_cwd)
    sys.path.insert(0, os.getcwd())
    merge_config(CONFIG, {}, reconfig=True) # XXX: should not be necessary!?

    CONFIG['server_host'] = {
        'scheme': 'http',
        'host': 'example.org',
        'port': '8001',
    }
    # TODO: test with server_prefix

    # add symlink to templates -- XXX: hacky, should not be necessary!?
    templates_path = instance.__file__.split(os.path.sep)[:-2] + ['templates']
    os.symlink(os.path.sep.join(templates_path), 'templates')

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('example.org', 8001, load_app)
Example #4
0
def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT

    # bump up a level if we're already in the test instance
    if os.getcwd().endswith('test_instance'):
        os.chdir('..')

    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system(
        'echo "drop database if exists tiddlyspacetest; create database tiddlyspacetest character set = utf8mb4 collate = utf8mb4_bin;" | mysql'
    )
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
        tiddlywebplugins.mysql3.Session.remove()
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.chdir('test_instance')
    os.symlink('../tiddlywebplugins/templates', 'templates')
    os.symlink('../tiddlywebplugins', 'tiddlywebplugins')

    from tiddlyweb.web import serve
    module.store = get_store(init_config)

    app = serve.load_app()

    if not hsearch:
        from tiddlywebplugins.whoosher import _tiddler_change_handler
        try:
            HOOKS['tiddler']['put'].remove(_tiddler_change_handler)
            HOOKS['tiddler']['delete'].remove(_tiddler_change_handler)
        except ValueError:
            pass

    def app_fn():
        return app

    module.app_fn = app_fn
def test_spawn_without_store_structure():
    # NB: `instance_pkgstores` only sensible if `store_structure` exists
    empty_config = {}
    spawn('testinstance', empty_config, DummyInstanceModule())

    assert os.path.exists('testinstance/tiddlywebconfig.py')
    assert os.path.exists('testinstance/store/bags')
    assert len(os.listdir('testinstance/store/bags')) == 0
Example #6
0
    def test_create_tiddlywebwiki_instance(self):
        spawn(instance_dir, config, instance_module)

        contents = _get_file_contents('%s/tiddlywebconfig.py'
                % instance_dir)

        assert "'system_plugins': ['tiddlywebwiki']" in contents
        assert "'twanager_plugins': ['tiddlywebwiki']" in contents
def test_spawn():
    from testpackage import instance as instance_module
    from testpackage.config import config as init_config

    spawn('testinstance', init_config, instance_module)

    assert os.path.exists('testinstance/tiddlywebconfig.py')
    assert os.path.exists('testinstance/store/bags/testbag/tiddlers/testtiddler')
Example #8
0
def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT

    # bump up a level if we're already in the test instance
    if os.getcwd().endswith('test_instance'):
        os.chdir('..')

    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('echo "drop database if exists tiddlyspacetest; create database tiddlyspacetest character set = utf8mb4 collate = utf8mb4_bin;" | mysql')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
        tiddlywebplugins.mysql3.Session.remove()
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.chdir('test_instance')
    os.symlink('../tiddlywebplugins/templates', 'templates')
    os.symlink('../tiddlywebplugins', 'tiddlywebplugins')

    from tiddlyweb.web import serve
    module.store = get_store(init_config)

    app = serve.load_app()

    if not hsearch:
        from tiddlywebplugins.whoosher import _tiddler_change_handler
        try:
            HOOKS['tiddler']['put'].remove(_tiddler_change_handler)
            HOOKS['tiddler']['delete'].remove(_tiddler_change_handler)
        except ValueError:
            pass

    def app_fn():
        return app
    module.app_fn = app_fn
Example #9
0
def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT
    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('mysqladmin -f drop tiddlyspacetest create tiddlyspacetest')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config
    init_config['log_level'] = 'DEBUG'

    if sys.path[0] != os.getcwd():
        sys.path.insert(0, os.getcwd())
    spawn('test_instance', init_config, instance_module)
    os.symlink('tiddlywebplugins/templates', 'test_instance/templates')

    from tiddlyweb.web import serve
    module.store = get_store(config)

    app = serve.load_app()

    if not hsearch:
        from tiddlywebplugins.whoosher import _tiddler_change_handler
        try:
            HOOKS['tiddler']['put'].remove(_tiddler_change_handler)
            HOOKS['tiddler']['delete'].remove(_tiddler_change_handler)
        except ValueError:
            pass

    def app_fn():
        return app
    module.app_fn = app_fn
def test_spawn():
    spawn('testinstance', init_config, instance_module)

    assert os.path.exists('testinstance/tiddlywebconfig.py')
    assert os.path.exists('testinstance/store/bags/testbag/tiddlers/testtiddler')
def test_spawn_without_pgkstore():
    empty_config = {}
    spawn('testinstance', empty_config, instance_module)

    assert os.path.exists('testinstance/tiddlywebconfig.py')
    assert not os.path.exists('testinstance/store/bags/testbag/tiddlers/testtiddler')