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'
示例#2
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'
示例#3
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'
示例#4
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_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'
def test_get_recipe_list_templated_bag():
    recipe = Recipe('tr')
    recipe.set_recipe([
        ('{{ user }}', '')
        ])
    list = recipe.get_recipe({'user': '******'})
    assert list[0][0] == 'testuser'
示例#7
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'
示例#8
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_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'
示例#10
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'
示例#11
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
示例#12
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
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"]
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]
示例#15
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_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.get_recipe() == new_recipe.get_recipe()

    recipe = Recipe("other")
    recipe.set_recipe([("bagboom", "")])
    assert recipe != new_recipe
示例#17
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.get_recipe() == new_recipe.get_recipe()

    recipe = Recipe('other')
    recipe.set_recipe([('bagboom', '')])
    assert recipe != new_recipe
示例#18
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']
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.get_recipe() == new_recipe.get_recipe()

    recipe = Recipe('other')
    recipe.set_recipe([('bagboom', '')])
    assert recipe != new_recipe, 'modified recipe not equal new_recipe'
示例#20
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']
示例#21
0
def test_put_unicode_recipe():
    http = httplib2.Http()
    encoded_recipe_name = encoded_name
    recipe_name = name
    encoded_bag_name = encoded_name
    bag_name = name

    recipe_list = [[bag_name, '[tag[%s]]' % name]]
    json_recipe_list = simplejson.dumps(dict(recipe=recipe_list))
    response, content = http.request('http://our_test_domain:8001/recipes/%s' % encoded_recipe_name,
            method='PUT', body=json_recipe_list, headers={'Content-Type':'application/json'})
    assert response['status'] == '204'

    recipe = Recipe(recipe_name)
    recipe = store.get(recipe)
    assert recipe.get_recipe() == recipe_list
    assert recipe.name == recipe_name
示例#22
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()
示例#23
0
def test_put_unicode_recipe():
    encoded_recipe_name = encoded_name
    recipe_name = name
    bag_name = name

    recipe_list = [[bag_name, '[tag[%s]]' % name]]
    json_recipe_list = simplejson.dumps(dict(recipe=recipe_list))
    response, content = http.requestU(
        'http://our_test_domain:8001/recipes/%s' % encoded_recipe_name,
        method='PUT',
        body=json_recipe_list,
        headers={'Content-Type': 'application/json'})
    assert response['status'] == '204'

    recipe = Recipe(recipe_name)
    recipe = store.get(recipe)
    assert recipe.get_recipe() == recipe_list
    assert recipe.name == recipe_name
def test_roundtrip_unicode_recipe():
    http = httplib2.Http()
    encoded_recipe_name = '%E3%81%86%E3%81%8F%E3%81%99'
    recipe_name = unicode(urllib.unquote(encoded_recipe_name), 'utf-8')
    assert type(recipe_name) == unicode
    recipe_list = [[recipe_name, '']]
    body = simplejson.dumps(dict(desc='',recipe=recipe_list))
    response, content = http.request('http://our_test_domain:8001/recipes/%s' % encoded_recipe_name,
            method='PUT', body=body.encode('utf-8'), headers={'Content-Type': 'application/json'})
    assert response['status'] == '204'

    recipe = Recipe(recipe_name)
    recipe = store.get(recipe)
    assert recipe.get_recipe() == recipe_list

    response, content = http.request('http://our_test_domain:8001/recipes/%s.json' % encoded_recipe_name,
            method='GET')
    assert response['status'] == '200'
    assert simplejson.loads(content)['recipe'] == recipe_list
示例#25
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()
示例#26
0
def test_put_unicode_recipe():
    http = httplib2.Http()
    encoded_recipe_name = encoded_name
    recipe_name = name
    encoded_bag_name = encoded_name
    bag_name = name

    recipe_list = [[bag_name, "[tag[%s]]" % name]]
    json_recipe_list = simplejson.dumps(dict(recipe=recipe_list))
    response, content = http.request(
        "http://our_test_domain:8001/recipes/%s" % encoded_recipe_name,
        method="PUT",
        body=json_recipe_list,
        headers={"Content-Type": "application/json"},
    )
    assert response["status"] == "204"

    recipe = Recipe(recipe_name)
    recipe = store.get(recipe)
    assert recipe.get_recipe() == recipe_list
    assert recipe.name == recipe_name
