def setup_module(module):
    # cleanup
    try:
        shutil.rmtree('store')
    except OSError:
        pass

    # establish web server
    app = load_app()
    def app_fn():
        return app
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)

    # establish store
    store = Store(config['server_store'][0], config['server_store'][1],
            environ={'tiddlyweb.config': config})

    # make some stuff
    bag = Bag('place')
    store.put(bag)
    for i in range(1, 10):
        tiddler = Tiddler('tiddler%s' % i, 'place')
        tiddler.text = 'hi%s'
        store.put(tiddler)

    module.http = httplib2.Http()
Ejemplo n.º 2
0
def profile_listing_tiddlers():
    store = Store('text', environ=environ)
    environ['tiddlyweb.store'] = store

    bag = Bag('profiler')
    bag.skinny = True
    store.get(bag)

    print 'filter', time()
    filter_string = 'select=tag:100'
    filters, leftovers = parse_for_filters(filter_string, environ)
    tiddlers = control.filter_tiddlers_from_bag(bag, filters)

    print 'tmp bag', time()
    tmp_bag = Bag('tmp_bag', tmpbag=True)
    tmp_bag.add_tiddlers(tiddlers)

    print 'output', time()
    print[tiddler.title for tiddler in control.get_tiddlers_from_bag(tmp_bag)]

    #print 'serializer', time()
    #serializer = Serializer('wiki', environ)
    #print 'wikify', time()
    #output = serializer.list_tiddlers(tmp_bag)

    print 'done', time()
 def __init__(self, store_config=None, environ=None):
     super(Store, self).__init__(store_config, environ)
     self.config = environ.get('tiddlyweb.config')
     self.binary_store = StoreBoss('text', {'store_root': 'binarystore'},
             environ=environ).storage
     self.core_store = StoreBoss(self.config['binarystore.child'][0],
             self.config['binarystore.child'][1], environ=environ).storage
Ejemplo n.º 4
0
def test_tiddler_get():
    store = Store('tiddlywebplugins.mappingsql',
                  {'db_config': 'sqlite:///test.db'},
                  {'tiddlyweb.config': config})
    tiddler = Tiddler('monkey', 'avox')
    tiddler = store.get(tiddler)
    assert tiddler.fields['field_one'] == 'fat'
def cache_tiddlers(package_name):
    """
    Stores instance tiddlers in the package.

    reads store_contents from <package>.instance

    tiddler files are stored in <package>/resources/store
    """
    instance_module = __import__('%s.instance' % package_name, None, None,
        ['instance'])
    store_contents = instance_module.store_contents

    target_store = Store('tiddlywebplugins.pkgstore',
            {'package': package_name, 'read_only': False}, {})

    sources = {}
    for bag, uris in store_contents.items():
        sources[bag] = []
        for uri in uris:
            if uri.endswith('.recipe'):
                urls = recipe_to_urls(uri)
                sources[bag].extend(urls)
            else:
                sources[bag].append(uri)

    for bag_name, uris in sources.items():
        bag = Bag(bag_name)
        target_store.put(bag)

        for uri in uris:
            std_error_message('retrieving %s' % uri)
            tiddler = url_to_tiddler(uri)
            tiddler.bag = bag.name
            target_store.put(tiddler)
Ejemplo n.º 6
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('..')
Ejemplo n.º 7
0
def _make_recipe(recipe_name, bags):
    """Make a recipe with recipe_name."""
    recipe = Recipe(recipe_name)
    recipe_list = [[bag, ''] for bag in bags]
    recipe.set_recipe(recipe_list)
    store = Store(config['server_store'][0], environ={'tiddlyweb.config': config})
    store.put(recipe)
Ejemplo n.º 8
0
def test_bag_get():
    store = Store('tiddlywebplugins.mappingsql', {'db_config': 'sqlite:///test.db'}, {'tiddlyweb.config': config})
    bag = Bag('avox')
    assert len(bag.list_tiddlers()) == 0

    bag = store.get(bag)
    assert len(bag.list_tiddlers()) == 1
    assert "NONE" in bag.policy.write
