def setup_module(module):
    """
    clean up the store, establish a registered client
    """
    clean_store()
    module.store = get_store(config)
    environ = {'tiddlyweb.config': config, 'tiddlyweb.store': module.store}
    ensure_bags(config)

    # make an application and store that info
    app = create(name='testapp', owner='appowner1',
            app_url='http://our_test_domain:8001',
            callback_url='http://our_test_domain:8001/_oauth/callback')

    client_id = app.title
    client_secret = app.fields['client_secret']
    store_app(environ, app)

    config['oauth.servers']['testserver']['client_id'] = client_id
    config['oauth.servers']['testserver']['client_secret'] = client_secret

    module.client_id = client_id

    initialize_app(config)

    module.http = Http()

    # we need a user who is going to use the client app
    user = User('cdent')
    user.set_password('cowpig')
    module.store.put(user)
def test_create_application():

    py.test.raises(TypeError, 'create(name="missing")')

    app = create(name='monkey',
                 owner='cdent',
                 app_url='http://oauth.peermore.com',
                 callback_url='http://oauth.peermore.com/oauth2callback')

    assert app.modifier == 'cdent'
    assert app.fields['name'] == 'monkey'
    assert app.fields['app_url'] == 'http://oauth.peermore.com'
    assert (app.fields['callback_url'] ==
            'http://oauth.peermore.com/oauth2callback')
    assert 'client_secret' in app.fields

    assert isinstance(app, Tiddler)

    app = store_app(environ, app)

    assert client_valid(environ, app.title, app.fields['client_secret'])
def test_create_application():

    py.test.raises(TypeError, 'create(name="missing")')

    app = create(name='monkey',
            owner='cdent',
            app_url='http://oauth.peermore.com',
            callback_url='http://oauth.peermore.com/oauth2callback')

    assert app.modifier == 'cdent'
    assert app.fields['name'] == 'monkey'
    assert app.fields['app_url'] == 'http://oauth.peermore.com'
    assert (app.fields['callback_url']
            == 'http://oauth.peermore.com/oauth2callback')
    assert 'client_secret' in app.fields

    assert isinstance(app, Tiddler)

    app = store_app(environ, app)

    assert client_valid(environ, app.title, app.fields['client_secret'])