def test_simple():
    bag = Bag('MAGICUSER')
    store.put(bag)
    extractor = Extractor()
    userinfo = {'name': 'cdent', 'roles': ['HELLO']}

    more_info = extractor.extract_more_info(environ, userinfo)

    assert 'modifier' in more_info
    assert 'name' in more_info
    assert 'roles' in more_info
    assert 'tags' in more_info
    assert 'fields' in more_info
    assert 'modified' in more_info

    assert more_info['tags'] == []
    assert more_info['fields'] == {}
    assert more_info['roles'] == ['HELLO']

    tiddler = Tiddler('cdent', 'MAGICUSER')
    tiddler.fields['roles'] = "GOODBYE CHRISTMAS EASTER ADMIN"
    tiddler.tags = ['monkey', 'hello', 'barney']
    tiddler.fields['spaces'] = "one two three"
    store.put(tiddler)

    more_info = extractor.extract_more_info(environ, userinfo)

    assert more_info['tags'] == ['monkey', 'hello', 'barney']
    assert len(more_info['roles']) == 5
    for role in ['HELLO', 'GOODBYE', 'CHRISTMAS', 'EASTER', 'ADMIN']:
        assert role in more_info['roles']
    assert more_info['fields']['spaces'] == 'one two three'
def test_simple_magic():
    bag = Bag('MAGICUSER')
    store.put(bag)
    extractor = Extractor()
    userinfo = {'name': 'cdent', 'roles': ['HELLO']}

    more_info = extractor.extract_more_info(environ, userinfo)

    assert 'modifier' in more_info
    assert 'name' in more_info
    assert 'roles' in more_info
    assert 'tags' in more_info
    assert 'fields' in more_info
    assert 'modified' in more_info

    assert more_info['tags'] == []
    assert more_info['fields'] == {}
    assert more_info['roles'] == ['HELLO']

    tiddler = Tiddler('cdent', 'MAGICUSER')
    tiddler.fields['roles'] = "GOODBYE CHRISTMAS EASTER ADMIN"
    tiddler.tags = ['monkey', 'hello', 'barney']
    tiddler.fields['spaces'] = "one two three"
    store.put(tiddler)

    more_info = extractor.extract_more_info(environ, userinfo)

    assert sorted(more_info['tags']) == [u'barney', u'hello', u'monkey']
    assert len(more_info['roles']) == 5
    for role in ['HELLO', 'GOODBYE', 'CHRISTMAS', 'EASTER', 'ADMIN']:
        assert role in more_info['roles']
    assert more_info['fields']['spaces'] == 'one two three'
def test_simple_translate():
    bag = Bag('MAPUSER')
    store.put(bag)
    tiddler = Tiddler('xfoo.example.com', 'MAPUSER')
    tiddler.fields['mapped_user'] = '******'
    store.put(tiddler)

    extractor = Extractor()

    assert extractor.translate_user(environ, 'xfoo.example.com') == 'xfoo'
def test_simple_translate():
    bag = Bag('MAPUSER')
    store.put(bag)
    tiddler = Tiddler('xfoo.example.com', 'MAPUSER')
    tiddler.fields['mapped_user'] = '******'
    store.put(tiddler)

    extractor = Extractor()

    assert extractor.translate_user(environ, 'xfoo.example.com') == 'xfoo'