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)
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)
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)
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)
def test_str_validation_max_length_failed(self): expected = '12345' with self.assertRaises(Invalid): _ = str_validation(val=expected, max_length=4)
def test_validation_max_length(self): expected = '1234' result = str_validation(val=expected, max_length=4) self.assertEqual(expected, result)
def test_str_validation_untouched_test(self): expected = 'banana' result = str_validation(val=expected) self.assertEqual(expected, result)