Skip to content
Merged
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
15 changes: 12 additions & 3 deletions splitio/models/splits.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __init__( #pylint: disable=too-many-arguments
conditions=None,
algo=None,
traffic_allocation=None,
traffic_allocation_seed=None
traffic_allocation_seed=None,
configurations=None
):
"""
Class constructor.
Expand Down Expand Up @@ -91,6 +92,8 @@ def __init__( #pylint: disable=too-many-arguments
except ValueError:
self._algo = HashAlgorithm.LEGACY

self._configurations = configurations

@property
def name(self):
"""Return name."""
Expand Down Expand Up @@ -146,6 +149,10 @@ def traffic_allocation_seed(self):
"""Return the traffic allocation seed of the split."""
return self._traffic_allocation_seed

def get_configurations_for(self, treatment):
"""Return the mapping of treatments to configurations."""
return self._configurations.get(treatment) if self._configurations else None

def get_segment_names(self):
"""
Return a list of segment names referenced in all matchers from this split.
Expand All @@ -168,7 +175,8 @@ def to_json(self):
'killed': self.killed,
'defaultTreatment': self.default_treatment,
'algo': self.algo.value,
'conditions': [c.to_json() for c in self.conditions]
'conditions': [c.to_json() for c in self.conditions],
'configurations': self._configurations
}

def to_split_view(self):
Expand Down Expand Up @@ -219,5 +227,6 @@ def from_raw(raw_split):
[condition.from_raw(c) for c in raw_split['conditions']],
raw_split.get('algo'),
traffic_allocation=raw_split.get('trafficAllocation'),
traffic_allocation_seed=raw_split.get('trafficAllocationSeed')
traffic_allocation_seed=raw_split.get('trafficAllocationSeed'),
configurations=raw_split.get('configurations')
)
7 changes: 6 additions & 1 deletion tests/models/test_splits.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ class SplitTests(object):
'combiner': 'AND'
}
}
]
],
'configurations': {
'on': '{"color": "blue", "size": 13}'
},
}

def test_from_raw(self):
Expand All @@ -74,6 +77,8 @@ def test_from_raw(self):
assert parsed.default_treatment == 'off'
assert parsed.algo == splits.HashAlgorithm.MURMUR
assert len(parsed.conditions) == 2
assert parsed.get_configurations_for('on') == '{"color": "blue", "size": 13}'
assert parsed._configurations == {'on': '{"color": "blue", "size": 13}'}

def test_get_segment_names(self, mocker):
"""Test fetching segment names."""
Expand Down