Ejemplo n.º 9
0
def test_bag_get():
    store = Store("tiddlywebplugins.mappingsql", {"db_config": "sqlite:///test.db"}, {"tiddlyweb.config": config})
    bag = Bag("avox")
    assert len(list(store.list_bag_tiddlers(bag))) == 1

    bag = store.get(bag)
    assert len(list(store.list_bag_tiddlers(bag))) == 1
    assert "NONE" in bag.policy.write
Ejemplo n.º 10
0
 def __init__(self, store_config=None, environ=None):
     super(Store, self).__init__(store_config, environ)
     self.config = environ.get('tiddlyweb.config')
     self.binary_store = StoreBoss('text', {
         'store_root': 'binarystore'
     },
                                   environ=environ).storage
     self.core_store = StoreBoss(self.config['binarystore.child'][0],
                                 self.config['binarystore.child'][1],
                                 environ=environ).storage
Ejemplo n.º 11
0
def test_tiddler_limit_field():
    store = Store('tiddlywebplugins.mappingsql', {'db_config': 'sqlite:///test.db'}, {'tiddlyweb.config': config})
    tiddler = Tiddler('monkey', 'avox')
    tiddler = store.get(tiddler)
    assert tiddler.fields['field_one'] == 'fat'
    assert 'field_three' not in tiddler.fields
    assert 'field_two' not in tiddler.fields

    store = Store('tiddlywebplugins.mappingsql', {'db_config': 'sqlite:///test.db'}, {
        'tiddlyweb.config': config,
        'tiddlyweb.usersign': {'name': 'zow'}
        })
    tiddler = Tiddler('monkey', 'avox')
    tiddler = store.get(tiddler)
    assert tiddler.fields['field_one'] == 'fat'
    assert 'field_three' in tiddler.fields
    assert 'field_two' in tiddler.fields

    store = Store('tiddlywebplugins.mappingsql', {'db_config': 'sqlite:///test.db'}, {
        'tiddlyweb.config': config,
        'tiddlyweb.usersign': {'name': u'GUEST'}
        })
    tiddler = Tiddler('monkey', 'avox')
    tiddler = store.get(tiddler)
    assert tiddler.fields['field_one'] == 'fat'
    assert 'field_three' not in tiddler.fields
    assert 'field_two' not in tiddler.fields
Ejemplo n.º 12
0
def make_tiddlers_for_bag():
    store = Store('text', environ=environ)

    print 'store', time()
    bag = Bag('profiler')
    store.put(bag)

    for name in range(1, 1000):
        name = str(name)
        tiddler = Tiddler(name, bag.name)
        tiddler.text = name
        store.put(tiddler)
Ejemplo n.º 13
0
def get_request(environ, start_response):
	query = environ["tiddlyweb.query"]
	tiddler_count = query.get("tiddlers", [default_tiddler_count])[0]

	store = Storage("datagenerator", {})
	bag = Bag(str(tiddler_count))
	bag = store.get(bag)
	# populate tiddlers in bag
	for tiddler in bag.list_tiddlers():
		store.get(tiddler)

	return send_tiddlers(environ, start_response, bag)
Ejemplo n.º 14
0
def test_where_it_goes():
    store = Store(SAMPLE_CONFIG['server_store'][0],
            SAMPLE_CONFIG['server_store'][1],
            environ=ENVIRON)
    bbag = Bag('bbag')
    cbag = Bag('cbag')
    store.put(bbag)
    store.put(cbag)

    assert os.path.exists('store1/bags/bbag/tiddlers')
    assert os.path.exists('store2/bags/cbag/tiddlers')
    assert not os.path.exists('store2/bags/bbag/tiddlers')
    assert not os.path.exists('store1/bags/cbag/tiddlers')
Ejemplo n.º 15
0
def profile_listing_tiddlers():
    store = Store('text', environ['tiddlyweb.config']['server_store'][1], environ)
    environ['tiddlyweb.store'] = store

    bag = Bag('profiler')

    print 'filter', time()
    filter_string = 'select=tag:1'
    filters, leftovers = parse_for_filters(filter_string, environ)
    tiddlers = control.filter_tiddlers(store.list_bag_tiddlers(bag), filters, environ=environ)

    print 'output', time()
    print [tiddler.title for tiddler in tiddlers]
