Ejemplo n.º 1
0
def test_get_recipe_list_templated_bag():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ user }}', '')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][0] == 'testuser'
Ejemplo n.º 2
0
def test_get_recipe_list_templated_filter2():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('system', 'modifier={{ user }};creator={{ user }}')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][1] == 'modifier=testuser;creator=testuser'
Ejemplo n.º 3
0
def test_put_recipe():
    recipe = Recipe('cookies')
    recipe.set_recipe(recipe_list)

    store.put(recipe)

    assert os.path.exists('store/recipes/cookies')
Ejemplo n.º 4
0
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)')
Ejemplo n.º 5
0
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)')
Ejemplo n.º 6
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.º 7
0
def _create_recipe(environ):
    """Take the form input and turn it into a recipe."""
    # get bag_names before we flatten because it will be a list
    bag_names = environ['tiddlyweb.query'].get('bags', [])
    query_data = _flatten_form_data(environ['tiddlyweb.query'])
    store = environ['tiddlyweb.store']
    try:
        new_recipe_name = query_data['recipe_name']

        if _recipe_exists(store, new_recipe_name):
            raise HTTP409('That recipe may not be created.')

        new_recipe = Recipe(new_recipe_name)

        username = environ['tiddlyweb.usersign']['name']
        new_recipe.policy.owner = username
        new_recipe.policy.manage = [username]
        new_recipe.desc = query_data.get('recipe_desc', '')

        privacy = query_data['privacy']
        new_recipe.policy.read = _policy_form_to_entry(username, privacy)

        bag_list = []

        if query_data.get('autowiki', 0):
            bag_list.extend(AUTOWIKI_BAGS)

        # don't worry about default content bag yet
        bag_list.extend(bag_names)
        recipe_list = [[bag_name, ''] for bag_name in bag_list]
        new_recipe.set_recipe(recipe_list)

        store.put(new_recipe)
    except KeyError, exc:
        raise HTTP400('something went wrong processing for: %s' % exc)
Ejemplo n.º 8
0
def setup_module(module):

    module.store = get_store(config)

    # cascade to deal with differently named files depending on 
    # anydbm impelementation
    try:
        os.unlink('links.db')
    except OSError:
        pass  # not there
    module.links_manager = LinksManager()

    try:
        shutil.rmtree('store')
    except:
        pass
    
    def app():
        return serve.load_app()
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app)

    # for @someone syntax to test correctly we need a corresponding
    # recipe
    module.store.put(Bag('cdent_public'))
    recipe = Recipe('cdent_public')
    recipe.set_recipe([('cdent_public', '')])
    module.store.put(recipe)
Ejemplo n.º 9
0
def make_fake_space(store, name):
    def set_policy(policy, private=False):
        for policy_attr in policy.attributes:
            if policy_attr not in ['read', 'owner']:
                setattr(policy, policy_attr, [name])
        if private:
            policy.read = [name]

    public_recipe = Recipe('%s_public' % name)
    private_recipe = Recipe('%s_private' % name)
    public_bag = Bag('%s_public' % name)
    private_bag = Bag('%s_private' % name)
    archive_bag = Bag('%s_archive' % name)
    set_policy(public_recipe.policy)
    set_policy(private_recipe.policy, private=True)
    set_policy(public_bag.policy)
    set_policy(private_bag.policy, private=True)
    set_policy(archive_bag.policy, private=True)
    public_recipe.set_recipe([('system', ''), ('tiddlyspace', ''),
                              ('%s_public' % name, '')])
    private_recipe.set_recipe([('system', ''), ('tiddlyspace', ''),
                               ('%s_public' % name, ''),
                               ('%s_private' % name, '')])
    for entity in [
            public_recipe, private_recipe, public_bag, private_bag, archive_bag
    ]:
        store.put(entity)
