|
1 | 1 | """Unit tests for the input_validator module.""" |
2 | | -import logging |
3 | 2 | import pytest |
4 | 3 |
|
5 | 4 | from splitio.client.factory import SplitFactory, get_factory, SplitFactoryAsync, get_factory_async |
6 | 5 | from splitio.client.client import CONTROL, Client, _LOGGER as _logger, ClientAsync |
7 | | -from splitio.client.manager import SplitManager, SplitManagerAsync |
8 | 6 | from splitio.client.key import Key |
9 | 7 | from splitio.storage import SplitStorage, EventStorage, ImpressionStorage, SegmentStorage, RuleBasedSegmentsStorage |
10 | 8 | from splitio.storage.inmemmory import InMemoryTelemetryStorage, InMemoryTelemetryStorageAsync, \ |
|
14 | 12 | from splitio.recorder.recorder import StandardRecorder, StandardRecorderAsync |
15 | 13 | from splitio.engine.telemetry import TelemetryStorageProducer, TelemetryStorageProducerAsync |
16 | 14 | from splitio.engine.impressions.impressions import Manager as ImpressionManager |
17 | | -from splitio.engine.evaluator import EvaluationDataFactory |
| 15 | +from splitio.models.fallback_treatment import FallbackTreatment |
18 | 16 |
|
19 | 17 | class ClientInputValidationTests(object): |
20 | 18 | """Input validation test cases.""" |
@@ -1627,7 +1625,42 @@ def test_flag_sets_validation(self): |
1627 | 1625 | flag_sets = input_validator.validate_flag_sets([12, 33], 'method') |
1628 | 1626 | assert flag_sets == [] |
1629 | 1627 |
|
| 1628 | + def test_fallback_treatments(self, mocker): |
| 1629 | + _logger = mocker.Mock() |
| 1630 | + mocker.patch('splitio.client.input_validator._LOGGER', new=_logger) |
1630 | 1631 |
|
| 1632 | + assert input_validator.validate_fallback_treatment(FallbackTreatment("on", {"prop":"val"})) |
| 1633 | + assert input_validator.validate_fallback_treatment(FallbackTreatment("on")) |
| 1634 | + |
| 1635 | + _logger.reset_mock() |
| 1636 | + assert not input_validator.validate_fallback_treatment(FallbackTreatment("on" * 100)) |
| 1637 | + assert _logger.warning.mock_calls == [ |
| 1638 | + mocker.call("Config: Fallback treatment size should not exceed %s characters", 100) |
| 1639 | + ] |
| 1640 | + |
| 1641 | + assert input_validator.validate_fallback_treatment(FallbackTreatment("on", {"prop" * 500:"val" * 500})) |
| 1642 | + |
| 1643 | + _logger.reset_mock() |
| 1644 | + assert not input_validator.validate_fallback_treatment(FallbackTreatment("on/c")) |
| 1645 | + assert _logger.warning.mock_calls == [ |
| 1646 | + mocker.call("Config: Fallback treatment should match regex %s", "^[a-zA-Z][a-zA-Z0-9-_;]+$") |
| 1647 | + ] |
| 1648 | + |
| 1649 | + _logger.reset_mock() |
| 1650 | + assert not input_validator.validate_fallback_treatment(FallbackTreatment("9on")) |
| 1651 | + assert _logger.warning.mock_calls == [ |
| 1652 | + mocker.call("Config: Fallback treatment should match regex %s", "^[a-zA-Z][a-zA-Z0-9-_;]+$") |
| 1653 | + ] |
| 1654 | + |
| 1655 | + _logger.reset_mock() |
| 1656 | + assert not input_validator.validate_fallback_treatment(FallbackTreatment("on$as")) |
| 1657 | + assert _logger.warning.mock_calls == [ |
| 1658 | + mocker.call("Config: Fallback treatment should match regex %s", "^[a-zA-Z][a-zA-Z0-9-_;]+$") |
| 1659 | + ] |
| 1660 | + |
| 1661 | + assert input_validator.validate_fallback_treatment(FallbackTreatment("on_c")) |
| 1662 | + assert input_validator.validate_fallback_treatment(FallbackTreatment("on_45-c")) |
| 1663 | + |
1631 | 1664 | class ClientInputValidationAsyncTests(object): |
1632 | 1665 | """Input validation test cases.""" |
1633 | 1666 |
|
|
0 commit comments