Ejemplo n.º 16
0
def test_where_it_goes():
    store = Store(SAMPLE_CONFIG['server_store'][0],
                  SAMPLE_CONFIG['server_store'][1],
                  environ=ENVIRON)
    bbag = Bag('bbag')
    cbag = Bag('cbag')
    store.put(bbag)
    store.put(cbag)

    assert os.path.exists('store1/bags/bbag/tiddlers')
    assert os.path.exists('store2/bags/cbag/tiddlers')
    assert not os.path.exists('store2/bags/bbag/tiddlers')
    assert not os.path.exists('store1/bags/cbag/tiddlers')
def setup_module(module):
    bag = Bag('holder')
    store = Store(config['server_store'][0], config['server_store'][1],
            {'tiddlyweb.config': config})
    store.put(bag)

    import_one('holder', IMAGE, store)
    import_one('holder', ZERO, store)

    tiddler = Tiddler('index', 'holder')
    tiddler.text = open(HTML).read().decode('UTF-8')
    tiddler.type = 'text/html'
    store.put(tiddler)
    module.store = store
Ejemplo n.º 18
0
def setup_module(module):
    reset_textstore()
    module.savedin = sys.stdin
    sys.exit = boring_exit
    module.store = Store(config['server_store'][0],
            config['server_store'][1],
            environ={'tiddlyweb.config': config})
Ejemplo n.º 19
0
def setup_module(module):
    if os.path.exists('store'):
        shutil.rmtree('store')

    module.config = config
    module.store = Store('simpletext', {'store_root': 'store'},
                         environ={'tiddlyweb.config': config})
Ejemplo n.º 20
0
def migrate(args):
    """Migrate the content in current store to one described in target_store in config."""
    source_environ = {'tiddlyweb.config': config}
    target_environ = copy.deepcopy(source_environ)
    target_environ['tiddlyweb.config']['server_store'] = config['target_store']
    source_store = Store(config['server_store'][0], config['server_store'][1],
                         source_environ)
    target_store = Store(config['target_store'][0], config['target_store'][1],
                         target_environ)

    if args:
        migrate_bags(source_store, target_store, bags=args)
    else:
        migrate_users(source_store, target_store)
        migrate_recipes(source_store, target_store)
        migrate_bags(source_store, target_store)
Ejemplo n.º 21
0
def make_tiddlers_for_bag():
    store = Store('text', environ['tiddlyweb.config']['server_store'][1], environ)

    print 'store', time()
    bag = Bag('profiler')
    store.put(bag)

    for name in range(1, 10000):
        tag = name % 10
        name = str(name)
        tag = str(tag)
        tiddler = Tiddler(name, bag.name)
        tiddler.text = name
        tiddler.tags.append(tag)
        store.put(tiddler)
    print 'stored', time()
Ejemplo n.º 22
0
    def __init__(self, store_config=None, environ=None):
        if store_config is None:
            store_config = {}
        if environ is None:
            environ = {}
        self.environ = environ
        self.config = environ.get('tiddlyweb.config')

        self._mc = self._MC

        if self._mc == None:
            try:
                from google.appengine.api import memcache
                self._MC = memcache
            except ImportError:
                import memcache
                try:
                    self._MC = memcache.Client(self.config['memcache_hosts'])
                except KeyError:
                    from tiddlyweb.config import config
                    self.config = config
                    self._MC = memcache.Client(self.config['memcache_hosts'])
            self._mc = self._MC

            self.cached_store = StoreBoss(self.config['cached_store'][0],
                                          self.config['cached_store'][1],
                                          environ=environ)
            self.prefix = self.config['server_prefix']
            self.host = self.config['server_host']['host']
Ejemplo n.º 23
0
def init(init_config):
    selector = init_config['selector']
    replace_handler(selector, '/', GET=home_page)
    selector.add('/loadall', GET=load_all)
    store = Store(config['server_store'][0],
                  config['server_store'][1],
                  environ={'tiddlyweb.config': config})
