Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion optimizely/cmab/cmab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _filter_attributes(self, project_config: ProjectConfig,
for attribute_id in cmab_attribute_ids:
attribute = project_config.attribute_id_map.get(attribute_id)
if attribute and attribute.key in user_attributes:
filtered_user_attributes[attribute.key] = user_attributes[attribute.key]
filtered_user_attributes[attribute.id] = user_attributes[attribute.key]

return filtered_user_attributes

Expand Down
13 changes: 6 additions & 7 deletions tests/test_cmab_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setUp(self):

def test_returns_decision_from_cache_when_valid(self):
expected_key = self.cmab_service._get_cache_key("user123", "exp1")
expected_attributes = {"age": 25, "location": "USA"}
expected_attributes = {"66": 25, "77": "USA"}
expected_hash = self.cmab_service._hash_attributes(expected_attributes)

self.mock_cmab_cache.lookup.return_value = {
Expand All @@ -70,7 +70,7 @@ def test_returns_decision_from_cache_when_valid(self):

def test_ignores_cache_when_option_given(self):
self.mock_cmab_client.fetch_decision.return_value = "varB"
expected_attributes = {"age": 25, "location": "USA"}
expected_attributes = {"66": 25, "77": "USA"}

decision, _ = self.cmab_service.get_decision(
self.mock_project_config,
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_new_decision_when_hash_changes(self):
}
self.mock_cmab_client.fetch_decision.return_value = "varE"

expected_attribute = {"age": 25, "location": "USA"}
expected_attribute = {"66": 25, "77": "USA"}
expected_hash = self.cmab_service._hash_attributes(expected_attribute)
expected_key = self.cmab_service._get_cache_key("user123", "exp1")

Expand All @@ -148,8 +148,8 @@ def test_new_decision_when_hash_changes(self):

def test_filter_attributes_returns_correct_subset(self):
filtered = self.cmab_service._filter_attributes(self.mock_project_config, self.mock_user_context, "exp1")
self.assertEqual(filtered["age"], 25)
self.assertEqual(filtered["location"], "USA")
self.assertEqual(filtered["66"], 25)
self.assertEqual(filtered["77"], "USA")

def test_filter_attributes_empty_when_no_cmab(self):
self.mock_project_config.experiment_id_map["exp1"].cmab = None
Expand Down Expand Up @@ -178,11 +178,10 @@ def test_only_cmab_attributes_passed_to_client(self):
[OptimizelyDecideOption.IGNORE_CMAB_CACHE]
)

# Verify only age and location are passed (attributes configured in setUp)
self.mock_cmab_client.fetch_decision.assert_called_once_with(
"exp1",
self.mock_user_context.user_id,
{"age": 25, "location": "USA"},
{"66": 25, "77": "USA"},
decision["cmab_uuid"]
)

Expand Down
Loading