示例#1
0
async def test_create_user(is_admin, expected_authorization,
                           tmpcwd, app):
    '''Test method get_or_create_user for new user and authorization '''
    auth = NaasAuthenticator(db=app.db)

    if is_admin:
        auth.admin_users = ({'johnsnow'})

    auth.get_or_create_user('johnsnow', 'password')
    user_info = UserInfo.find(app.db, 'johnsnow')
    assert user_info.username == 'johnsnow'
    assert user_info.is_authorized == expected_authorization
示例#2
0
async def test_create_user(is_admin, expected_authorization, tmpcwd, app):
    """Test method create_user for new user and authorization"""
    auth = NaasAuthenticator(db=app.db)

    if is_admin:
        auth.admin_users = {"johnsnow"}

    auth.create_user("johnsnow", "password")
    if expected_authorization:
        UserInfo.change_authorization(app.db, "johnsnow")
    user_info = UserInfo.find(app.db, "johnsnow")
    assert user_info.username == "johnsnow"
    assert user_info.is_authorized == expected_authorization
    assert user_info.is_authorized == UserInfo.get_authorization(
        app.db, "johnsnow")

    UserInfo.change_authorization(app.db, "johnsnow")
    assert UserInfo.get_authorization(app.db,
                                      "johnsnow") != expected_authorization
    UserInfo.update_authorization(app.db, "johnsnow", expected_authorization)
    assert UserInfo.get_authorization(app.db,
                                      "johnsnow") == expected_authorization