Ejemplo n.º 24
0
    def __init__(self, store_config=None, environ=None):
        if store_config is None:
            store_config = {}
        if environ is None:
            environ = {}
        self.environ = environ
        self.config = environ.get("tiddlyweb.config")

        self._mc = self._MC

        if self._mc == None:
            try:
                from google.appengine.api import memcache

                self._MC = memcache
            except ImportError:
                import memcache

                try:
                    self._MC = memcache.Client(self.config["memcache_hosts"])
                except KeyError:
                    from tiddlyweb.config import config

                    self.config = config
                    self._MC = memcache.Client(self.config["memcache_hosts"])
            self._mc = self._MC

            self.cached_store = StoreBoss(
                self.config["cached_store"][0], self.config["cached_store"][1], environ=environ
            )
            self.prefix = self.config["server_prefix"]
            self.host = self.config["server_host"]["host"]
Ejemplo n.º 25
0
def test_recipe_put_to_store():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	name = "foo"
	recipe = Recipe(name)
	store.put(recipe)

	assert os.path.exists("%s.recipe" % os.path.join(STORE_DIR, name))
Ejemplo n.º 26
0
	def __init__(self, environ=None):
		logging.debug("initializing SSL Store")
		super(Store, self).__init__(environ)
		config = self.environ["tiddlyweb.config"]
		self.ssl_bags = config["ssl_bags"] # intentionally not providing empty fallback -- XXX: rename?
		real_store = config["server_store"][1]["store_module"] # XXX: rename? -- TODO: use pop method to keep config clean?
		self.real_store = Storage(real_store, self.environ)
Ejemplo n.º 27
0
def test_get_tiddler_revision():
	_cleanup()

	config = { "server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {
			"myBag": ["%s/alpha/index.recipe" % REPO_DIR]
		},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	tiddler = Tiddler("lorem")
	tiddler.bag = "myBag"
	t = store.get(tiddler)

	assert t.title == "lorem"
	assert t.bag == "myBag"
	assert t.revision == 1
	assert t.tags == []
	assert t.creator == "FND"
	assert t.modifier == "FND"
	assert len(t.created) == 14
	assert len(t.modified) == 14
	assert t.created == t.modified
	assert t.text == "lorem ipsum"

	tiddler = Tiddler("hello world")
	tiddler.bag = "myBag"
	tiddler.tags = ["foo", "bar"]
	tiddler.modifier = "FND"
	tiddler.text = "lorem ipsum"
	store.put(tiddler)
	tiddler = Tiddler("hello world")
	tiddler.bag = "myBag"
	t = store.get(tiddler)

	assert t.title == "hello world"
	assert t.bag == "myBag"
	assert t.revision == 1
	assert t.tags == ["foo", "bar"]
	assert t.creator == "FND"
	assert t.modifier == "FND"
	assert len(t.created) == 14
	assert len(t.modified) == 14
	assert t.created == t.modified
	assert t.text == "lorem ipsum"
Ejemplo n.º 28
0
    def update_store(self):
        """
        prepopulates/updates store contents by (re)importing instance_tiddlers
        """
        cwd = os.getcwd()
        os.chdir(self.root)

        store = get_store(self.init_config)
        for package_name in self.init_config['instance_pkgstores']:
            source_store = Store('tiddlywebplugins.pkgstore',
                    {'package': package_name, 'read_only': True},
                    {'tiddlyweb.config': self.init_config})
            for bag in source_store.list_bags():
                for tiddler in source_store.list_bag_tiddlers(bag):
                    tiddler = source_store.get(tiddler)
                    store.put(tiddler)
        os.chdir(cwd)
Ejemplo n.º 29
0
def _teststore():
    """
    Different from the above because it is using config loaded in this
    module. Kept for backwards awareness.
    """
    return Store(config['server_store'][0],
                 config['server_store'][1],
                 environ={'tiddlyweb.config': config})
Ejemplo n.º 30
0
def setup_module(module):
    module.store = Store(config['server_store'][0],
                         config['server_store'][1],
                         environ={'tiddlyweb.config': config})
    module.environ = {
        'tiddlyweb.store': module.store,
        'tiddlyweb.config': config
    }
Ejemplo n.º 31
0
def setup_module(module):
    module.store = Store(config['server_store'][0], config['server_store'][1],
                         {'tiddlyweb.config': config})
    # delete everything
    Base.metadata.drop_all()
    Base.metadata.create_all()
    import warnings
    warnings.simplefilter('error')