Ejemplo n.º 10
0
def test_determine_tiddler_from_recipe():
    """
    Work out what bag a provided tiddler is in, when we have no knowledge of the bag,
    but we do have a recipe.
    """
    short_recipe = Recipe(name='foobar')
    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagone']
        ])
    bag = control.determine_tiddler_bag_from_recipe(short_recipe, tiddlers[0])
    assert bag.name == bagfour.name, 'bag name should be bagfour, is %s' % bag.name

    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagthree']
        ])
    bag = control.determine_tiddler_bag_from_recipe(short_recipe, tiddlers[0])
    assert bag.name == bagone.name, 'bag name should be bagone, is %s' % bag.name

    lonely_tiddler = Tiddler('lonely')
    lonely_tiddler.bag = 'lonelybag'

    py.test.raises(NoBagError,
            'bag = control.determine_tiddler_bag_from_recipe(short_recipe, lonely_tiddler)')
def test_recipe_variables():
    """
    access a recipe with variables in it
    """
    store = setup_store()
    url(['/foo/{name:segment}', '/recipes/custom/tiddlers'])
    urls_init(config)
    setup_web()
    http = httplib2.Http()

    tiddler = Tiddler('bar', 'foo')
    tiddler.text = 'foo bar'
    store.put(tiddler)

    recipe = Recipe('custom')
    recipe.set_recipe([('{{ name:bar }}', '')])
    store.put(recipe)

    response, content = http.request('http://test_domain:8001/foo/foo')

    assert response.status == 200

    direct_url = http.request('http://test_domain:8001/recipes/custom/tiddlers')[1]
    assert content != direct_url #accessing directly, the default bag should be used instead

    #now check that the correct bag was actually loaded)
    recipe.set_recipe([('foo', '')])
    store.put(recipe)
    direct_url = http.request('http://test_domain:8001/recipes/custom/tiddlers')[1]
    assert content == direct_url
Ejemplo n.º 12
0
def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    info_tiddler = Tiddler('SiteInfo', space.public_bag())
    info_tiddler.text = 'Space %s' % space_name
    store.put(info_tiddler)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Ejemplo n.º 13
0
def test_json_recipe():
    """
    JSON serializer roundtrips.
    """
    recipe = Recipe('other')
    recipe.set_recipe([['bagbuzz', '']])
    recipe.policy.manage = ['a']
    recipe.policy.read = ['b']
    recipe.policy.create = ['c']
    recipe.policy.delete = ['d']
    recipe.policy.owner = 'e'
    serializer = Serializer('json')
    serializer.object = recipe
    string = serializer.to_string()

    other_recipe = Recipe('other')
    serializer.object = other_recipe
    serializer.from_string(string)

    assert recipe == other_recipe

    serializer.object = other_recipe
    other_string = serializer.to_string()

    assert string == other_string
def test_unicode_in_recipes():
    """
    visit a recipe passing unicode in as one of the variables
    """
    store = setup_store()
    url(['/foo/{bar:segment}', '/recipes/custom/tiddlers'])
    urls_init(config)
    setup_web()
    http = httplib2.Http()

    bag = Bag(u'unicodeø•º∆∆˙ª')
    store.put(bag)
    tiddler = Tiddler(u'bar œ∑´®†¥', u'unicodeø•º∆∆˙ª')
    tiddler.text = 'foo bar'
    store.put(tiddler)

    recipe = Recipe('custom')
    recipe.set_recipe([('{{ bar:foo }}', '')])
    store.put(recipe)

    response, content = http.request('http://test_domain:8001/foo/unicodeø•º∆∆˙ª')

    assert response.status == 200

    direct_url = http.request(u'http://test_domain:8001/recipes/custom/tiddlers')[1]
    assert content != direct_url #direct_url should load the foo bag instead

    recipe.set_recipe([(u'unicodeø•º∆∆˙ª', '')])
    store.put(recipe)
    direct_url = http.request(u'http://test_domain:8001/recipes/custom/tiddlers')[1]
    assert content == direct_url
