-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Client support for custom stickiness (#143)
* Allow custom fields in FlexibleRollout Strategy. * Allow custom fields in Variants. * Add spec tests for "11-strategy-constraints-edge-cases.json" * Add spec tests for "12-custom-stickiness.json". * Update changelog. * Add spec tests to Makefile.
- Loading branch information
1 parent
f85ca07
commit 5e3686c
Showing
9 changed files
with
578 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
tests/specification_tests/test_11_strategy_constraints_edge_cases.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import uuid | ||
import json | ||
import pytest | ||
import responses | ||
from UnleashClient import UnleashClient | ||
from UnleashClient.constants import FEATURES_URL, METRICS_URL, REGISTER_URL | ||
from tests.utilities.testing_constants import URL, APP_NAME | ||
|
||
|
||
MOCK_JSON = """ | ||
{ | ||
"version": 1, | ||
"features": [ | ||
{ | ||
"name": "Feature.constraints.no_values", | ||
"description": "Not enabled with constraints and no values", | ||
"enabled": true, | ||
"strategies": [ | ||
{ | ||
"name": "default", | ||
"parameters": {}, | ||
"constraints": [ | ||
{ | ||
"contextName": "environment", | ||
"operator": "IN", | ||
"values": [] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Feature.constraints.no_values_NOT_IN", | ||
"description": "Is enabled with constraints and NOT_IN empty values", | ||
"enabled": true, | ||
"strategies": [ | ||
{ | ||
"name": "default", | ||
"parameters": {}, | ||
"constraints": [ | ||
{ | ||
"contextName": "environment", | ||
"operator": "NOT_IN", | ||
"values": [] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Feature.constraints.empty", | ||
"description": "Is enabled with empty constraints array", | ||
"enabled": true, | ||
"strategies": [ | ||
{ | ||
"name": "default", | ||
"parameters": {}, | ||
"constraints": [] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
""" | ||
|
||
|
||
@pytest.fixture() | ||
def unleash_client(): | ||
unleash_client = UnleashClient(url=URL, | ||
app_name=APP_NAME, | ||
instance_id='pytest_%s' % uuid.uuid4()) | ||
yield unleash_client | ||
unleash_client.destroy() | ||
|
||
|
||
@responses.activate | ||
def test_feature_constraints_novalue_defaultenv(unleash_client): | ||
""" | ||
Feature.constraints.no_value should not be enabled in default environment | ||
""" | ||
# Set up API | ||
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202) | ||
responses.add(responses.GET, URL + FEATURES_URL, json=json.loads(MOCK_JSON), status=200) | ||
responses.add(responses.POST, URL + METRICS_URL, json={}, status=202) | ||
|
||
# Tests | ||
unleash_client.initialize_client() | ||
assert not unleash_client.is_enabled("Feature.constraints.no_values", {'environment': 'default'}) | ||
|
||
|
||
@responses.activate | ||
def test_feature_constraints_novalue_emptyenv(unleash_client): | ||
""" | ||
Feature.constraints.no_value should not be enabled in empty environment | ||
""" | ||
# Set up API | ||
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202) | ||
responses.add(responses.GET, URL + FEATURES_URL, json=json.loads(MOCK_JSON), status=200) | ||
responses.add(responses.POST, URL + METRICS_URL, json={}, status=202) | ||
|
||
# Tests | ||
unleash_client.initialize_client() | ||
assert not unleash_client.is_enabled("Feature.constraints.no_values", {}) | ||
|
||
|
||
@responses.activate | ||
def test_feature_constraints_novalue_defaultenv_notin(unleash_client): | ||
""" | ||
Feature.constraints.no_values_NOT_IN should be enabled in default environment | ||
""" | ||
# Set up API | ||
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202) | ||
responses.add(responses.GET, URL + FEATURES_URL, json=json.loads(MOCK_JSON), status=200) | ||
responses.add(responses.POST, URL + METRICS_URL, json={}, status=202) | ||
|
||
# Tests | ||
unleash_client.initialize_client() | ||
assert unleash_client.is_enabled("Feature.constraints.no_values_NOT_IN", {'environment': 'default'}) | ||
|
||
|
||
@responses.activate | ||
def test_feature_constraints_novalue_emptyenv_notin(unleash_client): | ||
""" | ||
Feature.constraints.no_values_NOT_IN should be enabled in empty environment | ||
""" | ||
# Set up API | ||
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202) | ||
responses.add(responses.GET, URL + FEATURES_URL, json=json.loads(MOCK_JSON), status=200) | ||
responses.add(responses.POST, URL + METRICS_URL, json={}, status=202) | ||
|
||
# Tests | ||
unleash_client.initialize_client() | ||
assert unleash_client.is_enabled("Feature.constraints.no_values_NOT_IN", {}) | ||
|
||
|
||
@responses.activate | ||
def test_feature_constraints_empty_defaultenv(unleash_client): | ||
""" | ||
Feature.constraints.empty should be enabled | ||
""" | ||
# Set up API | ||
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202) | ||
responses.add(responses.GET, URL + FEATURES_URL, json=json.loads(MOCK_JSON), status=200) | ||
responses.add(responses.POST, URL + METRICS_URL, json={}, status=202) | ||
|
||
# Tests | ||
unleash_client.initialize_client() | ||
assert unleash_client.is_enabled("Feature.constraints.no_values_NOT_IN", {'environment': 'default'}) | ||
|
||
|
||
@responses.activate | ||
def test_feature_constraints_empty_emptyenv(unleash_client): | ||
""" | ||
Feature.constraints.empty should be enabled | ||
""" | ||
# Set up API | ||
responses.add(responses.POST, URL + REGISTER_URL, json={}, status=202) | ||
responses.add(responses.GET, URL + FEATURES_URL, json=json.loads(MOCK_JSON), status=200) | ||
responses.add(responses.POST, URL + METRICS_URL, json={}, status=202) | ||
|
||
# Tests | ||
unleash_client.initialize_client() | ||
assert unleash_client.is_enabled("Feature.constraints.no_values_NOT_IN", {}) |
Oops, something went wrong.