Ejemplo n.º 32
0
def test_list_bags_in_store():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {
			"alpha": ["%s/alpha/index.recipe" % REPO_DIR],
			"bravo": ["%s/bravo/index.recipe" % REPO_DIR]
		},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	actual = [bag.name for bag in store.list_bags()]
	expected = ["bravo", "alpha"]
	assert sorted(actual) == sorted(expected)
Ejemplo n.º 33
0
def setup_module(module):
    config['system_plugins'] = ['tiddlywebplugins.methodhack']
    from tiddlyweb.web import serve
    def app_fn():
        return serve.load_app()
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
    module.store = Store(config['server_store'][0], config['server_store'][1],
            {'tiddlyweb.config': config})
Ejemplo n.º 34
0
def test_unsupported_class():
    class Foo(object):
        pass

    foo = Foo()
    store = Store(config['server_store'][0],
                  config['server_store'][1],
                  environ={'tiddlyweb.config': config})
    py.test.raises(AttributeError, 'store.put(foo)')
Ejemplo n.º 35
0
def setup_module(module):
    module.store = Store('ramstore', {}, {})
    config['server_store'] = ['ramstore', {}]

    def app_fn():
        return serve.load_app()

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
Ejemplo n.º 36
0
def test_list_recipes_in_store():
    _cleanup()

    config = {
        "server_store": ["tiddlywebplugins.devstore", {"store_root": STORE_DIR}],
        "instance_tiddlers": {},
        "root_dir": "",
    }
    env = {"tiddlyweb.config": config}
    store = Store(config["server_store"][0], config["server_store"][1], env)

    for name in ["alpha", "bravo", "charlie"]:
        filepath = "%s.recipe" % os.path.join(STORE_DIR, name)
        open(filepath, "w").close()

    actual = [recipe.name for recipe in store.list_recipes()]
    expected = ["bravo", "alpha", "charlie"]
    assert set(actual) == set(expected)
Ejemplo n.º 37
0
def test_get_bag_from_store():
    _cleanup()

    config = {
        "server_store": ["tiddlywebplugins.devstore", {"store_root": STORE_DIR}],
        "instance_tiddlers": {"myBag": ["%s/alpha/index.recipe" % REPO_DIR]},
        "root_dir": "",
    }
    env = {"tiddlyweb.config": config}
    store = Store(config["server_store"][0], config["server_store"][1], env)

    bag = Bag("myBag")
    bag = store.get(bag)

    assert bag.name == "myBag"

    actual = [tiddler.title for tiddler in bag.list_tiddlers()]
    expected = ["SiteTitle", "foo", "lorem"]
    assert sorted(actual) == sorted(expected)
Ejemplo n.º 38
0
def profile_listing_tiddlers():
    store = Store('text', environ=environ)
    environ['tiddlyweb.store'] = store

    bag = Bag('profiler')
    bag.skinny = True
    store.get(bag)

    print 'filter', time()
    filter_string = 'select=tag:100'
    filters, leftovers = parse_for_filters(filter_string, environ)
    tiddlers = control.filter_tiddlers_from_bag(bag, filters)

    print 'tmp bag', time()
    tmp_bag = Bag('tmp_bag', tmpbag=True)
    tmp_bag.add_tiddlers(tiddlers)

    print 'output', time()
    print [tiddler.title for tiddler in control.get_tiddlers_from_bag(tmp_bag)]
Ejemplo n.º 39
0
def test_put_tiddler_to_store():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {
			"myBag": ["%s/alpha/index.recipe" % REPO_DIR]
		},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	tiddler = Tiddler("lorem")
	tiddler.bag = "myBag"
	store.put(tiddler)

	tiddler_path = os.path.join(STORE_DIR, tiddler.bag, "%s.tid" % tiddler.title)
	assert os.path.exists(tiddler_path)

	tiddler = Tiddler("foo bar")
	tiddler.bag = "myBag"
	store.put(tiddler)

	tiddler_path = os.path.join(STORE_DIR, "myBag", "foo%20bar.tid")
	assert os.path.exists(tiddler_path)
	assert store.get(tiddler).title == "foo bar"

	# XXX: testing get operation here for convenience
	bag = Bag("myBag")
	try:
		assert "foo bar" in [t.title for t in store.list_bag_tiddlers(bag)]
	except AttributeError: # TiddlyWeb 1.0 has no list_bag_tiddlers method
		pass

	tiddler = Tiddler("foo/bar")
	tiddler.bag = "myBag"
	store.put(tiddler)

	tiddler_path = os.path.join(STORE_DIR, "myBag", "foo%2Fbar.tid")
	assert os.path.exists(tiddler_path)
	assert store.get(tiddler).title == "foo/bar"
