|
5 | 5 |
|
6 | 6 | from ldclient.impl.model import * |
7 | 7 | from ldclient.testing.builders import * |
| 8 | +from ldclient.versioned_data_kind import FEATURES, SEGMENTS |
8 | 9 |
|
9 | 10 |
|
10 | 11 | def test_flag_targets_are_stored_as_sets(): |
@@ -41,3 +42,38 @@ def test_clause_values_preprocessed_with_time_operator(op): |
41 | 42 | flag = make_boolean_flag_with_clauses(make_clause(None, "attr", op, 1000, "1970-01-01T00:00:02Z", True)) |
42 | 43 | assert flag.rules[0].clauses[0]._values == [1000, "1970-01-01T00:00:02Z", True] |
43 | 44 | assert list(x.as_time for x in flag.rules[0].clauses[0]._values_preprocessed) == [1000, 2000, None] |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.parametrize('kind', [FEATURES, SEGMENTS]) |
| 48 | +def test_tombstone_without_key_can_be_decoded(kind): |
| 49 | + # Other LaunchDarkly SDKs write deleted items to a persistent store with only the version, |
| 50 | + # so we must be able to read them back. |
| 51 | + item = kind.decode({"version": 5, "deleted": True}) |
| 52 | + assert item.version == 5 |
| 53 | + assert item.deleted is True |
| 54 | + assert item.key == '' |
| 55 | + # The original data must round-trip unchanged, because the store re-serializes it. |
| 56 | + assert item.to_json_dict() == {"version": 5, "deleted": True} |
| 57 | + |
| 58 | + |
| 59 | +@pytest.mark.parametrize('kind', [FEATURES, SEGMENTS]) |
| 60 | +def test_tombstone_with_placeholder_key_can_be_decoded(kind): |
| 61 | + # The Go SDK and the Relay Proxy write deleted items with a placeholder key. |
| 62 | + item = kind.decode({"key": "$deleted", "version": 5, "deleted": True}) |
| 63 | + assert item.version == 5 |
| 64 | + assert item.deleted is True |
| 65 | + assert item.key == '$deleted' |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.parametrize('kind', [FEATURES, SEGMENTS]) |
| 69 | +def test_tombstone_still_requires_version(kind): |
| 70 | + with pytest.raises(ValueError): |
| 71 | + kind.decode({"deleted": True}) |
| 72 | + |
| 73 | + |
| 74 | +@pytest.mark.parametrize('kind', [FEATURES, SEGMENTS]) |
| 75 | +def test_item_that_is_not_deleted_still_requires_key(kind): |
| 76 | + with pytest.raises(ValueError): |
| 77 | + kind.decode({"version": 5}) |
| 78 | + with pytest.raises(ValueError): |
| 79 | + kind.decode({"version": 5, "deleted": False}) |
0 commit comments