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
def test_post_no_title(): """ post a tiddler with no title set and make sure it gets into the store """ store = setup_store() setup_web() http = httplib2.Http() #post some fields to a tiddler response = http.request('http://test_domain:8001/bags/foo/tiddlers', method='POST', headers={'Content-type': 'application/x-www-form-urlencoded'}, body='text=Hi%20There')[0] assert response.status == 204 #now find the tiddler just entered and check it bag = Bag('foo') bag = store.get(bag) tiddlers = bag.list_tiddlers() assert len(tiddlers) == 1 tiddler = store.get(tiddlers[0]) assert tiddler.title != '' assert tiddler.text == 'Hi There'
def test_post_fields(): """ post some fields to a tiddler """ store = setup_store() setup_web() http = httplib2.Http() #make sure there is nothing in bag 'foo' bag = Bag('foo') bag = store.get(bag) assert len(bag.list_tiddlers()) == 0 response = http.request('http://test_domain:8001/bags/foo/tiddlers', method='POST', headers={'Content-type': 'application/x-www-form-urlencoded'}, body='title=HelloWorld&field1=foo&field2=bar')[0] assert response.status == 204 #now find the tiddler just entered tiddler = Tiddler('HelloWorld', 'foo') try: store.get(tiddler) except NoTiddlerError: raise AssertionError('tiddler was not put into store') #and check the fields assert tiddler.title == 'HelloWorld' assert len(tiddler.fields) == 2 assert tiddler.fields['field1'] == 'foo' assert tiddler.fields['field2'] == 'bar'
def test_list_tiddlers(): bag = Bag('bag1') bag = store.get(bag) tiddlers = bag.list_tiddlers() assert len(tiddlers) == 1 assert 'tiddler1' in [tiddler.title for tiddler in tiddlers]
def test_filter_by_text_string_negate(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = list(control.filter_tiddlers_from_bag(bag, 'select=text:!tiddler 0')) assert len(found_tiddlers) == 9
def test_filter_by_text_string_negate(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = control.filter_tiddlers_from_bag(bag, '[!text[tiddler 0]]') assert len(found_tiddlers) == 9
def test_filter_by_text(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = list(control.filter_tiddlers_from_bag(bag, 'select=text:tiddler 0')) assert len(found_tiddlers) == 1 assert found_tiddlers[0].title == 'tiddler0'
def play(): store = _store() store.list_bags() bag = Bag('ahosey') bag = store.get(bag) tiddlers = bag.list_tiddlers() print len(tiddlers) tiddler = store.get(tiddlers[5]) print tiddler.text
def test_filter_by_text_string(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = control.filter_tiddlers_from_bag(bag, '[text[tiddler 0]]') assert len(found_tiddlers) == 1 assert found_tiddlers[0].title == 'tiddler0'
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)
def test_simple_get(): tiddler = tiddlers[0] tiddler.bag = 'bagone' store.put(tiddler) bag = Bag(name='bagone') bag = store.get(bag) assert bag.list_tiddlers()[0].title == tiddler.title assert bag.list_tiddlers()[0].text == '' assert bag.list_tiddlers()[0].tags == [] assert bag.policy.read == bagone.policy.read assert bag.policy.write == bagone.policy.write assert bag.policy.create == bagone.policy.create assert bag.policy.delete == bagone.policy.delete assert bag.policy.manage == bagone.policy.manage assert bag.policy.owner == bagone.policy.owner assert bag.desc == 'I enjoy being stored' the_tiddler = bag.list_tiddlers()[0] the_tiddler = store.get(the_tiddler) assert the_tiddler.title == tiddler.title, 'stored tiddler title and retrieved tiddler.title the same' assert sorted(the_tiddler.tags) == sorted(tiddler.tags)
def make_basic_tw(self,bag): smallerbag = Bag("tmp",tmpbag=True) try: skinnybags = self.environ['tiddlyweb.config']['tiddlywebwikiplus']['skinny_bags'] except KeyError: skinnybags = [] for tiddler in bag.list_tiddlers(): if not tiddler.bag in skinnybags: smallerbag.add_tiddler(tiddler) else: if "_twp_skinny_include" in tiddler.fields: del tiddler.fields["_twp_skinny_include"] smallerbag.add_tiddler(tiddler) elif "root" in tiddler.fields and tiddler.fields["root"] in self.marked_tiddlers: smallerbag.add_tiddler(tiddler) return self._put_tiddlers_in_tiddlywiki(smallerbag.list_tiddlers())
def test_bag_get(): _cleanup() config = { "server_store": ["tiddlywebplugins.devstore", {"store_root": STORE_DIR}], "instance_tiddlers": {"myBag": ["%s/bravo/index.recipe" % REPO_DIR]}, "root_dir": "", } env = {"tiddlyweb.config": config} store = Storage(config["server_store"][1], env) bag = Bag("myBag") bag = store.bag_get(bag) assert bag.name == "myBag" actual = [tiddler.title for tiddler in bag.list_tiddlers()] expected = ["lorem", "foo", "SiteTitle", "ipsum", "bar"] assert set(actual) == set(expected) # XXX: sets as temporary workaround for dupes issue
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)
def imrsswithtags(args): """Import an rss feed into a bag and parse its words against tag words in bag2 or bag 3 to make tags <url> <bag> <bag2,bag3>""" rsstiddlers = tiddlers_from_rss(args[0]) bagname = args[1] tagbags = args[2].split(",") for tagbag in tagbags: bag = Bag(tagbag) store = get_store(config) bag = store.get(bag) tags = {} for tiddler in bag.list_tiddlers(): tiddler = store.get(tiddler) for tag in tiddler.tags: tags[tag.lower()] = True newtiddlers = [] for tiddler in rsstiddlers: description = tiddler.text newtags = [] for word in description.split(" "): try: if len(word) > 0 and (word[0:] == "#" or word[0] == "@" or word[0:1] == "L:"): #look for twitter keywords test = True word = word[1:] else: test = tags[word.lower()] tag = word.lower().strip("!").strip(".").strip(":") #print "Tag %s matches"%tag #print "appending %s"%tag if not tag in newtags: newtags.append(tag) except KeyError: pass tiddler.tags = newtags newtiddlers.append(tiddler) savetiddlerstobag(newtiddlers, bagname, overwrite=True)
def imrsswithtags(args): """Import an rss feed into a bag and parse its words against tag words in bag2 or bag 3 to make tags <url> <bag> <bag2,bag3>""" rsstiddlers = tiddlers_from_rss(args[0]) bagname = args[1] tagbags = args[2].split(",") for tagbag in tagbags: bag = Bag(tagbag) store = get_store(config) bag = store.get(bag) tags = {} for tiddler in bag.list_tiddlers(): tiddler = store.get(tiddler) for tag in tiddler.tags: tags[tag.lower()] = True newtiddlers = [] for tiddler in rsstiddlers: description = tiddler.text newtags = [] for word in description.split(" "): try: if len(word) > 0 and ( word[0:] == "#" or word[0] == "@" or word[0:1] == "L:" ): # look for twitter keywords test = True word = word[1:] else: test = tags[word.lower()] tag = word.lower().strip("!").strip(".").strip(":") # print "Tag %s matches"%tag # print "appending %s"%tag if not tag in newtags: newtags.append(tag) except KeyError: pass tiddler.tags = newtags newtiddlers.append(tiddler) savetiddlerstobag(newtiddlers, bagname, overwrite=True)
def faq(environ, start_response): store = environ['tiddlyweb.store'] bag = Bag(FAQ_BAG) bag = store.get(bag) tiddlers = [store.get(tiddler) for tiddler in bag.list_tiddlers()] categorical = {} for tiddler in tiddlers: tiddler.fields['url'] = tiddler_url(environ, tiddler) for tag in tiddler.tags: try: categorical[tag].append(tiddler) except KeyError: categorical[tag] = [tiddler] try: requested_category = environ['wsgiorg.routing_args'][1]['category'] all_tags = [requested_category] except KeyError: all_tags = categorical.keys() template = template_env.get_template('faqtop.html') return template.generate(categories=all_tags, info=categorical)
def faq(environ, start_response): store = environ['tiddlyweb.store'] bag = Bag(FAQ_BAG) bag = store.get(bag) tiddlers = [store.get(tiddler) for tiddler in bag.list_tiddlers()] categorical = {} for tiddler in tiddlers: tiddler.fields['url'] = tiddler_url(environ, tiddler) for tag in tiddler.tags: try: categorical[tag].append(tiddler) except KeyError: categorical[tag] = [tiddler] try: requested_category = environ['wsgiorg.routing_args'][1]['category'] all_tags = [requested_category] except KeyError: all_tags = categorical.keys() template = template_env.get_template('faqtop.html') return template.generate( categories=all_tags, info=categorical )
def test_simple_put(): """ put a tiddler to disk and make sure it is there. """ bagone = Bag('bagone') bagone.add_tiddlers(tiddlers) store.put(bagone) tiddler = bagone.list_tiddlers()[0] print tiddler.revision tiddler.tags = ['tagone', 'tagtwo', 'tag five'] tiddler.modified = '200803030303' store.put(tiddler) if type(store.storage) != Texter: py.test.skip('skipping this test for non-text store') assert os.path.exists(expected_stored_filename) f = file(expected_stored_filename) text = f.read() assert text == expected_stored_text
def form(environ, start_response): """ Produce this named form to the web. """ store = environ['tiddlyweb.store'] bag_id = environ['wsgiorg.routing_args'][1]['formid'] recipe_id, uuid = bag_id.rsplit('.', 1) logging.debug('getting form with bag %s using recipe %s' % (bag_id, recipe_id)) bag = store.get(Bag(bag_id)) _process_config_tiddler(store, bag) recipe = store.get(Recipe(recipe_id)) base_tiddlers = control.get_tiddlers_from_recipe(recipe) # read the bag (again) to make sure we have all the tiddlers bag = store.get(bag) data_tiddlers = bag.list_tiddlers() tiddlers = base_tiddlers + data_tiddlers tmp_bag = Bag('tmp', tmpbag=True) for tiddler in tiddlers: store.get(tiddler) tmp_bag.add_tiddler(tiddler) logging.debug(['%s:%s' % (tiddler.bag, tiddler.title) for tiddler in tmp_bag.list_tiddlers()]) environ['tiddlyweb.type'] = 'text/x-tiddlywiki' return send_tiddlers(environ, start_response, tmp_bag)