Ejemplo n.º 40
0
def setup_module(module):
    module.store = Store(config['server_store'][0],
                         config['server_store'][1],
                         environ={'tiddlyweb.config': config})
    try:
        bag = Bag('holder')
        store.delete(bag)
    except:
        pass
    bag = Bag('holder')
    module.store.put(bag)
Ejemplo n.º 41
0
    def __init__(self, environ=None):
        if environ is None:
            environ = {}
        self.environ = environ

        internal_store_environ  = {
                'tiddlyweb.config': {
                    'server_store': config['cached_store'],
                    }
                }
        self.cached_store = StoreBoss('text', environ=internal_store_environ)
Ejemplo n.º 42
0
    def _init_store(self):
        server_store = self.environ['tiddlyweb.config']['server_store']
        extra_store_config = server_store[1]['extras']
        main_store_config = server_store[1]['main']

        self.main_store = Storer(main_store_config[0], main_store_config[1],
                self.environ)

        for rule, store in extra_store_config:
            pattern = re.compile(rule)
            self.stores.append((pattern, Storer(store[0], store[1],
                self.environ)))
Ejemplo n.º 43
0
def test_recipe_delete_from_store():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	name = "foo"
	recipe = Recipe(name)
	recipe.desc = "lorem ipsum"
	store.put(recipe)

	recipe = Recipe(name)
	store.delete(recipe)

	recipe = Recipe(name)
	raises(NoRecipeError, "store.get(recipe)")
Ejemplo n.º 44
0
def test_tiddler_limit_field():
    store = Store("tiddlywebplugins.mappingsql", {"db_config": "sqlite:///test.db"}, {"tiddlyweb.config": config})
    tiddler = Tiddler("monkey", "avox")
    tiddler = store.get(tiddler)
    assert tiddler.fields["field_one"] == "fat"
    assert "field_three" not in tiddler.fields
    assert "field_two" not in tiddler.fields

    store = Store(
        "tiddlywebplugins.mappingsql",
        {"db_config": "sqlite:///test.db"},
        {"tiddlyweb.config": config, "tiddlyweb.usersign": {"name": "zow"}},
    )
    tiddler = Tiddler("monkey", "avox")
    tiddler = store.get(tiddler)
    assert tiddler.fields["field_one"] == "fat"
    assert "field_three" in tiddler.fields
    assert "field_two" in tiddler.fields

    store = Store(
        "tiddlywebplugins.mappingsql",
        {"db_config": "sqlite:///test.db"},
        {"tiddlyweb.config": config, "tiddlyweb.usersign": {"name": u"GUEST"}},
    )
    tiddler = Tiddler("monkey", "avox")
    tiddler = store.get(tiddler)
    assert tiddler.fields["field_one"] == "fat"
    assert "field_three" not in tiddler.fields
    assert "field_two" not in tiddler.fields
Ejemplo n.º 45
0
class TestInstance(object):

    def setup_method(self, module):
        env = { 'tiddlyweb.config': config }
        self.store = Store(config['server_store'][0], config['server_store'][1], environ=env)

    def teardown_method(self, module):
        os.chdir('..')
        rmtree(instance_dir)

    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_create_bag_policies(self):
        spawn(instance_dir, config, instance_module)

        bag = Bag('system')
        system_policy = self.store.get(bag).policy
        bag = Bag('common')
        common_policy = self.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 == []
