def test_get_all_feature_states_returns_correct_value_when_traits_passed_manually(
    environment: Environment,
    project: Project,
) -> None:
    """
    Verify that when traits are passed manually, then the segments are correctly
    analysed for the identity and the correct value is returned for the feature
    state.
    """

    # Given - an identity with a trait that has an integer value of 10
    trait_key = "trait-key"
    trait_value = 10
    identity = Identity.objects.create(
        identifier="test-identity", environment=environment
    )
    trait = Trait(
        identity=identity,
        trait_key=trait_key,
        integer_value=trait_value,
        value_type=INTEGER,
    )

    # and a segment that matches all identities with a trait value greater than or equal to 5
    segment = Segment.objects.create(name="Test segment 1", project=project)
    rule = SegmentRule.objects.create(segment=segment, type=SegmentRule.ALL_RULE)
    Condition.objects.create(
        rule=rule, property=trait_key, value=5, operator=GREATER_THAN_INCLUSIVE
    )

    # and a feature flag
    default_state = False
    feature_flag = Feature.objects.create(
        project=project, name="test_flag", default_enabled=default_state
    )

    # which is overridden by the segment
    enabled_for_segment = not default_state
    feature_segment = FeatureSegment.objects.create(
        feature=feature_flag,
        segment=segment,
        environment=environment,
        priority=1,
    )
    FeatureState.objects.create(
        feature=feature_flag,
        feature_segment=feature_segment,
        environment=environment,
        enabled=enabled_for_segment,
    )

    # When - we get all feature states for an identity
    feature_states = identity.get_all_feature_states(traits=[trait])

    # Then - the flag is returned with the correct state
    assert len(feature_states) == 1
    assert feature_states[0].enabled == enabled_for_segment

    Verify that when traits are passed manually, then the segments are correctly
    analysed for the identity and the correct value is returned for the feature
    state.
    
api/tests/unit/environments/identities/test_unit_identities_models.py