示例#1
0
 def test_str_validation_choices_test(self):
     expected = ['apple', 'banana', 'citrus']
     for item in expected:
         result = str_validation(val=item, choices=expected)
         self.assertEqual(item, result)
示例#2
0
 def test_str_validation_choices_wrong_item_test(self):
     choices = ['apple', 'banana', 'citrus']
     wrong_choices = ['star', 'moon']
     for item in wrong_choices:
         with self.assertRaises(Invalid):
             _ = str_validation(val=item, choices=choices)
示例#3
0
 def test_str_validation_failed_regex_test(self):
     """Match only two words with regex"""
     regex = r'^(\w+ )(\w+)$'
     expected = 'apple tree barks what is '
     with self.assertRaises(Invalid):
         _ = str_validation(key=None, val=expected, regex=regex)
示例#4
0
 def test_str_validation_reqex_test(self):
     """Match only two words with regex"""
     regex = r'^(\w+ )(\w+)$'
     expected = 'apple tree'
     result = str_validation(val=expected, regex=regex)
     self.assertEqual(expected, result)
示例#5
0
 def test_str_validation_max_length_failed(self):
     expected = '12345'
     with self.assertRaises(Invalid):
         _ = str_validation(val=expected, max_length=4)
示例#6
0
 def test_validation_max_length(self):
     expected = '1234'
     result = str_validation(val=expected, max_length=4)
     self.assertEqual(expected, result)
示例#7
0
 def test_str_validation_untouched_test(self):
     expected = 'banana'
     result = str_validation(val=expected)
     self.assertEqual(expected, result)