Skip to content

Commit 1db546c

Browse files
committed
Validare in and not_in errors fixed | case-sensitive
1 parent 621d3ac commit 1db546c

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
***
44

5+
## V0.3.1
6+
7+
- Validate `in` and `not_in` errors fixed
8+
- `in` and `not_in` are case-sensitive
9+
10+
***
11+
512
## V0.3.0
613

714
- File

src/pyvalidations/rules/inside.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ def is_in(self, target):
1414
:param target: any
1515
:return: bool
1616
"""
17-
return self.value in target
17+
18+
validate = target.split(",")
19+
return self.value in validate
1820

1921
def is_not_in(self, target):
2022
"""
2123
check value not in target
2224
:param target: any
2325
:return: bool
2426
"""
25-
return self.value not in target
27+
validate = target.split(",")
28+
return self.value not in validate

tests/test_inside.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@ def test_is_in(self):
99
passed_1 = Rule.Inside(5).is_in("1,2,3,4,5")
1010
passed_2 = Rule.Inside("5").is_in("1,2,3,4,5")
1111
passed_3 = Rule.Inside("Iran").is_in("Iran,USA,UK")
12+
passed_4 = Rule.Inside("Web").is_in("Web,Mobile")
1213
self.assertTrue(passed_1)
1314
self.assertTrue(passed_2)
1415
self.assertTrue(passed_3)
16+
self.assertTrue(passed_4)
1517
failed_1 = Rule.Inside(5).is_in("1,2,3,4")
1618
failed_2 = Rule.Inside("5").is_in("1,2,3,4")
1719
failed_3 = Rule.Inside("iran").is_in("Iran,USA,UK")
20+
failed_4 = Rule.Inside("web").is_in("Web,Mobile")
1821
self.assertFalse(failed_1)
1922
self.assertFalse(failed_2)
2023
self.assertFalse(failed_3)
24+
self.assertFalse(failed_4)
2125

2226
def test_is_not_in(self):
2327
passed_1 = Rule.Inside(5).is_not_in("1,2,3,4")
@@ -43,7 +47,6 @@ def test_pyvalidation_in_passed(self):
4347
"north_america": ["required", "in:usa,canada"],
4448
"europe": ["required", "not_in:china,japan"],
4549
"grade": ["required", "in:a,b"],
46-
4750
}
4851
validate = PyValidation.make(data, rules)
4952
self.assertEqual(validate, {'errors': {}, 'failed': False})

0 commit comments

Comments
 (0)