Ejemplo n.º 1
0
def test_adduser_with_roles():
    handle(['', u'adduser', u'cdent', u'crunk', u'cow', u'monkey'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('crunk')
    assert 'cow' in the_user.list_roles()
    assert 'monkey' in the_user.list_roles()
Ejemplo n.º 2
0
def test_adduser_with_roles():
    handle(['', u'adduser', u'cdent', u'crunk', u'cow', u'monkey'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('crunk')
    assert 'cow' in the_user.list_roles()
    assert 'monkey' in the_user.list_roles()
Ejemplo n.º 3
0
def test_ltiddlers(capsys):
    handle(['', u'ltiddlers'])
    results, err = capsys.readouterr()
    assert 'bag1' in results
    assert '\ttiddler1' in results
    handle(['', 'ltiddlers', 'bag1'])
    results, err = capsys.readouterr()
    assert 'bag1' in results
    assert '\ttiddler1' in results
Ejemplo n.º 4
0
def test_bag():
    set_stdin(BAG_STRING)
    handle(['', u'bag', u'bag1'])

    the_bag = Bag('bag1')
    the_bag = store.get(the_bag)

    assert the_bag.name == 'bag1'
    assert the_bag.desc == 'hello'
Ejemplo n.º 5
0
def test_bag():
    set_stdin(BAG_STRING)
    handle(['', u'bag', u'bag1'])

    the_bag = Bag('bag1')
    the_bag = store.get(the_bag)

    assert the_bag.name == 'bag1'
    assert the_bag.desc == 'hello'
Ejemplo n.º 6
0
def test_simple_replace():
    handle(['', 'recipeupdate', '/bags/stuff/tiddlers?select=title:monkey',
        '/bags/faster/tiddlers'])

    recipe = store.get(Recipe('hi'))
    recipelist = recipe.get_recipe()

    assert ['faster', ''] in recipelist
    assert ['stuff', 'select=title:monkey'] not in recipelist
Ejemplo n.º 7
0
def test_ltiddlers(capsys):
    handle(['', u'ltiddlers'])
    results, err = capsys.readouterr()
    assert 'bag1' in results
    assert '\ttiddler1' in results
    handle(['', 'ltiddlers', 'bag1'])
    results, err = capsys.readouterr()
    assert 'bag1' in results
    assert '\ttiddler1' in results
Ejemplo n.º 8
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]
Ejemplo n.º 9
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]
Ejemplo n.º 10
0
def test_tiddler():
    set_stdin(TIDDLER_STRING)
    handle(['', u'tiddler', u'bag1', u'tiddler1'])

    the_tiddler = Tiddler('tiddler1', 'bag1')
    the_tiddler = store.get(the_tiddler)

    assert the_tiddler.title == 'tiddler1'
    assert the_tiddler.bag == u'bag1'
    assert the_tiddler.modifier == 'cdent'
Ejemplo n.º 11
0
def test_tiddler():
    set_stdin(TIDDLER_STRING)
    handle(['', u'tiddler', u'bag1', u'tiddler1'])

    the_tiddler = Tiddler('tiddler1', 'bag1')
    the_tiddler = store.get(the_tiddler)

    assert the_tiddler.title == 'tiddler1'
    assert the_tiddler.bag == u'bag1'
    assert the_tiddler.modifier == 'cdent'
Ejemplo n.º 12
0
def test_simple_replace():
    handle([
        '', 'recipeupdate', '/bags/stuff/tiddlers?select=title:monkey',
        '/bags/faster/tiddlers'
    ])

    recipe = store.get(Recipe('hi'))
    recipelist = recipe.get_recipe()

    assert ['faster', ''] in recipelist
    assert ['stuff', 'select=title:monkey'] not in recipelist
Ejemplo n.º 13
0
def test_double_replace():
    handle(['', 'recipeupdate', '/bags/faster/tiddlers',
        '/bags/thanks/tiddlers?sort=modified',
        '/bags/collapse/tiddlers'])

    recipe = store.get(Recipe('hi'))
    recipelist = recipe.get_recipe()

    assert ['faster', ''] not in recipelist
    assert ['thanks', 'sort=modified'] in recipelist
    assert ['collapse', ''] in recipelist
Ejemplo n.º 14
0
def test_double_replace():
    handle([
        '', 'recipeupdate', '/bags/faster/tiddlers',
        '/bags/thanks/tiddlers?sort=modified', '/bags/collapse/tiddlers'
    ])

    recipe = store.get(Recipe('hi'))
    recipelist = recipe.get_recipe()

    assert ['faster', ''] not in recipelist
    assert ['thanks', 'sort=modified'] in recipelist
    assert ['collapse', ''] in recipelist
def test_one_simple_tiddler():
    set_stdin('title,text,modifier,tags,one\r\nfoo,Hello There!,bob,foo bar baz,1\r\n')
    handle(['', u'csvimport', u'bag1'])


    tiddler = Tiddler('foo', 'bag1')
    tiddler = store.get(tiddler)

    assert tiddler.title == 'foo'
    assert tiddler.text == 'Hello There!'
    assert sorted(tiddler.tags) == sorted(['foo', 'bar', 'baz'])
    assert tiddler.fields['one'] == '1'
    store.delete(tiddler)
Ejemplo n.º 16
0
def test_server(capsys):
    import tiddlyweb.web.serve
    def start_cherrypy(config):
        print 'host is %s' % config['server_host']['host']
    tiddlyweb.web.serve.start_cherrypy = start_cherrypy
    handle(['', 'server'])
    results, err = capsys.readouterr()
    assert 'host is our_test_domain' in results

    handle(['', 'server', '192.168.1.1', '8001'])
    results, err = capsys.readouterr()
    assert 'host is 192.168.1.1' in results
    config['server_host']['host'] = 'our_test_domain'
Ejemplo n.º 17
0
def test_server(capsys):
    import tiddlyweb.web.serve

    def start_server(config):
        print('host is %s' % config['server_host']['host'])

    tiddlyweb.web.serve.start_server = start_server
    handle(['', 'server'])
    results, err = capsys.readouterr()
    assert 'host is our_test_domain' in results

    handle(['', 'server', '192.168.1.1', '8001'])
    results, err = capsys.readouterr()
    assert 'host is 192.168.1.1' in results
    config['server_host']['host'] = 'our_test_domain'
def test_two_untitled_tiddlers():
    set_stdin("""alpha,beta,gamma,hotel
one,two,three,four
cat,dog,hamster,mouse""")
    handle(['', u'csvimport', u'bag1'])

    tiddlers = [store.get(tiddler) for tiddler
            in store.list_bag_tiddlers(Bag('bag1'))]

    assert len(tiddlers) == 2
    assert tiddlers[0].text == ''
    assert tiddlers[1].text == ''

    assert 'alpha' in tiddlers[0].fields
    assert 'beta' in tiddlers[1].fields
    
    assert (tiddlers[0].fields['alpha'] == 'one' or
        tiddlers[0].fields['alpha'] == 'cat')
def test_tagdex():
    bag = Bag('snippets')
    STORE.put(bag)

    tiddler = Tiddler('index', 'snippets')
    tiddler.text = 'lipsum'
    tiddler.tags = ['foo', 'bar']
    STORE.put(tiddler)

    response, content = req('GET', '/tags/foo')
    assert response.status == 200

    response, content = req('GET', '/tags/bar')
    assert response.status == 200

    with StreamCapture('stdout') as stream:
        handle(['', 'tags'])

        stream.seek(0)
        tags = stream.read().splitlines()
        assert "foo" in tags
        assert "bar" in tags
Ejemplo n.º 20
0
def test_assetcopy():
    target_dir = os.path.join(TMPDIR, 'static_assets')

    # capture STDERR to avoid confusion
    with StreamCapture('stderr') as stream:
        with raises(SystemExit): # no directory provided
            handle(['', 'assetcopy'])

        handle(['', 'assetcopy', target_dir])

        entries = os.listdir(target_dir)
        assert 'favicon.ico' in entries

        with raises(SystemExit): # directory already exists
            handle(['', 'assetcopy', target_dir])
Ejemplo n.º 21
0
def test_assetcopy(): # XXX: does not belong here
    target_dir = os.path.join(TMPDIR, 'static_assets')
    # capture STDERR to avoid confusion -- XXX: might interefere with reporting - belongs into setup/teardown
    stderr = sys.stderr
    from StringIO import StringIO
    sys.stderr = StringIO()

    with raises(SystemExit): # no directory provided
        handle(['', 'assetcopy'])

    handle(['', 'assetcopy', target_dir])

    entries = os.listdir(target_dir)
    assert 'favicon.ico' in entries

    with raises(SystemExit): # directory already exists
        handle(['', 'assetcopy', target_dir])

    sys.stderr = stderr # restore
Ejemplo n.º 22
0
def test_lusers(capsys):
    handle(['', 'lusers'])
    results, err = capsys.readouterr()
    # cdent user with role monkey was created above
    assert 'cdent' in results
    assert 'monkey' in results
Ejemplo n.º 23
0
def test_lbags(capsys):
    handle(['', u'lbags'])
    results, err = capsys.readouterr()
    assert 'Name: bag1' in results
Ejemplo n.º 24
0
def test_userpass():
    handle(['', u'userpass', u'cdent', u'drunk'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('drunk')
Ejemplo n.º 25
0
def test_addrole():
    handle(['', u'addrole', u'cdent', u'pig'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert 'cow' in the_user.list_roles()
Ejemplo n.º 26
0
def test_lrecipes(capsys):
    handle(['', u'lrecipes'])
    results, err = capsys.readouterr()
    assert 'recipe1 ' in results
Ejemplo n.º 27
0
def test_adduser():
    handle(['', u'adduser', u'cdent', u'crunk'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('crunk')
Ejemplo n.º 28
0
def test_load_module():
    handle(['twanager', '--load', 'test.test_external_load', 'info'])
    assert global_config['monkey'] == 'bar'
Ejemplo n.º 29
0
def test_lrecipes(capsys):
    handle(['', u'lrecipes'])
    results, err = capsys.readouterr()
    assert 'recipe1 ' in results
Ejemplo n.º 30
0
def test_lbags(capsys):
    handle(['', u'lbags'])
    results, err = capsys.readouterr()
    assert 'Name: bag1' in results
Ejemplo n.º 31
0
def test_lusers(capsys):
    handle(['', 'lusers'])
    results, err = capsys.readouterr()
    # cdent user with role monkey was created above
    assert 'cdent' in results
    assert 'monkey' in results
Ejemplo n.º 32
0
def test_addrole():
    handle(['', u'addrole', u'cdent', u'pig'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert 'cow' in the_user.list_roles()
Ejemplo n.º 33
0
def test_info(capsys):
    handle(['', 'info'])
    results, err = capsys.readouterr()
    assert 'current store is' in results
    assert __version__ in results
Ejemplo n.º 34
0
def test_userpass():
    handle(['', u'userpass', u'cdent', u'drunk'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('drunk')
Ejemplo n.º 35
0
def test_info(capsys):
    handle(['', 'info'])
    results, err = capsys.readouterr()
    assert 'current store is' in results
    assert __version__ in results
Ejemplo n.º 36
0
def test_adduser():
    handle(['', u'adduser', u'cdent', u'crunk'])
    the_user = User('cdent')
    the_user = store.get(the_user)
    assert the_user.check_password('crunk')
Ejemplo n.º 37
0
def test_load_module():
    handle(['twanager', '--load', 'test.test_external_load', 'info'])
    assert global_config['monkey'] == 'bar'