Ejemplo n.º 15
0
def test_get_recipe_list_templated_bag():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ user }}', '')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][0] == 'testuser'
Ejemplo n.º 16
0
    def _init_store(self, struct):
        """
        creates basic store structure with bags, recipes and users

        (no support for user passwords for security reasons)
        """
        store = get_store(self.init_config)

        bags = struct.get("bags", {})
        for name, data in bags.items():
            desc = data.get("desc")
            bag = Bag(name, desc=desc)
            constraints = data.get("policy", {})
            _set_policy(bag, constraints)
            store.put(bag)

        recipes = struct.get("recipes", {})
        for name, data in recipes.items():  # TODO: DRY
            desc = data.get("desc")
            recipe = Recipe(name, desc=desc)
            recipe.set_recipe(data["recipe"])
            constraints = data.get("policy", {})
            _set_policy(recipe, constraints)
            store.put(recipe)

        users = struct.get("users", {})
        for name, data in users.items():
            note = data.get("note")
            user = User(name, note=note)
            password = data.get("_password")
            if password:
                user.set_password(password)
            for role in data.get("roles", []):
                user.add_role(role)
            store.put(user)
Ejemplo n.º 17
0
def test_get_recipe_list_templated_filter2():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('system', 'modifier={{ user }};creator={{ user }}')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][1] == 'modifier=testuser;creator=testuser'
Ejemplo n.º 18
0
def setup_store():
    """
    initialise a blank store, and fill it with some data
    """
    store = get_store(config)
    for bag in BAGS:
        bag = Bag(bag)
        try:
            store.delete(bag)
        except NoBagError:
            pass
        
        store.put(bag)
    
    for recipe, contents in RECIPES.iteritems():
        recipe = Recipe(recipe)
        try:
            store.delete(recipe)
        except NoRecipeError:
            pass
        
        recipe.set_recipe(contents)
        store.put(recipe)
        
    return store
Ejemplo n.º 19
0
def test_put_recipe():
    recipe = Recipe('cookies')
    recipe.set_recipe(recipe_list)

    store.put(recipe)

    assert os.path.exists('store/recipes/cookies')
Ejemplo n.º 20
0
def _make_space(environ, space_name):
    """
    The details of creating the bags and recipes that make up a space.
    """
    store = environ['tiddlyweb.store']
    member = environ['tiddlyweb.usersign']['name']

    # XXX stub out the clumsy way for now
    # can make this much more declarative

    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
Ejemplo n.º 21
0
def _create_recipe(environ):
    """Take the form input and turn it into a recipe."""
    # get bag_names before we flatten because it will be a list
    bag_names = environ['tiddlyweb.query'].get('bags', [])
    query_data = _flatten_form_data(environ['tiddlyweb.query'])
    store = environ['tiddlyweb.store']
    try:
        new_recipe_name = query_data['recipe_name']

        if _recipe_exists(store, new_recipe_name):
            raise HTTP409('That recipe may not be created.')

        new_recipe = Recipe(new_recipe_name)

        username = environ['tiddlyweb.usersign']['name']
        new_recipe.policy.owner = username
        new_recipe.policy.manage = [username]
        new_recipe.desc = query_data.get('recipe_desc', '')

        privacy = query_data['privacy']
        new_recipe.policy.read = _policy_form_to_entry(username, privacy)

        bag_list = []

        if query_data.get('autowiki', 0):
            bag_list.extend(AUTOWIKI_BAGS)

        # don't worry about default content bag yet
        bag_list.extend(bag_names)
        recipe_list = [[bag_name, ''] for bag_name in bag_list]
        new_recipe.set_recipe(recipe_list)

        store.put(new_recipe)
    except KeyError, exc:
        raise HTTP400('something went wrong processing for: %s' % exc)
Ejemplo n.º 22
0
def _make_space(environ, space_name):
    """
    The details of creating the bags and recipes that make up a space.
    """
    store = environ['tiddlyweb.store']
    member = environ['tiddlyweb.usersign']['name']

    # XXX stub out the clumsy way for now
    # can make this much more declarative

    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)
