def test_registration_and_login_with_user_activation_flow(
    db: None,
    api_client: APIClient,
) -> None:
    """
    Test user registration and login flow via email activation.
    By default activation flow is disabled
    """

    # Given user registration data
    email = "test@example.com"
    password = FFAdminUser.objects.make_random_password()
    register_data = {
        "email": email,
        "password": password,
        "first_name": "test",
        "last_name": "register",
    }

    # When register
    register_url = reverse("api-v1:custom_auth:ffadminuser-list")
    result = api_client.post(
        register_url, data=register_data, status_code=status.HTTP_201_CREATED
    )

    # Then success and account inactive
    assert "key" in result.data
    assert "is_active" in result.data
    assert not result.data["is_active"]

    new_user = FFAdminUser.objects.latest("id")
    assert new_user.email == register_data["email"]
    assert new_user.is_active is False

    # And login should fail as we have not activated account yet
    login_data = {
        "email": email,
        "password": password,
    }
    login_url = reverse("api-v1:custom_auth:custom-mfa-authtoken-login")
    failed_login_res = api_client.post(login_url, data=login_data)
    # should return 400
    assert failed_login_res.status_code == status.HTTP_400_BAD_REQUEST

    # verify that the user has been emailed activation email
    # and extract uid and token for account activation
    assert len(mail.outbox) == 1
    # get the url and grab the uid and token
    url = re.findall(r"http\:\/\/.*", mail.outbox[0].body)[0]  # type: ignore[arg-type]
    split_url = url.split("/")
    uid = split_url[-2]
    token = split_url[-1]

    activate_data = {"uid": uid, "token": token}

    activate_url = reverse("api-v1:custom_auth:ffadminuser-activation")
    # And activate account
    api_client.post(
        activate_url, data=activate_data, status_code=status.HTTP_204_NO_CONTENT
    )

    # And login success
    login_result = api_client.post(login_url, data=login_data)
    assert login_result.status_code == status.HTTP_200_OK
    assert "key" in login_result.data

    Test user registration and login flow via email activation.
    By default activation flow is disabled
    
api/tests/integration/custom_auth/end_to_end/test_custom_auth_integration.py