Skip to content

Commit b31dac4

Browse files
committed
feat: trimmed-tests
1 parent 226bb62 commit b31dac4

File tree

3 files changed

+24
-84
lines changed

3 files changed

+24
-84
lines changed

tests/test_flagsmith.py

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -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}},

tests/test_models.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import typing
2-
from unittest import mock
32

43
import pytest
54

6-
from flagsmith.analytics import PipelineAnalyticsProcessor
75
from flagsmith.models import Flag, Flags
86
from flagsmith.types import SDKEvaluationResult, SDKFlagResult
97

@@ -153,34 +151,6 @@ def test_flag_from_evaluation_result_missing_metadata__raises_expected() -> None
153151
Flag.from_evaluation_result(flag_result)
154152

155153

156-
def test_get_flag_records_pipeline_evaluation_event(
157-
pipeline_analytics_processor: PipelineAnalyticsProcessor,
158-
) -> None:
159-
flags = Flags(
160-
flags={
161-
"my_feature": Flag(
162-
enabled=True, value="v1", feature_name="my_feature", feature_id=1
163-
)
164-
},
165-
_pipeline_analytics_processor=pipeline_analytics_processor,
166-
_identity_identifier="user123",
167-
_traits={"plan": "premium"},
168-
)
169-
170-
with mock.patch.object(
171-
pipeline_analytics_processor, "record_evaluation_event"
172-
) as mock_record:
173-
flags.get_flag("my_feature")
174-
175-
mock_record.assert_called_once_with(
176-
flag_key="my_feature",
177-
enabled=True,
178-
value="v1",
179-
identity_identifier="user123",
180-
traits={"plan": "premium"},
181-
)
182-
183-
184154
def test_get_flag_without_pipeline_processor() -> None:
185155
flags = Flags(
186156
flags={

tests/test_pipeline_analytics.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,6 @@ def test_failed_flush_requeues_events(
137137
assert pipeline_analytics_processor._buffer[0]["event_id"] == "my_flag"
138138

139139

140-
@pytest.mark.parametrize(
141-
"url, expected_endpoint",
142-
[
143-
("http://example.com", "http://example.com/v1/analytics/batch"),
144-
("http://example.com/", "http://example.com/v1/analytics/batch"),
145-
],
146-
)
147-
def test_url_trailing_slash_handling(url: str, expected_endpoint: str) -> None:
148-
config = PipelineAnalyticsConfig(analytics_server_url=url)
149-
processor = PipelineAnalyticsProcessor(config=config, environment_key="key")
150-
assert processor._batch_endpoint == expected_endpoint
151-
152-
153140
def test_record_custom_event(
154141
pipeline_analytics_processor: PipelineAnalyticsProcessor,
155142
) -> None:

0 commit comments

Comments
 (0)