@@ -924,57 +924,49 @@ def test_track_event_raises_without_config(api_key: str) -> None:
924924 flagsmith .track_event ("purchase" )
925925
926926
927- def test_track_event_calls_pipeline_processor (
928- mocker : MockerFixture , api_key : str
929- ) -> None :
930- config = PipelineAnalyticsConfig (analytics_server_url = "http://test/" )
931- flagsmith = Flagsmith (environment_key = api_key , pipeline_analytics_config = config )
932-
933- mock_record = mocker .patch .object (
934- flagsmith ._pipeline_analytics_processor , "record_custom_event"
935- )
936-
937- flagsmith .track_event (
938- "purchase" ,
939- identity_identifier = "user1" ,
940- traits = {"plan" : "premium" },
941- metadata = {"amount" : 99 },
942- )
943-
944- mock_record .assert_called_once_with (
945- event_name = "purchase" ,
946- identity_identifier = "user1" ,
947- traits = {"plan" : "premium" },
948- metadata = {"amount" : 99 },
949- )
950-
951-
952927@responses .activate ()
953- def test_get_flag_records_evaluation_event_via_flagsmith (
928+ def test_pipeline_analytics_records_events (
954929 mocker : MockerFixture , api_key : str , flags_json : str
955930) -> None :
956931 config = PipelineAnalyticsConfig (analytics_server_url = "http://test/" )
957932 flagsmith = Flagsmith (environment_key = api_key , pipeline_analytics_config = config )
958933
959- mock_record = mocker .patch .object (
934+ mock_eval = mocker .patch .object (
960935 flagsmith ._pipeline_analytics_processor , "record_evaluation_event"
961936 )
937+ mock_custom = mocker .patch .object (
938+ flagsmith ._pipeline_analytics_processor , "record_custom_event"
939+ )
962940
963941 responses .add (method = "GET" , url = flagsmith .environment_flags_url , body = flags_json )
964942 flags = flagsmith .get_environment_flags ()
965943 flags .get_flag ("some_feature" )
966944
967- mock_record .assert_called_once_with (
945+ mock_eval .assert_called_once_with (
968946 flag_key = "some_feature" ,
969947 enabled = True ,
970948 value = "some-value" ,
971949 identity_identifier = None ,
972950 traits = None ,
973951 )
974952
953+ flagsmith .track_event (
954+ "purchase" ,
955+ identity_identifier = "user1" ,
956+ traits = {"plan" : "premium" },
957+ metadata = {"amount" : 99 },
958+ )
959+
960+ mock_custom .assert_called_once_with (
961+ event_name = "purchase" ,
962+ identity_identifier = "user1" ,
963+ traits = {"plan" : "premium" },
964+ metadata = {"amount" : 99 },
965+ )
966+
975967
976968@responses .activate ()
977- def test_get_identity_flags_passes_identity_and_traits (
969+ def test_identity_flags_records_evaluation_with_resolved_traits (
978970 mocker : MockerFixture , api_key : str , identities_json : str
979971) -> None :
980972 config = PipelineAnalyticsConfig (analytics_server_url = "http://test/" )
@@ -985,6 +977,8 @@ def test_get_identity_flags_passes_identity_and_traits(
985977 )
986978
987979 responses .add (method = "POST" , url = flagsmith .identities_url , body = identities_json )
980+ responses .add (method = "POST" , url = flagsmith .identities_url , body = identities_json )
981+
988982 flags = flagsmith .get_identity_flags ("user123" , traits = {"plan" : "premium" })
989983 flags .get_flag ("some_feature" )
990984
@@ -996,19 +990,8 @@ def test_get_identity_flags_passes_identity_and_traits(
996990 traits = {"plan" : "premium" },
997991 )
998992
993+ mock_record .reset_mock ()
999994
1000- @responses .activate ()
1001- def test_get_identity_flags_resolves_trait_config_values (
1002- mocker : MockerFixture , api_key : str , identities_json : str
1003- ) -> None :
1004- config = PipelineAnalyticsConfig (analytics_server_url = "http://test/" )
1005- flagsmith = Flagsmith (environment_key = api_key , pipeline_analytics_config = config )
1006-
1007- mock_record = mocker .patch .object (
1008- flagsmith ._pipeline_analytics_processor , "record_evaluation_event"
1009- )
1010-
1011- responses .add (method = "POST" , url = flagsmith .identities_url , body = identities_json )
1012995 flags = flagsmith .get_identity_flags (
1013996 "user123" ,
1014997 traits = {"plan" : {"value" : "premium" , "transient" : True }},
0 commit comments