def setup_module(module):
    try:
        shutil.rmtree('store')
    except:
        pass
    config['markdown.wiki_link_base'] = ''
    store = get_store(config)

    environ['tiddlyweb.store'] = store

    store.put(Bag('bag'))
    module.store = store

    recipe = Recipe('recipe_public')
    recipe.set_recipe([('bag', '')])
    store.put(recipe)

    tiddlerA = Tiddler('tiddler a', 'bag')
    tiddlerA.text = 'I am _tiddler_'
    store.put(tiddlerA)

    tiddlerB = Tiddler('tiddler b')
    tiddlerB.text = '''
You wish

{{tiddler a}}

And I wish too.
'''
    module.tiddlerB = tiddlerB
Ejemplo n.º 24
0
def test_get_recipe_list_templated_bag_filter():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ bagname }}', 'modifier={{ user }}')
        ])
    list = recipe.get_recipe({'user': '******', 'bagname': 'foobar'})
    assert list[0][1] == 'modifier=testuser'
    assert list[0][0] == 'foobar'
Ejemplo n.º 25
0
def test_get_recipe_list_templated_bag_filter():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ bagname }}', 'modifier={{ user }}')
        ])
    list = recipe.get_recipe({'user': '******', 'bagname': 'foobar'})
    assert list[0][1] == 'modifier=testuser'
    assert list[0][0] == 'foobar'
Ejemplo n.º 26
0
def test_get_recipe_list_templated_bag_filter_defaulted_bag():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ bagname:common }}', 'modifier={{ user }}')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][1] == 'modifier=testuser'
    assert list[0][0] == 'common'
Ejemplo n.º 27
0
def test_get_recipe_list_templated_bag_filter_defaulted_bag():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ bagname:common }}', 'modifier={{ user }}')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][1] == 'modifier=testuser'
    assert list[0][0] == 'common'
Ejemplo n.º 28
0
def ensure_public_recipe(store, username):
    name = "%s-public" % username
    recipe = Recipe(name)
    recipe.policy.read = []
    recipe.policy.manage = [username]
    recipe.policy.owner = username
    recipe.set_recipe([("system", ""), (name, "")])
    store.put(recipe)
Ejemplo n.º 29
0
def test_recipe_bad_filter_400():
    recipe = Recipe("badfilter")
    recipe.desc = u"hello"
    recipe.set_recipe([("bag8", "select=error:5")])
    store.put(recipe)

    http = httplib2.Http()
    response, content = http.request("http://our_test_domain:8001/recipes/badfilter/tiddlers")
    assert response["status"] == "400", content
Ejemplo n.º 30
0
def test_recipe_bad_filter_400():
    recipe = Recipe('badfilter')
    recipe.desc = u'hello'
    recipe.set_recipe([('bag8', 'select=error:5')])
    store.put(recipe)

    response, content = http.requestU(
            'http://our_test_domain:8001/recipes/badfilter/tiddlers')
    assert response['status'] == '400', content
Ejemplo n.º 31
0
def setup_module(module):
    initialize_app()
    reset_textstore()
    module.store = _teststore()

    for i in xrange(5):
        recipe = Recipe('recipe%s' % i)
        recipe.set_recipe([('monkey', '')])
        module.store.put(recipe)
def test_get_serializations_recipe():

    assert len(serialization._matches('recipe_as')) == 3

    recipe = Recipe('hello')
    recipe.set_recipe([('barney', '')])

    output = serialization.recipe_as(recipe)
    assert 'tiddlyweb.serializations.json' in ''.join(list(output))
Ejemplo n.º 33
0
def test_recipe_bad_filter_400():
    recipe = Recipe('badfilter')
    recipe.desc = u'hello'
    recipe.set_recipe([('bag8', 'select=error:5')])
    store.put(recipe)

    response, content = http.requestU(
        'http://our_test_domain:8001/recipes/badfilter/tiddlers')
    assert response['status'] == '400', content
