|
10 | 10 | from datetime import datetime |
11 | 11 |
|
12 | 12 | from splitio.models.grammar import matchers |
| 13 | +from splitio.models.grammar.matchers.semver import Semver |
13 | 14 | from splitio.storage import SegmentStorage |
14 | 15 | from splitio.engine.evaluator import Evaluator |
15 | 16 |
|
@@ -884,3 +885,44 @@ def test_to_json(self): |
884 | 885 | as_json = matchers.RegexMatcher(self.raw).to_json() |
885 | 886 | assert as_json['matcherType'] == 'MATCHES_STRING' |
886 | 887 | assert as_json['stringMatcherData'] == "^[a-z][A-Z][0-9]$" |
| 888 | + |
| 889 | +class EqualToSemverMatcherTests(MatcherTestsBase): |
| 890 | + """Semver equalto matcher test cases.""" |
| 891 | + |
| 892 | + raw = { |
| 893 | + 'negate': False, |
| 894 | + 'matcherType': 'EQUAL_TO_SEMVER', |
| 895 | + 'stringMatcherData': "2.1.8" |
| 896 | + } |
| 897 | + |
| 898 | + def test_from_raw(self, mocker): |
| 899 | + """Test parsing from raw json/dict.""" |
| 900 | + parsed = matchers.from_raw(self.raw) |
| 901 | + assert isinstance(parsed, matchers.EqualToSemverMatcher) |
| 902 | + assert parsed._data == "2.1.8" |
| 903 | + assert isinstance(parsed._semver, Semver) |
| 904 | + assert parsed._semver._major == 2 |
| 905 | + assert parsed._semver._minor == 1 |
| 906 | + assert parsed._semver._patch == 8 |
| 907 | + assert parsed._semver._pre_release == [] |
| 908 | + |
| 909 | + def test_matcher_behaviour(self, mocker): |
| 910 | + """Test if the matcher works properly.""" |
| 911 | + parsed = matchers.from_raw(self.raw) |
| 912 | + assert not parsed._match("2.1.8+rc") |
| 913 | + assert parsed._match("2.1.8") |
| 914 | + assert not parsed._match("2.1.5") |
| 915 | + assert not parsed._match("2.1.5-rc1") |
| 916 | + assert not parsed._match(None) |
| 917 | + assert not parsed._match("semver") |
| 918 | + |
| 919 | + def test_to_json(self): |
| 920 | + """Test that the object serializes to JSON properly.""" |
| 921 | + as_json = matchers.EqualToSemverMatcher(self.raw).to_json() |
| 922 | + assert as_json['matcherType'] == 'EQUAL_TO_SEMVER' |
| 923 | + assert as_json['stringMatcherData'] == "2.1.8" |
| 924 | + |
| 925 | + def test_to_str(self): |
| 926 | + """Test that the object serializes to str properly.""" |
| 927 | + as_str = matchers.EqualToSemverMatcher(self.raw) |
| 928 | + assert str(as_str) == "equal semver 2.1.8" |
0 commit comments