def test_matches(self): cond = rules_plugins.MatchesCondition() for reg, field, res in [(r'.*', 'foo', True), (r'fo{1,2}', 'foo', True), (r'o{1,2}', 'foo', False), (r'[1-9]*', 42, True), (r'^(foo|bar)$', 'foo', True), (r'fo', 'foo', False)]: self.assertEqual(res, cond.check(None, field, {'value': reg}))
def test_validate(self): for cond in (rules_plugins.MatchesCondition(), rules_plugins.ContainsCondition()): cond.validate({'value': r'[a-z]?(foo|b.r).+'}) self.assertRaises(ValueError, cond.validate, {'value': '**'})