Ejemplo n.º 34
0
def test_recipe_weird_bag():
    recipe = Recipe("weirdbags")
    recipe.set_recipe([("foo/bar", ""), ("zam/boom", "")])
    store.put(recipe)

    new_recipe = Recipe("weirdbags")
    new_recipe = store.get(new_recipe)
    bags = [bag for bag, filter in new_recipe.get_recipe()]
    assert bags == ["foo/bar", "zam/boom"]
Ejemplo n.º 35
0
def setup_module(module):
    initialize_app()
    reset_textstore()
    module.store = _teststore()

    for i in xrange(5):
        recipe = Recipe('recipe%s' % i)
        recipe.set_recipe([('monkey', '')])
        module.store.put(recipe)
def test_get_remote_weird():
    recipe = Recipe('stuff')
    recipe.set_recipe([(REMOTE_HTML, '')])
    store.put(recipe)

    tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    assert len(tiddlers) == 1
    assert tiddlers[0].title == 'The Computer as Tool: From Interaction To Augmentation'
    tiddler = store.get(tiddlers[0])
    assert 'Humans are likely to grant intention to someone or something that performs actions in a way that is difficult to understand.' in tiddler.text
Ejemplo n.º 37
0
def test_with_customisations():
  clear_store()
  atoms = {"bag":"notfoo","revision":1,"title":"AtomSettings","fields":{},"tags":['excludeAtom'],"text":u'''!recipes/friends
feed.title:Jons Wacky Atom Feed
feed.link:http://tiddlyweb.com/foo

!bags/foo
entry.title:<<echo gtitle>>
entry.link:/posts/<<echo "file.html">>
entry.id:bar

!bags/pooh
entry.title:a tiddler from pooh
entry.content:winnie the pooh

!recipes/friends
entry.content:hello world content Cà Phê VN
'''}
  tid1 = {"bag":"foo","revision":1,"title":"Tiddler1","fields":{},"tags":[],"text":"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."}
  tid2 = {"bag":"notfoo","revision":1,"title":"Tiddler2","fields":{},"tags":[],"text":"Magic"}
  tid3 = {"bag":"foo","revision":1,"title":"Tiddler3","fields":{},"tags":[],"text":"Hello"}
  tid4 = {"bag":"pooh","revision":1,"title":"Tigger","fields":{},"tags":[],"text":"Rabbit"} 
  store.put(Bag("notfoo"))
  store.put(Bag("foo"))
  r =Recipe("friends")
  r.set_recipe([['foo',''],['notfoo','']])
  store.put(r)
  atid =Tiddler(atoms['title'],atoms['bag'])
  atid.text = atoms['text']
  store.put(atid)
  newconfig = config
  newconfig['server_prefix']='stuff'
  newconfig['server_host']={'scheme':'http','host':'friends.com'}
  s = NewAtom({'tiddlyweb.store':store,'selector.vars':{'recipe_name':'friends'},'SCRIPT_URI':'/feeds','tiddlyweb.config':newconfig})
  text = s.dump([tid1,tid2,tid3,tid4,atoms],'list')
  
  print "#############"
  print text
  print "#############"
  assert '<title>Jons Wacky Atom Feed</title>' in text
  assert '<title>Tiddler2' in text
  assert '<link rel="alternate" type="text/html" href="http://friends.com/stuff/recipes/friends/tiddlers/Tiddler2"/>' in text
  assert '<title>gtitle</title>' in text
  assert '<link rel="alternate" type="text/html" href="http://friends.com/posts/file.html"/>' in text
  assert '<title>AtomSettings</title>' not in text
  assert u'hello world content Cà Phê VN' in text
  assert '<id>bar</id>' in text
  assert 'a tiddler from pooh</title>' in text
  assert 'Rabbit' not in text
  assert 'Tigger</title>' not in text
  assert 'winnie the pooh' not in text
  
  s.environ['selector.vars'] = {'bag_name':'notfoo'}
  newtext = s.dump([tid2,atoms],'list')
  assert 'hello world content' not in newtext