示例#27
0
def test_roundtrip_unicode_recipe():
    encoded_recipe_name = '%E3%81%86%E3%81%8F%E3%81%99'
    recipe_name = unquote(encoded_recipe_name)
    recipe_list = [[recipe_name, '']]
    body = simplejson.dumps(dict(desc='', recipe=recipe_list))
    response, content = http.requestU(
        'http://our_test_domain:8001/recipes/%s' % encoded_recipe_name,
        method='PUT',
        body=body.encode('utf-8'),
        headers={'Content-Type': 'application/json'})
    assert response['status'] == '204'

    recipe = Recipe(recipe_name)
    recipe = store.get(recipe)
    assert recipe.get_recipe() == recipe_list

    response, content = http.requestU(
        'http://our_test_domain:8001/recipes/%s.json' % encoded_recipe_name,
        method='GET')
    assert response['status'] == '200'
    assert simplejson.loads(content)['recipe'] == recipe_list
示例#28
0
def test_roundtrip_unicode_recipe():
    http = httplib2.Http()
    encoded_recipe_name = "%E3%81%86%E3%81%8F%E3%81%99"
    recipe_name = unicode(urllib.unquote(encoded_recipe_name), "utf-8")
    assert type(recipe_name) == unicode
    recipe_list = [[recipe_name, ""]]
    body = simplejson.dumps(dict(desc="", recipe=recipe_list))
    response, content = http.request(
        "http://our_test_domain:8001/recipes/%s" % encoded_recipe_name,
        method="PUT",
        body=body.encode("utf-8"),
        headers={"Content-Type": "application/json"},
    )
    assert response["status"] == "204"

    recipe = Recipe(recipe_name)
    recipe = store.get(recipe)
    assert recipe.get_recipe() == recipe_list

    response, content = http.request("http://our_test_domain:8001/recipes/%s.json" % encoded_recipe_name, method="GET")
    assert response["status"] == "200"
    assert simplejson.loads(content)["recipe"] == recipe_list
示例#29
0
 def _ensure_recipe(self, environ, username):
   store = environ['tiddlyweb.store']
   private_recipe = Recipe("portal-"+username);
   try:
       store.delete(private_recipe)
   except NoRecipeError:
       # dont care
       x=1
       # print "dont care"
   portal_recipe = Recipe("portal")
   store.get(portal_recipe)
   # print "PORTAL RECIPE"
   # print portal_recipe
   private_recipe_list = portal_recipe.get_recipe()
   # print "THE LIST"
   # print private_recipe_list
   private_recipe_list.append(['private-'+username, ""])
   private_recipe_list.append(['protected-'+username, ""])
   # private_recipe_list.append(['public-'+username, ""])
   # print "THE LIST"
   # print private_recipe_list
   private_recipe.set_recipe(private_recipe_list)
   store.put(private_recipe)