Ejemplo n.º 46
0
def profile_listing_tiddlers():
    store = Store('text', environ['tiddlyweb.config']['server_store'][1],
                  environ)
    environ['tiddlyweb.store'] = store

    bag = Bag('profiler')

    print 'filter', time()
    filter_string = 'select=tag:1'
    filters, leftovers = parse_for_filters(filter_string, environ)
    tiddlers = control.filter_tiddlers(store.list_bag_tiddlers(bag),
                                       filters,
                                       environ=environ)

    print 'output', time()
    print[tiddler.title for tiddler in tiddlers]

    #print 'serializer', time()
    #serializer = Serializer('wiki', environ)
    #print 'wikify', time()
    #output = serializer.list_tiddlers(tmp_bag)

    print 'done', time()
Ejemplo n.º 47
0
def test_serialization():
	_cleanup()

	config = {
		"server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }],
		"instance_tiddlers": {},
		"root_dir": ""
	}
	env = { "tiddlyweb.config": config }
	store = Store(config["server_store"][0], config["server_store"][1], env)

	name = "foo"
	recipe = Recipe(name)
	recipe.desc = "lorem ipsum"
	store.put(recipe)

	f = open("%s.recipe" % os.path.join(STORE_DIR, name))
	actual = f.read()
	f.close()
	expected = """desc: lorem ipsum
policy: {"read": [], "create": [], "manage": [], "accept": [], "write": [], "owner": null, "delete": []}
"""
	assert actual == expected
def setup_module(module):
    initialize_app()

    module.store = Store(config['server_store'][0], config['server_store'][1],
                         {'tiddlyweb.config': config})
    bag = Bag('MAPUSER')
    module.store.put(bag)

    user = User('ben')
    user.set_password('mocha')
    module.store.put(user)
    user = User('chris')
    user.set_password('piccolo')
    module.store.put(user)
Ejemplo n.º 49
0
    def _init_store(self):
        server_store = self.environ['tiddlyweb.config']['server_store']
        server_store_copy = copy.deepcopy(server_store)
        extra_store_config = server_store[1]['extras']
        main_store_config = server_store[1]['main']

        self.environ['tiddlyweb.config']['server_store'] = main_store_config
        self.main_store = Storer(main_store_config[0], main_store_config[1],
                                 self.environ)

        for rule, store in extra_store_config:
            pattern = re.compile(rule)
            self.environ['tiddlyweb.config']['server_store'] = store
            self.environ['tiddlyweb.config']['main_store'] = self.main_store
            self.stores.append(
                (pattern, Storer(store[0], store[1], self.environ)))
        self.environ['tiddlyweb.config']['server_store'] = server_store_copy
Ejemplo n.º 50
0
def setup_module(module):
    bag = Bag('holder')
    store = Store(config['server_store'][0], config['server_store'][1],
                  {'tiddlyweb.config': config})
    store.put(bag)

    import_one('holder', IMAGE, store)
    import_one('holder', ZERO, store)

    tiddler = Tiddler('index', 'holder')
    tiddler.text = open(HTML).read().decode('UTF-8')
    tiddler.type = 'text/html'
    store.put(tiddler)
    module.store = store
Ejemplo n.º 51
0
def make_tiddlers_for_bag():
    store = Store('text', environ=environ)

    print 'store', time()
    bag = Bag('profiler')
    store.put(bag)

    for name in range(1, 10000):
        tag = name % 10
        name = str(name)
        tag = str(tag)
        tiddler = Tiddler(name, bag.name)
        tiddler.text = name
        tiddler.tags.append(tag)
        store.put(tiddler)
    print 'stored', time()
Ejemplo n.º 52
0
from tiddlyweb.config import config
from tiddlyweb.store import Store
from tiddlyweb.model.bag import Bag
from tiddlyweb.model.tiddler import Tiddler

from tiddlywebplugins.whoosher import init, search

environ = {'tiddlyweb.config': config}
store = Store(config['server_store'][0], config['server_store'][1], environ)
environ['tiddlyweb.store'] = store

init(config)


def test_search_unique():
    bag = Bag('bag1')
    store.put(bag)
    tiddler1 = Tiddler('tiddler1', 'bag1')
    tiddler1.text = 'catsdogshouses'
    store.put(tiddler1)

    tiddler2 = Tiddler('tiddler2', 'bag1')
    tiddler2.text = 'housesdogscats'
    store.put(tiddler2)

    tiddlers = list(search(config, 'catsdogshouses'))
    assert len(tiddlers) == 1
    assert tiddlers[0]['id'] == 'bag1:tiddler1'

    tiddlers = list(search(config, 'housesdogscats'))