def test_get_recipe_filters():
    recipe = Recipe('thing')
    recipe.set_recipe([(REMOTE_BAG, 'select=tag:alpha')])
    store.put(recipe)

    tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    assert len(tiddlers) == 1
    assert tiddlers[0].title == 'alpha'

    assert tiddlers[0].bag == REMOTE_BAG
    assert tiddlers[0].text == 'alpha'
Ejemplo n.º 39
0
def ensure_public_recipe(store, username):
    name = '%s-public' % username
    recipe = Recipe(name)
    recipe.policy.read = []
    recipe.policy.manage = [username]
    recipe.policy.owner = username
    recipe.set_recipe([
        ('system', ''),
        (name, ''),
    ])
    store.put(recipe)
Ejemplo n.º 40
0
def ensure_public_recipe(store, username):
    name = '%s-public' % username
    recipe = Recipe(name)
    recipe.policy.read = []
    recipe.policy.manage = [username]
    recipe.policy.owner = username
    recipe.set_recipe([
        ('system', ''),
        (name, ''),
    ])
    store.put(recipe)
Ejemplo n.º 41
0
def test_get_tiddlers_limited():
    """
    Using a different recipe get different tiddlers.
    """

    short_recipe = Recipe(name='foobar')
    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagone']
        ])
    tiddlers = control.get_tiddlers_from_recipe(short_recipe)
    assert len(tiddlers) == 2, 'tiddler list should be length 2, is %s' % len(tiddlers)
Ejemplo n.º 42
0
def test_get_recipe():
    recipe = Recipe('templated')
    recipe.set_recipe([('common', 'select=topic:{{ id:default }}'),
                       ('{{ user }}', ''), ('system', '')])

    stuff = recipe.get_recipe()
    assert stuff[0][1] == 'select=topic:{{ id:default }}'
    assert stuff[1][0] == '{{ user }}'

    filled = recipe.get_recipe(recipe_template(environ))
    assert filled[0][1] == 'select=topic:default'
    assert filled[1][0] == 'JohnSmith'
Ejemplo n.º 43
0
    def create_recipe(self, name, recipe_contents, policy=None, desc=None):
        """
        create a recipe
        """
        recipe = Recipe(name)

        if self.exists(recipe):
            raise RecipeExistsError('%s already exists' % name)

        recipe.set_recipe(recipe_contents)

        self._put_thing(recipe, policy, desc)
Ejemplo n.º 44
0
def test_recipe_weird_bag():
    recipe = Recipe('weirdbags')
    recipe.set_recipe([
        ('foo/bar', ''),
        ('zam/boom', ''),
        ])
    store.put(recipe)

    new_recipe = Recipe('weirdbags')
    new_recipe = store.get(new_recipe)
    bags = [bag for bag,filter in new_recipe.get_recipe()]
    assert bags == ['foo/bar', 'zam/boom']
Ejemplo n.º 45
0
def test_store_recipe():
    recipe = Recipe('recipe1')
    recipe.desc = 'recipe 1 desc'
    recipe.set_recipe([['bag1', '']])

    store.put(recipe)

    assert os.path.exists('store/recipe1.recipe')

    loaded_recipe = Recipe('recipe1')
    loaded_recipe = store.get(loaded_recipe)
    assert loaded_recipe.desc == recipe.desc
Ejemplo n.º 46
0
def test_recipe_weird_bag():
    recipe = Recipe('weirdbags')
    recipe.set_recipe([
        ('foo/bar', ''),
        ('zam/boom', ''),
    ])
    store.put(recipe)

    new_recipe = Recipe('weirdbags')
    new_recipe = store.get(new_recipe)
    bags = [bag for bag, filter in new_recipe.get_recipe()]
    assert bags == ['foo/bar', 'zam/boom']
Ejemplo n.º 47
0
def setup_module(module):
    try:
        shutil.rmtree('store')
    except:
        pass
    module.store = get_store(config)
    init(config)
    base_recipe = Recipe('hi')
    base_recipe.set_recipe([('system', ''), ('stuff', 'select=title:monkey'),
                            ('things', '')])
    module.store.put(base_recipe)
    sys.exit = boring_exit
