Пример #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'
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
Пример #3
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)
Пример #4
0
def test_put_recipe():
    recipe = Recipe('cookies')
    recipe.set_recipe(recipe_list)

    store.put(recipe)

    assert os.path.exists('store/recipes/cookies')
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
Пример #6
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)
Пример #7
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)
Пример #8
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
Пример #9
0
def test_put_recipe():
    recipe = Recipe('cookies')
    recipe.set_recipe(recipe_list)

    store.put(recipe)

    assert os.path.exists('store/recipes/cookies')
Пример #10
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)
Пример #11
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'
Пример #12
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'
Пример #13
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'
Пример #14
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)')
Пример #15
0
def remove_user(environ, space_name, user_name):
    """
    remove user_name from space_name while
    checking the policy allows the logged
    in user to do it
    """
    store = environ['tiddlyweb.store']
    
    user = User(user_name)
    user = store.get(user)
    
    logged_in_user = environ['tiddlyweb.usersign']
    
    space_definition = environ['tiddlyweb.config']['space']
    space = []
    for name, values in space_definition['bags'].iteritems():
        bag = Bag(name.replace('SPACE_NAME', space_name))
        bag = store.get(bag)
        bag.policy.allows(logged_in_user, 'manage')
        bag.policy = remove_from_policy(user, bag.policy)
        space.append(bag)
    for name, values in space_definition['recipes'].iteritems():
        recipe = Recipe(name.replace('SPACE_NAME', space_name))
        recipe = store.get(recipe)
        recipe.policy.allows(logged_in_user, 'manage')
        recipe.policy = remove_from_policy(user, recipe.policy)
        space.append(recipe)
        
    for thing in space:
        store.put(thing)
Пример #16
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
Пример #17
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)')
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
Пример #19
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)
Пример #20
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)
Пример #21
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)')
Пример #22
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'
Пример #23
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'
Пример #24
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)
Пример #25
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'
Пример #26
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'
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))
Пример #28
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
Пример #29
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)
Пример #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)

    http = httplib2.Http()
    response, content = http.request("http://our_test_domain:8001/recipes/badfilter/tiddlers")
    assert response["status"] == "400", content
Пример #31
0
def test_recipe_get():
    """
    get a recipe from disk and confirm it has proper form.
    """

    stored_recipe = Recipe('testrecipe')
    stored_recipe = store.get(stored_recipe)

    assert stored_recipe.get_recipe() == recipe_list_string
Пример #32
0
def test_store_recipe():
    recipe_in = Recipe('recipeone')
    recipe_in.desc = 'recipe description'

    store.put(recipe_in)

    recipe_out = store.get(Recipe('recipeone'))

    assert recipe_out.name == recipe_in.name
Пример #33
0
def test_store_recipe():
    recipe_in = Recipe('recipeone')
    recipe_in.desc = 'recipe description'

    store.put(recipe_in)

    recipe_out = store.get(Recipe('recipeone'))

    assert recipe_out.name == recipe_in.name
Пример #34
0
def test_recipe_get():
    """
    get a recipe from disk and confirm it has proper form.
    """

    stored_recipe = Recipe('testrecipe')
    stored_recipe = store.get(stored_recipe)

    assert stored_recipe.get_recipe() == recipe_list_string
Пример #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)
Пример #36
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
Пример #37
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"]
Пример #38
0
def test_recipe():
    set_stdin(RECIPE_STRING)
    handle(['', u'recipe', u'recipe1'])

    the_recipe = Recipe('recipe1')
    the_recipe = store.get(the_recipe)

    assert the_recipe.name == 'recipe1'
    assert u'bag1' in the_recipe.get_recipe()[0]
    assert u'bag2' in the_recipe.get_recipe()[1]
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
Пример #40
0
def test_recipe_etag():
    """
    Explicitly test recipe_etag method (not used by the core code).
    """
    recipe1 = Recipe('foo')
    recipe1.desc = 'desc'
    recipe2 = Recipe('foo')
    recipe2.desc = 'desc'

    assert recipe_etag(environ, recipe1) == recipe_etag(environ, recipe2)
Пример #41
0
def test_put_get_recipe():
    recipe = Recipe('testone')
    recipe.policy.read = ['cdent']
    store.put(recipe)

    read_recipe = Recipe('testone')
    read_recipe.skinny = True
    read_recipe = store.get(read_recipe)

    assert read_recipe.policy.read == ['cdent']
Пример #42
0
def test_put_get_recipe():
    recipe = Recipe('testone')
    recipe.policy.read = ['cdent']
    store.put(recipe)

    read_recipe = Recipe('testone')
    read_recipe.skinny = True
    read_recipe = store.get(read_recipe)

    assert read_recipe.policy.read == ['cdent']
