def test_get_hashed_percentage_does_not_return_1(mock_hashlib):  # type: ignore[no-untyped-def]
    """
    Quite complex test to ensure that the function will never return 1.

    To achieve this, we mock the hashlib module to return a magic mock so that we can
    subsequently mock the hexdigest method to return known strings. These strings are
    chosen such that they can be converted (via `int(s, base=16)`) to known integers.
    """

    # Given
    object_ids = [12, 93]

    # -- SETTING UP THE MOCKS --
    # hash strings specifically created to return specific values when converted to
    # integers via int(s, base=16). Note that the reverse function was created
    # courtesy of https://code.i-harness.com/en/q/1f7c41
    hash_string_to_return_1 = "270e"
    hash_string_to_return_0 = "270f"
    hashed_values = [hash_string_to_return_0, hash_string_to_return_1]

    def hexdigest_side_effect():  # type: ignore[no-untyped-def]
        return hashed_values.pop()

    mock_hash = mock.MagicMock()
    mock_hashlib.md5.return_value = mock_hash

    mock_hash.hexdigest.side_effect = hexdigest_side_effect

    # -- FINISH SETTING UP THE MOCKS --

    # When
    # we get the hashed percentage value for the given object ids
    value = get_hashed_percentage_for_object_ids(object_ids)

    # Then
    # The value is 0 as defined by the mock data
    assert value == 0

    # and the md5 function was called twice
    # (i.e. the get_hashed_percentage_for_object_ids function was also called twice)
    call_list = mock_hashlib.md5.call_args_list
    assert len(call_list) == 2

    # the first call, with a string (in bytes) that contains each object id once
    expected_bytes_1 = ",".join(str(id_) for id_ in object_ids).encode("utf-8")
    assert call_list[0][0][0] == expected_bytes_1

    # the second call, with a string (in bytes) that contains each object id twice
    expected_bytes_2 = ",".join(str(id_) for id_ in object_ids * 2).encode("utf-8")
    assert call_list[1][0][0] == expected_bytes_2

    Quite complex test to ensure that the function will never return 1.

    To achieve this, we mock the hashlib module to return a magic mock so that we can
    subsequently mock the hexdigest method to return known strings. These strings are
    chosen such that they can be converted (via `int(s, base=16)`) to known integers.
    
api/tests/unit/environments/identities/test_unit_identities_helpers.py