Skip to content

Commit

Permalink
Fix sticky bucket tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn committed Apr 6, 2024
1 parent bb08508 commit 5fe1249
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 8 additions & 7 deletions growthbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ def __init__(
self.name = name
self.phase = phase
self.disableStickyBucketing = disableStickyBucketing
self.bucketVersion = bucketVersion
self.minBucketVersion = minBucketVersion
self.bucketVersion = bucketVersion or 0
self.minBucketVersion = minBucketVersion or 0
self.parentConditions = parentConditions

self.fallbackAttribute = None
Expand Down Expand Up @@ -645,8 +645,8 @@ def __init__(
self.name = name
self.phase = phase
self.disableStickyBucketing = disableStickyBucketing
self.bucketVersion = bucketVersion
self.minBucketVersion = minBucketVersion
self.bucketVersion = bucketVersion or 0
self.minBucketVersion = minBucketVersion or 0
self.parentConditions = parentConditions

def to_dict(self) -> dict:
Expand Down Expand Up @@ -1418,15 +1418,16 @@ def _run(self, experiment: Experiment, featureId: Optional[str] = None) -> Resul
experiment.bucketVersion
)] = result.key

doc = self._generate_sticky_bucket_assignment_doc(
data = self._generate_sticky_bucket_assignment_doc(
hashAttribute,
hashValue,
assignment
)
if doc.get('changed', False):
doc = data.get("doc", None)
if doc and data.get('changed', False):
if not self.sticky_bucket_assignment_docs:
self.sticky_bucket_assignment_docs = {}
self.sticky_bucket_assignment_docs[doc.get('key')] = doc
self.sticky_bucket_assignment_docs[data.get('key')] = doc
self.sticky_bucket_service.save_assignments(doc)

# 14. Fire the tracking callback if set
Expand Down
6 changes: 4 additions & 2 deletions tests/test_growthbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ def test_stickyBucket(stickyBucket_data):
gb = GrowthBook(**ctx)
res = gb.eval_feature(key)

assert res.experimentResult != None
if not res.experimentResult:
assert None == expected_result
else:
assert res.experimentResult.to_dict() == expected_result

assert res.experimentResult.to_dict() == expected_result
assert gb.get_sticky_bucket_assignment_docs() == expected_docs


Expand Down

0 comments on commit 5fe1249

Please sign in to comment.