Ejemplo n.º 48
0
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'
Ejemplo n.º 49
0
def test_recipe_put():
    """
    put a recipe to disk and make sure it is there.
    """

    recipe = Recipe('testrecipe')
    recipe.desc = 'I enjoy being stored'
    recipe.set_recipe(recipe_list_string)
    store.put(recipe)

    if type(store.storage) != tiddlyweb.stores.text.Store:
        py.test.skip('skipping this test for non-text store')

    assert os.path.exists(expected_stored_filename)
Ejemplo n.º 50
0
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)
Ejemplo n.º 51
0
def test_determine_bag_for_tiddler():
    recipe = Recipe('example')
    recipe.set_recipe([('bagone', ''), ('bagtwo', 'select=title:monkey')])

    tiddler = Tiddler('happy')

    bag = determine_bag_for_tiddler(recipe, tiddler)
    assert bag.name == 'bagone'

    tiddler = Tiddler('monkey')
    bag = determine_bag_for_tiddler(recipe, tiddler)
    assert bag.name == 'bagtwo'

    recipe.set_recipe([('bagone', 'select=tag:foo'),
                       ('bagtwo', 'select=title:monkeys')])

    py.test.raises(NoBagError, 'determine_bag_for_tiddler(recipe, tiddler)')
Ejemplo n.º 52
0
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()
Ejemplo n.º 53
0
def muchdata(store):
    for bag_numeral in range(30):
        bag = create_bag(store, bag_numeral)
        for tiddler_numeral in range(10):
            tiddler = create_tiddler(store, bag, tiddler_numeral)

    recipe = Recipe('long')

    recipe_list = [(u'bag1', '')]
    for numeral in range(0, 30, 2):
        bag_name = u'bag%s' % numeral
        filter_string = u'select=title:tiddler%s' % (numeral % 10)
        if not (numeral % 10) % 3:
            filter_string = filter_string + u';select=tag:tag three'
        recipe_list.append([bag_name, filter_string])
    recipe.set_recipe(recipe_list)

    store.put(recipe)
Ejemplo n.º 54
0
def post_createrecipe(environ, start_response):
    user = get_user_object(environ)
    store = environ['tiddlyweb.store']
    recipe_name = environ['tiddlyweb.query'].get('recipe', [''])[0]
    bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    publicity = environ['tiddlyweb.query'].get('publicity', [''])[0]
    description = environ['tiddlyweb.query'].get('description', [''])[0]
    if not bag_name or not recipe_name:
        raise HTTP400('missing data')

    recipe = Recipe(recipe_name)
    bag = Bag(bag_name)
    try:
        recipe = store.get(recipe)
        raise HTTP400('recipe exists')
    except NoRecipeError:
        pass

    try:
        bag = store.get(bag)
        try:
            bag.policy.allows(user, 'read')
        except (UserRequiredError, ForbiddenError):
            raise HTTP400('bag not readable')
    except NoBagError:
        bag.policy.owner = user['name']
        for constraint in ['read', 'write', 'create', 'delete', 'manage']:
            setattr(bag.policy, constraint, [user['name']])
        store.put(bag)

    if publicity == 'private':
        recipe.policy.read = [user['name']]
    else:
        recipe.policy.read = []
    recipe.policy.manage = [user['name']]
    recipe.policy.owner = user['name']
    recipe.desc = description
    recipe.set_recipe([
        ('system', ''),
        (bag.name, ''),
    ])
    store.put(recipe)

    raise HTTP303('%s/home' % server_base_url(environ))
Ejemplo n.º 55
0
def test_recipe_put():
    """
    put a recipe to disk and make sure it is there.
    """

    recipe = Recipe('testrecipe')
    recipe.desc = 'I enjoy being stored'
    recipe.set_recipe(recipe_list_string)
    store.put(recipe)

    if type(store.storage) != tiddlyweb.stores.text.Store:
        py.test.skip('skipping this test for non-text store')

    assert os.path.exists(expected_stored_filename)

    with open(expected_stored_filename) as f:
        content = f.read()

    if sys.version_info[0] < 3:
        assert content == expected_stored_content
