コード例 #1
0
def test_create_user(user_mgr, remoteuser_mgr, atomic_m):
    user = User(id=42, username="******")
    user_mgr.create_user.return_value = user
    create_user({"sub": "abc", "cognito:username": "******"})

    user_mgr.create_user.assert_called_with(username="******", password=None)
    remoteuser_mgr.create.assert_called_with(user=user, external_user_id="abc")
コード例 #2
0
def test_create_user_external_idp_no_email(user_mgr, remoteuser_mgr, atomic_m):
    # Users coming from external IDPs without email should be accepted too
    user = User(id=42, username="******")
    user_mgr.create_user.return_value = user
    create_user({
        "sub": "abc",
        "cognito:username": "******",
        "identities": [{
            "providerName": "Google"
        }],
    })

    user_mgr.create_user.assert_called_with(username="******", password=None)
    remoteuser_mgr.create.assert_called_with(user=user, external_user_id="abc")
コード例 #3
0
def test_create_user_external_idp(user_mgr, remoteuser_mgr, atomic_m):
    # Users coming from external IDPs should get their email as username
    user = User(id=42, username="******")
    user_mgr.create_user.return_value = user
    create_user({
        "sub": "abc",
        "cognito:username": "******",
        "email": "*****@*****.**",
        "identities": [{
            "providerName": "Google"
        }],
    })

    user_mgr.create_user.assert_called_with(username="******",
                                            password=None)
    remoteuser_mgr.create.assert_called_with(user=user, external_user_id="abc")
コード例 #4
0
def test_create_user_remoteuser_exists(user_mgr, remoteuser_mgr, atomic_m):
    user_mgr.create_user.side_effect = IntegrityError

    # mock the remote-user existence check
    user_mgr.filter.return_value.exists.return_value = True
    assert create_user({"sub": "abc", "cognito:username": "******"}) is None

    assert user_mgr.create_user.call_count == 1
    remoteuser_mgr.filter.assert_called_with(external_user_id="abc")
コード例 #5
0
def test_create_user_username_exists(user_mgr, create_user_m, mocker):
    random_string = mocker.patch("nens_auth_client.users.get_random_string")
    random_string.return_value = "x23f"

    user = User(id=42, username="******")
    create_user_m.side_effect = (IntegrityError, user)

    # mock the user-existence check
    user_mgr.filter.return_value.exists.return_value = True
    assert create_user({"sub": "abc", "cognito:username": "******"}) == user

    # _create_user should have been called twice
    assert create_user_m.call_count == 2
    first_call, second_call = create_user_m.call_args_list
    assert first_call[0] == ("testuser", "abc")
    assert second_call[0] == ("testuserx23f", "abc")