Ejemplo n.º 53
0
 def _store():
     """Get our Store from config."""
     return Store(config['server_store'][0],
                  config['server_store'][1],
                  environ={'tiddlyweb.config': config})
Ejemplo n.º 54
0
def test_module_load_fail():
    with py.test.raises(ImportError):
        store = Store("notexiststore")
Ejemplo n.º 55
0
def setup_module(module):
    module.store = Store('sql', {'db_config': 'sqlite:///store.db'},
                         environ={'tiddlyweb.config': config})
Ejemplo n.º 56
0
class Store(StorageInterface):
    def __init__(self, store_config=None, environ=None):
        super(Store, self).__init__(store_config, environ)
        self.main_store = None
        self.stores = []
        self._init_store()

    def _init_store(self):
        server_store = self.environ['tiddlyweb.config']['server_store']
        server_store_copy = copy.deepcopy(server_store)
        extra_store_config = server_store[1]['extras']
        main_store_config = server_store[1]['main']

        self.environ['tiddlyweb.config']['server_store'] = main_store_config
        self.main_store = Storer(main_store_config[0], main_store_config[1],
                                 self.environ)

        for rule, store in extra_store_config:
            pattern = re.compile(rule)
            self.environ['tiddlyweb.config']['server_store'] = store
            self.environ['tiddlyweb.config']['main_store'] = self.main_store
            self.stores.append(
                (pattern, Storer(store[0], store[1], self.environ)))
        self.environ['tiddlyweb.config']['server_store'] = server_store_copy

    def recipe_delete(self, recipe):
        self.main_store.delete(recipe)

    def recipe_get(self, recipe):
        return self.main_store.get(recipe)

    def recipe_put(self, recipe):
        self.main_store.put(recipe)

    def bag_delete(self, bag):
        store = self._determine_store(bag.name)
        store.delete(bag)

    def bag_get(self, bag):
        store = self._determine_store(bag.name)
        return store.get(bag)

    def bag_put(self, bag):
        store = self._determine_store(bag.name)
        store.put(bag)

    def tiddler_delete(self, tiddler):
        store = self._determine_store(tiddler.bag)
        store.delete(tiddler)

    def tiddler_get(self, tiddler):
        store = self._determine_store(tiddler.bag)
        return store.get(tiddler)

    def tiddler_put(self, tiddler):
        store = self._determine_store(tiddler.bag)
        store.put(tiddler)

    def user_delete(self, user):
        self.main_store.delete(user)

    def user_get(self, user):
        return self.main_store.get(user)

    def user_put(self, user):
        return self.main_store.put(user)

    def list_recipes(self):
        return self.main_store.list_recipes()

    def list_bags(self):
        bags = []
        for rule, store in self.stores:
            bags.extend(store.list_bags())
        bags.extend(self.main_store.list_bags())
        return bags

    def list_users(self):
        return self.main_store.list_users()

    def list_tiddler_revisions(self, tiddler):
        store = self._determine_store(tiddler.bag)
        return store.list_tiddler_revisions(tiddler)

    def search(self, search_query):
        tiddlers = []
        searched = False
        for rule, store in self.stores:
            try:
                tiddlers.extend(store.search(search_query))
                searched = True
            except StoreMethodNotImplemented:
                pass  # just ride right over those stores that don't search
        try:
            tiddlers.extend(self.main_store.search(search_query))
            searched = True
        except StoreMethodNotImplemented:
            pass
        if not searched:
            raise StoreMethodNotImplemented
        return tiddlers

    def _determine_store(self, name):
        for pattern, store in self.stores:
            # XXX should this be search or match?
            if pattern.match(name):
                return store
        return self.main_store
Ejemplo n.º 57
0
 def __call__(self, environ, start_response):
     database = Store(environ['tiddlyweb.config']['server_store'][0],
             environ['tiddlyweb.config']['server_store'][1],
             environ)
     environ['tiddlyweb.store'] = database
     return self.application(environ, start_response)