Ejemplo n.º 56
0
def _check_recipe(name, environ, user):
    """
    Get the user's recipes, create them if required.
    """
    store = environ['tiddlyweb.store']

    recipe_name = '%s-%s' % (user, name)
    recipe_name = recipe_name.replace('.', '_')
    try:
        recipe = Recipe(recipe_name)
        recipe = store.get(recipe)
    except NoRecipeError:
        bag = _check_bag('all', environ, user)
        recipe.set_recipe([
            [u'TiddlyWeb', u''],
            [unicode(bag.name), unicode(_filter_string(name))],
            ])
        recipe.desc = '%s twotes for %s' % (name, user)
        store.put(recipe)
    return recipe
Ejemplo n.º 57
0
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
Ejemplo n.º 58
0
def test_simple_recipe():
    recipe = Recipe('other')
    recipe.set_recipe([('bagbuzz', '')])
    recipe.policy.manage = ['a']
    recipe.policy.read = ['b']
    recipe.policy.create = ['c']
    recipe.policy.delete = ['d']
    recipe.policy.owner = 'e'
    serializer = Serializer('text')
    serializer.object = recipe
    string = serializer.to_string()

    new_recipe = Recipe('other')
    serializer.object = new_recipe
    serializer.from_string(string)

    assert recipe == new_recipe, 'recipe and new_recipe have equality'

    recipe = Recipe('other')
    recipe.set_recipe([('bagboom', '')])
    assert recipe != new_recipe, 'modified recipe not equal new_recipe'
Ejemplo n.º 59
0
def test_put_tiddler_recipe_with_filter():
    recipe = Recipe('recipe1')
    bag1 = Bag('bag1')
    bag2 = Bag('bag2')
    recipe.set_recipe([('bag1', ''), ('bag2', 'select=tag:foo')])
    store.put(bag1)
    store.put(bag2)
    store.put(recipe)

    tiddler_json_one = simplejson.dumps(dict(text='hello', tags=[]))
    tiddler_json_two = simplejson.dumps(dict(text='hello', tags=['foo']))

    http = httplib2.Http()
    response, content = http.request(
        'http://our_test_domain:8001/recipes/recipe1/tiddlers/tiddler_one',
        headers={'Content-Type': 'application/json'},
        method='PUT',
        body=tiddler_json_one)
    assert response['status'] == '204'
    assert 'bag1' in response['etag']

    response, content = http.request(
        'http://our_test_domain:8001/recipes/recipe1/tiddlers/tiddler_two',
        headers={'Content-Type': 'application/json'},
        method='PUT',
        body=tiddler_json_two)
    assert response['status'] == '204'
    assert 'bag2' in response['etag']

    tiddler = Tiddler('tiddler_three', 'bag2')
    tiddler.tags = ['foo']
    store.put(tiddler)

    response, content = http.request(
        'http://our_test_domain:8001/recipes/recipe1/tiddlers/tiddler_two',
        headers={'Content-Type': 'application/json'},
        method='PUT',
        body=tiddler_json_two)
    assert response['status'] == '204'
    assert 'bag2' in response['etag']
Ejemplo n.º 60
0
def make_space(space_name, store, member):
    """
    The details of creating the bags and recipes that make up a space.
    """
    space = Space(space_name)

    for bag_name in space.list_bags():
        bag = Bag(bag_name)
        bag.policy = _make_policy(member)
        if Space.bag_is_public(bag_name):
            bag.policy.read = []
        store.put(bag)

    public_recipe = Recipe(space.public_recipe())
    public_recipe.set_recipe(space.public_recipe_list())
    private_recipe = Recipe(space.private_recipe())
    private_recipe.set_recipe(space.private_recipe_list())
    private_recipe.policy = _make_policy(member)
    public_recipe.policy = _make_policy(member)
    public_recipe.policy.read = []
    store.put(public_recipe)
    store.put(private_recipe)