def test_in_a_recipe(): from tiddlyweb.config import config store = get_store(config) bag = Bag('hi') store.put(bag) tiddler = Tiddler('thing1', 'hi') tiddler.tags = ['research'] store.put(tiddler) tiddler = Tiddler('thing2', 'hi') store.put(tiddler) recipe1 = Recipe('oi') recipe1.set_recipe([('hi', 'mselect=tag:research')]) recipe1.store = store recipe2 = Recipe('coi') recipe2.set_recipe([('hi', 'select=tag:research')]) recipe2.store = store recipe3 = Recipe('boi') recipe3.set_recipe([('hi', '')]) recipe3.store = store environ = {'tiddlyweb.store': store} tiddlers = list(control.get_tiddlers_from_recipe(recipe1, environ)) assert len(tiddlers) == 1 tiddlers = list(control.get_tiddlers_from_recipe(recipe2, environ)) assert len(tiddlers) == 1 tiddlers = list(control.get_tiddlers_from_recipe(recipe3, environ)) assert len(tiddlers) == 2
def test_index_query_in_recipe(): config['indexer'] = 'test.indexernot' bag = Bag('noop') store.put(bag) tiddler = Tiddler('dwell', 'noop') store.put(tiddler) recipe = Recipe('coolio') recipe.set_recipe([('noop', u''), ('fwoop', u'')]) recipe.store = store tiddler = Tiddler('swell') py.test.raises(ImportError, 'determine_bag_from_recipe(recipe, tiddler, environ)') config['indexer'] = 'test.indexer' bag = determine_bag_from_recipe(recipe, tiddler, environ) assert bag.name == 'fwoop' tiddler = Tiddler('dwell') bag = determine_bag_from_recipe(recipe, tiddler, environ) assert bag.name == 'noop' tiddler = Tiddler('carnaby') # nowhere py.test.raises(NoBagError, 'determine_bag_from_recipe(recipe, tiddler, environ)')
def test_index_query_in_recipe(): config['indexer'] = 'test.indexernot' bag = Bag('noop') store.put(bag) tiddler = Tiddler('dwell', 'noop') store.put(tiddler) recipe = Recipe('coolio') recipe.set_recipe([('noop', ''), ('fwoop', '')]) recipe.store = store tiddler = Tiddler('swell') py.test.raises(ImportError, 'determine_bag_from_recipe(recipe, tiddler, environ)') config['indexer'] = 'test.indexer' bag = determine_bag_from_recipe(recipe, tiddler, environ) assert bag.name == 'fwoop' tiddler = Tiddler('dwell') bag = determine_bag_from_recipe(recipe, tiddler, environ) assert bag.name == 'noop' tiddler = Tiddler('carnaby') # nowhere py.test.raises(NoBagError, 'determine_bag_from_recipe(recipe, tiddler, environ)')
def test_in_a_recipe(): bag = Bag('hi') store.put(bag) tiddler = Tiddler('thing1', 'hi') tiddler.tags = ['research'] store.put(tiddler) tiddler = Tiddler('thing2', 'hi') store.put(tiddler) recipe1 = Recipe('oi') recipe1.set_recipe([('hi', 'select=tag:research')]) recipe1.store = store recipe2 = Recipe('boi') recipe2.set_recipe([('hi', '')]) recipe2.store = store environ = {'tiddlyweb.store': store} tiddlers = list(control.get_tiddlers_from_recipe(recipe1, environ)) assert len(tiddlers) == 1 tiddlers = list(control.get_tiddlers_from_recipe(recipe2, environ)) assert len(tiddlers) == 2
def test_bag_object_in_recipe(): bag = Bag('fwoop') store.put(bag) tiddler = Tiddler('swell', 'fwoop') tiddler.text = 'hi' store.put(tiddler) recipe = Recipe('heyo') recipe.set_recipe([(bag, '')]) recipe.store = store tiddlers = list(get_tiddlers_from_recipe(recipe, environ)) assert len(tiddlers) == 1 assert tiddlers[0].title == 'swell' assert tiddlers[0].bag == 'fwoop'
def test_bag_object_in_recipe(): bag = Bag('fwoop') store.put(bag) tiddler = Tiddler('swell', 'fwoop') tiddler.text = 'hi' store.put(tiddler) recipe = Recipe('heyo') recipe.set_recipe([(bag, '')]) recipe.store = store tiddlers = list(get_tiddlers_from_recipe(recipe, environ)) assert len(tiddlers) == 1 assert tiddlers[0].title == 'swell' assert tiddlers[0].bag == 'fwoop'
def user_page(environ, start_response): print(environ) name = environ['wsgiorg.routing_args'][1].get('name', 'default') recipe = Recipe('tmp') recipe.set_recipe([ [name, ''] ]) # establish the store on the recipe so that get_tiddlers_from_recipe # will load the bags and their tiddler lists from the store recipe.store = environ['tiddlyweb.store'] tiddlers = control.get_tiddlers_from_recipe(recipe, environ) bag = Bag('tmp', tmpbag=True) bag.add_tiddlers(tiddlers) return send_tiddlers(environ, start_response, bag)
def dyna(environ, start_response): name = environ['wsgiorg.routing_args'][1].get('name', 'default') username = environ['tiddlyweb.usersign']['name'] recipe = Recipe('tmp') recipe.set_recipe([ [BASE_BAG_NAME, ''], [name, ''], [username, ''] ]) # establish the store on the recipe so that get_tiddlers_from_recipe # will load the bags and their tiddler lists from the store recipe.store = environ['tiddlyweb.store'] tiddlers = control.get_tiddlers_from_recipe(recipe, environ) bag = Bag('tmp', tmpbag=True) bag.add_tiddlers(tiddlers) return send_tiddlers(environ, start_response, bag)
def test_recipe_with_special(): recipe = Recipe('special') recipe.set_recipe([('normal', ''), ('Xnine', '')]) recipe.store = store tiddlers = list(get_tiddlers_from_recipe(recipe, environ)) assert len(tiddlers) == 4 assert 'thing' in [tiddler.title for tiddler in tiddlers] assert 'alpha' in [tiddler.title for tiddler in tiddlers] assert 'beta' in [tiddler.title for tiddler in tiddlers] assert 'gamma' in [tiddler.title for tiddler in tiddlers] # roundtrip the recipes with a special store.put(recipe) recipe2 = store.get(Recipe('special')) assert recipe.get_recipe() == recipe2.get_recipe()
def test_recipe_with_special(): recipe = Recipe('special') recipe.set_recipe([ ('normal', ''), ('Xnine', '')]) recipe.store = store tiddlers = list(get_tiddlers_from_recipe(recipe, environ)) assert len(tiddlers) == 4 assert 'thing' in [tiddler.title for tiddler in tiddlers] assert 'alpha' in [tiddler.title for tiddler in tiddlers] assert 'beta' in [tiddler.title for tiddler in tiddlers] assert 'gamma' in [tiddler.title for tiddler in tiddlers] # roundtrip the recipes with a special store.put(recipe) recipe2 = store.get(Recipe('special')) assert recipe.get_recipe() == recipe2.get_recipe()
def test_list_recipe_tiddlers(): bag = Bag('alpha') STORE.put(bag) recipe = Recipe('omega') recipe.set_recipe([('alpha', '')]) recipe.store = STORE STORE.put(recipe) for title in ['Foo', 'Bar', 'Baz']: tiddler = Tiddler(title, bag.name) STORE.put(tiddler) initialize_app(STORE.environ['tiddlyweb.config']) http = httplib2.Http() response, content = (http. request('http://example.org:8001/recipes/omega/tiddlers.json', method='GET')) for tiddler in json.loads(content): assert tiddler["recipe"] == recipe.name
def create_dynamic_recipe(environ,recipeDefinition): recipe = Recipe('myRecipe') recipe.set_recipe(recipeDefinition) recipe.store = environ['tiddlyweb.store'] return recipe
def create_dynamic_recipe(environ, recipeDefinition): recipe = Recipe("myRecipe") logging.debug("havaz a %s" % recipeDefinition) recipe.set_recipe(recipeDefinition) recipe.store = environ["tiddlyweb.store"] return recipe