Пример #43
0
def test_recipe():
    set_stdin(RECIPE_STRING)
    handle(['', u'recipe', u'recipe1'])

    the_recipe = Recipe('recipe1')
    the_recipe = store.get(the_recipe)

    assert the_recipe.name == 'recipe1'
    assert u'bag1' in the_recipe.get_recipe()[0]
    assert u'bag2' in the_recipe.get_recipe()[1]
Пример #44
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
Пример #45
0
def test_recipe_has_description():
    """
    Confirm a recipe can set and use a description.
    """
    recipe = Recipe('hasbeen', desc='monkey puzzle')

    assert recipe.name == 'hasbeen'
    assert recipe.desc == 'monkey puzzle'

    recipe.desc = 'collapsing sideburns'
    assert recipe.desc == 'collapsing sideburns'
Пример #46
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)
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
Пример #48
0
def test_recipe_no_recipe():
    """
    make a sure a recipe that is stored without a recipe is retrievable
    """
    recipe = Recipe('testrecipe2')
    recipe.desc = 'I enjoy being stored'
    store.put(recipe)

    stored_recipe = Recipe('testrecipe2')
    stored_recipe = store.get(stored_recipe)

    assert stored_recipe.desc == recipe.desc
Пример #49
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)
Пример #50
0
def test_get_recipe_dot_name():
    """
    Effectively return an entity with a dot in the name.
    """
    recipe = Recipe('long.gif')
    recipe.desc = u'hello'
    store.put(recipe)

    response, content = http.requestU(
        'http://our_test_domain:8001/recipes/long.gif', method='GET')

    assert response['status'] == '200'

    store.delete(recipe)
Пример #51
0
def test_recipe_delete():
    recipe = Recipe('deleteme')
    recipe.desc = 'delete me please'
    store.put(recipe)

    stored_recipe = Recipe('deleteme')
    stored_recipe = store.get(stored_recipe)
    assert stored_recipe.desc == 'delete me please'

    deleted_recipe = Recipe('deleteme')
    store.delete(deleted_recipe)

    py.test.raises(NoRecipeError, 'store.get(deleted_recipe)')
    py.test.raises(NoRecipeError, 'store.delete(deleted_recipe)')
Пример #52
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'
Пример #53
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)
Пример #54
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)
Пример #55
0
def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = get_route_value(environ, 'space_name')
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except (NoRecipeError, ValueError):
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
Пример #56
0
def confirm_space(environ, start_response):
    """
    Confirm a spaces exists. If it does, raise 204. If
    not, raise 404.
    """
    store = environ['tiddlyweb.store']
    space_name = environ['wsgiorg.routing_args'][1]['space_name']
    try:
        space = Space(space_name)
        store.get(Recipe(space.public_recipe()))
        store.get(Recipe(space.private_recipe()))
    except NoRecipeError:
        raise HTTP404('%s does not exist' % space_name)
    start_response('204 No Content', [])
    return ['']
Пример #57
0
def test_html_list():
    serializer = Serializer('html')
    recipes = [Recipe('recipe' + str(name)) for name in xrange(2)]
    string = ''.join(serializer.list_recipes(recipes))

    assert 'href="recipes/recipe0' in string
    assert 'href="recipes/recipe1' in string
Пример #58
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)
Пример #59
0
def userpage(environ, start_response):
    username = environ['tiddlyweb.usersign']['name']
    user = environ['wsgiorg.routing_args'][1]['user']
    if username != user:
        #raise ForbiddenError
        raise UserRequiredError

    store = environ['tiddlyweb.store']
    user_data = User(user)
    try:
        user_data = store.get(user_data)
        wikinames = user_data.note.split('\n')

        wikis = []
        if wikinames:
            for name in wikinames:
                if not len(name):
                    continue
                recipe = Recipe(name)
                recipe = store.get(recipe)
                url = recipe_url(environ, recipe)
                wikis.append(dict(name=name, url=url, description=recipe.desc))
    except NoUserError:
        wikis = []

    start_response('200 OK', [('Content-Type', 'text/html')])
    environ['tiddlyweb.title'] = 'Hello %s' % user
    template = template_env.get_template('user.html')
    return template.generate(wikis=wikis)
Пример #60
0
def test_get_recipe():
    """
    Make sure we are in a different scope.
    """
    recipe_out = store.get(Recipe('recipeone'))
    assert recipe_out.name == 'recipeone'
    assert recipe_out.desc == 'recipe description'