示例#30
0
def test_subscription():
    response, content = add_subscription('cdent', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    response, content = add_subscription('cdent', 'fnd')  # identical to above
    assert response['status'] == '409'

    response, content = add_subscription('cdent', 'Fnd')  # bad space
    assert response['status'] == '409'

    response, content = add_subscription('cDent', 'fnd')  # bad space
    assert response['status'] == '409'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    response, content = add_subscription('psd', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 6
示例#31
0
def test_subscription():
    response, content = add_subscription('cdent', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    response, content = add_subscription('cdent', 'fnd') # identical to above
    assert response['status'] == '409'

    response, content = add_subscription('cdent', 'Fnd') # bad space
    assert response['status'] == '409'

    response, content = add_subscription('cDent', 'fnd') # bad space
    assert response['status'] == '409'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    response, content = add_subscription('psd', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 6
示例#32
0
def test_unsubscribe():
    """
    Remove a space from a subscription list.
    XXX What happens when there's additional bags (other than public
    and private) from the recipe of the subscribed space and the subscribed
    space has changed since we first subscribed. How do we know what to remove
    from the recipe?
    XXX And what happens with subscription in general if a space is subscribed
    to another space that then goes away? (A non-existent bag in a recipe will
    cause an error)
    """
    response, content = remove_subscription('psd', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    # do it with non-existent space
    response, content = remove_subscription('spanner', 'fnd')
    assert response['status'] == '409'
    assert 'Invalid content for unsubscription' in content

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    # unsubscribe self?
    response, content = remove_subscription('fnd', 'fnd')
    assert response['status'] == '409'
    assert 'Attempt to unsubscribe self' in content

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    # unsubscribe mutuality
    # We don't want a subscribed-to space which has subscribed to the
    # subscribing space to cause removal of one's own bags
    # In this test cdent is subscribed to fnd and fnd is subscribed
    # to cdent. We only want to remove the cdent bags.
    # The solution in code is not perfect because we only
    # make the match based on bag.name, not [bag, filter].
    response, content = remove_subscription('cdent', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 3

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4
def test_make_a_bunch():
    for x in xrange(RANGE):
        bag_name = u'bag%s' % x
        recipe_name = u'recipe%s' % x
        tiddler_name = u'tiddler%s' % x
        recipe_list = [(bag_name, '')]
        tiddler_text = u'hey ho %s' % x
        field_name = u'field%s' % x
        field_name2 = u'fieldone%s' % x
        tag_name = u'tag%s' % x
        user_name = u'user%s' % x
        user_pass = u'pass%s' % x
        user_note = u'note%s' % x
        user_roles = [u'rolehold', u'role%s' % x]

        bag = Bag(bag_name)
        bag.policy.owner = u'owner%s' % x
        bag.policy.read = [u'hi%s' % x, u'andextra']
        bag.policy.manage = [u'R:hi%s' % x, u'andmanage']
        store.put(bag)
        recipe = Recipe(recipe_name)
        recipe.policy.owner = u'owner%s' % x
        recipe.policy.read = [u'hi%s' % x, u'andextra']
        recipe.policy.manage = [u'R:hi%s' % x, u'andmanage']
        recipe.set_recipe(recipe_list)
        store.put(recipe)
        tiddler = Tiddler(tiddler_name, bag_name)
        tiddler.text = tiddler_text
        tiddler.fields[field_name] = field_name
        tiddler.fields[field_name2] = field_name2
        tiddler.fields['server.host'] = 'gunky'
        tiddler.tags = [tag_name]
        store.put(tiddler)
        store.put(tiddler)
        user = User(user_name)
        user.set_password(user_pass)
        user.note = user_note
        for role in user_roles:
            user.add_role(role)
        store.put(user)

    bags = [bag.name for bag in store.list_bags()]
    recipes = [recipe.name for recipe in store.list_recipes()]
    users = [user.usersign for user in store.list_users()]
    assert len(bags) == RANGE
    assert len(recipes) == RANGE
    assert len(users) == RANGE
    for x in xrange(RANGE):
        bname = 'bag%s' % x
        rname = 'recipe%s' % x
        uname = 'user%s' % x
        assert bname in bags
        assert rname in recipes
        assert uname in users

    tiddler = store.get(Tiddler(u'tiddler0', u'bag0'))
    assert tiddler.fields['field0'] == 'field0'
    assert tiddler.fields['fieldone0'] == 'fieldone0'

    bag = Bag(u'bag0')
    bag = store.get(bag)
    tiddlers = []
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.append(store.get(tiddler))
    assert len(tiddlers) == 1
    assert tiddlers[0].title == 'tiddler0'
    assert tiddlers[0].fields['field0'] == 'field0'
    assert tiddlers[0].fields['fieldone0'] == 'fieldone0'
    assert tiddlers[0].tags == ['tag0']
    assert sorted(bag.policy.read) == ['andextra', 'hi0']
    assert sorted(bag.policy.manage) == ['R:hi0', u'andmanage']
    assert bag.policy.owner == 'owner0'

    user = User(u'user1')
    user = store.get(user)
    assert user.usersign == 'user1'
    assert user.check_password('pass1')
    assert user.note == 'note1'
    assert 'role1' in user.list_roles()
    assert 'rolehold' in user.list_roles()

    recipe = Recipe(u'recipe2')
    recipe = store.get(recipe)
    assert recipe.name == 'recipe2'
    bags = [bag_name for bag_name, filter in recipe.get_recipe()]
    assert len(bags) == 1
    assert 'bag2' in bags
    assert sorted(recipe.policy.read) == ['andextra', 'hi2']
    assert sorted(recipe.policy.manage) == ['R:hi2', u'andmanage']
    assert recipe.policy.owner == 'owner2'

    recipe.policy.manage = [u'andmanage']
    store.put(recipe)

    recipe = Recipe (u'recipe2')
    recipe = store.get(recipe)
    assert recipe.policy.manage == [u'andmanage']

    # delete the above things
    store.delete(bag)
    py.test.raises(NoBagError, 'store.delete(bag)')
    py.test.raises(NoBagError, 'store.get(bag)')
    store.delete(recipe)
    py.test.raises(NoRecipeError, 'store.delete(recipe)')
    py.test.raises(NoRecipeError, 'store.get(recipe)')
    store.delete(user)
    py.test.raises(NoUserError, 'store.delete(user)')
    py.test.raises(NoUserError, 'store.get(user)')

    tiddler = Tiddler(u'tiddler9', u'bag9')
    store.get(tiddler)
    assert tiddler.bag == 'bag9'
    assert tiddler.text == 'hey ho 9'
    assert tiddler.tags == ['tag9']
    assert tiddler.fields['field9'] == 'field9'
    assert 'server.host' not in tiddler.fields
    store.delete(tiddler)
    py.test.raises(NoTiddlerError, 'store.delete(tiddler)')
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')
示例#34
0
def test_unsubscribe():
    """
    Remove a space from a subscription list.
    XXX What happens when there's additional bags (other than public
    and private) from the recipe of the subscribed space and the subscribed
    space has changed since we first subscribed. How do we know what to remove
    from the recipe?
    XXX And what happens with subscription in general if a space is subscribed
    to another space that then goes away? (A non-existent bag in a recipe will
    cause an error)
    """
    response, content = remove_subscription('psd', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    # do it with non-existent space
    response, content = remove_subscription('spanner', 'fnd')
    assert response['status'] == '409'
    assert 'Invalid content for unsubscription' in content

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    # unsubscribe self?
    response, content = remove_subscription('fnd', 'fnd')
    assert response['status'] == '409'
    assert 'Attempt to unsubscribe self' in content

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 5

    # unsubscribe mutuality
    # We don't want a subscribed-to space which has subscribed to the
    # subscribing space to cause removal of one's own bags
    # In this test cdent is subscribed to fnd and fnd is subscribed
    # to cdent. We only want to remove the cdent bags.
    # The solution in code is not perfect because we only
    # make the match based on bag.name, not [bag, filter].
    response, content = remove_subscription('cdent', 'fnd')
    assert response['status'] == '204'

    recipe = Recipe('fnd_public')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 3

    recipe = Recipe('fnd_private')
    recipe = store.get(recipe)
    recipe = recipe.get_recipe()
    assert len(recipe) == 4
示例#35
0
def test_make_a_bunch():
    for x in xrange(RANGE):
        bag_name = u"bag%s" % x
        recipe_name = u"recipe%s" % x
        tiddler_name = u"tiddler%s" % x
        recipe_list = [(bag_name, "")]
        tiddler_text = u"hey ho %s" % x
        field_name = u"field%s" % x
        tag_name = u"tag%s" % x
        user_name = u"user%s" % x
        user_pass = u"pass%s" % x
        user_note = u"note%s" % x
        user_roles = [u"rolehold", u"role%s" % x]

        bag = Bag(bag_name)
        bag.policy.owner = u"owner%s" % x
        bag.policy.read = [u"hi%s" % x, u"andextra"]
        bag.policy.manage = [u"R:hi%s" % x, u"andmanage"]
        store.put(bag)
        recipe = Recipe(recipe_name)
        recipe.policy.owner = u"owner%s" % x
        recipe.policy.read = [u"hi%s" % x, u"andextra"]
        recipe.policy.manage = [u"R:hi%s" % x, u"andmanage"]
        recipe.set_recipe(recipe_list)
        store.put(recipe)
        tiddler = Tiddler(tiddler_name, bag_name)
        tiddler.text = tiddler_text
        tiddler.fields[field_name] = field_name
        tiddler.fields["server.host"] = u"gunky"
        tiddler.tags = [tag_name]
        store.put(tiddler)
        user = User(user_name)
        user.set_password(user_pass)
        user.note = user_note
        for role in user_roles:
            user.add_role(role)
        store.put(user)

    bags = [bag.name for bag in store.list_bags()]
    recipes = [recipe.name for recipe in store.list_recipes()]
    users = [user.usersign for user in store.list_users()]
    assert len(bags) == RANGE
    assert len(recipes) == RANGE
    assert len(users) == RANGE
    for x in xrange(RANGE):
        bname = u"bag%s" % x
        rname = u"recipe%s" % x
        uname = u"user%s" % x
        assert bname in bags
        assert rname in recipes
        assert uname in users

    bag = Bag("bag0")
    bag = store.get(bag)
    tiddlers = []
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.append(store.get(tiddler))
    assert len(tiddlers) == 1
    assert tiddlers[0].title == "tiddler0"
    assert tiddlers[0].fields["field0"] == "field0"
    assert tiddlers[0].tags == ["tag0"]
    assert sorted(bag.policy.read) == ["andextra", "hi0"]
    assert sorted(bag.policy.manage) == ["R:hi0", "andmanage"]
    assert bag.policy.owner == "owner0"

    bag = Bag("bag0")
    bag = store.get(bag)
    bag.policy.read.remove("hi0")
    store.put(bag)
    bag = Bag("bag0")
    bag = store.get(bag)
    assert bag.policy.read == [u"andextra"]

    bag = Bag("bag0")
    bag = store.get(bag)
    bag.policy.read.append(u"hi0")
    store.put(bag)
    bag = Bag("bag0")
    bag = store.get(bag)
    assert sorted(bag.policy.read) == ["andextra", "hi0"]

    user = User("user1")
    user = store.get(user)
    assert user.usersign == "user1"
    assert user.check_password("pass1")
    assert user.note == "note1"
    assert "role1" in user.list_roles()
    assert "rolehold" in user.list_roles()

    recipe = Recipe("recipe2")
    recipe = store.get(recipe)
    assert recipe.name == "recipe2"
    bags = [bag_name for bag_name, filter in recipe.get_recipe()]
    assert len(bags) == 1
    assert "bag2" in bags
    assert sorted(recipe.policy.read) == ["andextra", "hi2"]
    assert sorted(recipe.policy.manage) == ["R:hi2", "andmanage"]
    assert recipe.policy.owner == "owner2"

    recipe.policy.manage = [u"andmanage"]
    store.put(recipe)

    recipe = Recipe("recipe2")
    recipe = store.get(recipe)
    assert recipe.policy.manage == ["andmanage"]

    # delete the above things
    store.delete(bag)
    py.test.raises(NoBagError, "store.delete(bag)")
    py.test.raises(NoBagError, "store.get(bag)")
    store.delete(recipe)
    py.test.raises(NoRecipeError, "store.delete(recipe)")
    py.test.raises(NoRecipeError, "store.get(recipe)")
    store.delete(user)
    py.test.raises(NoUserError, "store.delete(user)")
    py.test.raises(NoUserError, "store.get(user)")

    tiddler = Tiddler("tiddler9", "bag9")
    store.get(tiddler)
    assert tiddler.bag == "bag9"
    assert tiddler.text == "hey ho 9"
    assert tiddler.tags == ["tag9"]
    assert tiddler.fields["field9"] == "field9"
    assert "server.host" not in tiddler.fields
    store.delete(tiddler)
    py.test.raises(NoTiddlerError, "store.delete(tiddler)")
    py.test.raises(NoTiddlerError, "store.get(tiddler)")
示例#36
0
def test_make_a_bunch():
    for x in xrange(RANGE):
        bag_name = u'bag%s' % x
        recipe_name = u'recipe%s' % x
        tiddler_name = u'tiddler%s' % x
        recipe_list = [(bag_name, '')]
        tiddler_text = u'hey ho %s' % x
        field_name = u'field%s' % x
        field_name2 = u'fieldone%s' % x
        tag_name = u'tag%s' % x
        user_name = u'user%s' % x
        user_pass = u'pass%s' % x
        user_note = u'note%s' % x
        user_roles = [u'rolehold', u'role%s' % x]

        bag = Bag(bag_name)
        bag.policy.owner = u'owner%s' % x
        bag.policy.read = [u'hi%s' % x, u'andextra']
        bag.policy.manage = [u'R:hi%s' % x, u'andmanage']
        store.put(bag)
        recipe = Recipe(recipe_name)
        recipe.policy.owner = u'owner%s' % x
        recipe.policy.read = [u'hi%s' % x, u'andextra']
        recipe.policy.manage = [u'R:hi%s' % x, u'andmanage']
        recipe.set_recipe(recipe_list)
        store.put(recipe)
        tiddler = Tiddler(tiddler_name, bag_name)
        tiddler.text = tiddler_text
        tiddler.fields[field_name] = field_name
        tiddler.fields[field_name2] = field_name2
        tiddler.fields['server.host'] = 'gunky'
        tiddler.tags = [tag_name]
        store.put(tiddler)
        store.put(tiddler)
        user = User(user_name)
        user.set_password(user_pass)
        user.note = user_note
        for role in user_roles:
            user.add_role(role)
        store.put(user)

    bags = [bag.name for bag in store.list_bags()]
    recipes = [recipe.name for recipe in store.list_recipes()]
    users = [user.usersign for user in store.list_users()]
    assert len(bags) == RANGE
    assert len(recipes) == RANGE
    assert len(users) == RANGE
    for x in xrange(RANGE):
        bname = 'bag%s' % x
        rname = 'recipe%s' % x
        uname = 'user%s' % x
        assert bname in bags
        assert rname in recipes
        assert uname in users

    tiddler = store.get(Tiddler(u'tiddler0', u'bag0'))
    assert tiddler.fields[u'field0'] == u'field0'
    assert tiddler.fields[u'fieldone0'] == u'fieldone0'

    bag = Bag(u'bag0')
    bag = store.get(bag)
    tiddlers = []
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.append(store.get(tiddler))
    assert len(tiddlers) == 1
    assert tiddlers[0].title == 'tiddler0'
    assert tiddlers[0].fields['field0'] == 'field0'
    assert tiddlers[0].fields['fieldone0'] == 'fieldone0'
    assert tiddlers[0].tags == ['tag0']
    assert sorted(bag.policy.read) == ['andextra', 'hi0']
    assert sorted(bag.policy.manage) == ['R:hi0', u'andmanage']
    assert bag.policy.owner == 'owner0'

    user = User(u'user1')
    user = store.get(user)
    assert user.usersign == 'user1'
    assert user.check_password('pass1')
    assert user.note == 'note1'
    assert 'role1' in user.list_roles()
    assert 'rolehold' in user.list_roles()

    recipe = Recipe(u'recipe2')
    recipe = store.get(recipe)
    assert recipe.name == 'recipe2'
    bags = [bag_name for bag_name, filter in recipe.get_recipe()]
    assert len(bags) == 1
    assert 'bag2' in bags
    assert sorted(recipe.policy.read) == ['andextra', 'hi2']
    assert sorted(recipe.policy.manage) == ['R:hi2', u'andmanage']
    assert recipe.policy.owner == 'owner2'

    recipe.policy.manage = [u'andmanage']
    store.put(recipe)

    recipe = Recipe(u'recipe2')
    recipe = store.get(recipe)
    assert recipe.policy.manage == [u'andmanage']

    # delete the above things
    store.delete(bag)
    py.test.raises(NoBagError, 'store.delete(bag)')
    py.test.raises(NoBagError, 'store.get(bag)')
    store.delete(recipe)
    py.test.raises(NoRecipeError, 'store.delete(recipe)')
    py.test.raises(NoRecipeError, 'store.get(recipe)')
    store.delete(user)
    py.test.raises(NoUserError, 'store.delete(user)')
    py.test.raises(NoUserError, 'store.get(user)')

    tiddler = Tiddler(u'tiddler9', u'bag9')
    store.get(tiddler)
    assert tiddler.bag == 'bag9'
    assert tiddler.text == 'hey ho 9'
    assert tiddler.tags == ['tag9']
    assert tiddler.fields['field9'] == 'field9'
    assert 'server.host' not in tiddler.fields
    store.delete(tiddler)
    py.test.raises(NoTiddlerError, 'store.delete(tiddler)')
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')