Skip to content

Commit 651700d

Browse files
helper to build context with runtime data
1 parent 13bb958 commit 651700d

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

‎mixpanel/flags/test_local_feature_flags.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import httpx
55
import threading
66
from unittest.mock import Mock, patch
7-
from typing import Dict, Optional, List
7+
from typing import Any, Dict, Optional, List
88
from itertools import chain, repeat
99
from .types import LocalFlagsConfig, ExperimentationFlag, RuleSet, Variant, Rollout, FlagTestUsers, ExperimentationFlags, VariantOverride, SelectedVariant
1010
from .local_feature_flags import LocalFeatureFlagsProvider
@@ -222,19 +222,20 @@ async def test_get_variant_value_respects_runtime_evaluation_rule_not_satisfied(
222222
}
223223
result = self._flags.get_variant_value(TEST_FLAG_KEY, "fallback", context)
224224
assert result == "fallback"
225+
226+
def user_context_with_properties(self, properties: Dict[str, Any]) -> Dict[str, Any]:
227+
context = {"distinct_id": DISTINCT_ID, "custom_properties": properties}
228+
return context
225229

226230
@respx.mock
227231
async def test_get_variant_value_respects_runtime_evaluation_satisfied(self):
228232
runtime_eval = {"plan": "premium", "region": "US"}
229233
flag = create_test_flag(runtime_evaluation_legacy_definition=runtime_eval)
230234
await self.setup_flags([flag])
231-
context = {
232-
"distinct_id": DISTINCT_ID,
233-
"custom_properties": {
234-
"plan": "premium",
235-
"region": "US"
236-
}
237-
}
235+
context = self.user_context_with_properties({
236+
"plan": "premium",
237+
"region": "US"
238+
})
238239
result = self._flags.get_variant_value(TEST_FLAG_KEY, "fallback", context)
239240
assert result != "fallback"
240241

0 commit comments

Comments
 (0)