diff --git a/src/collective/contentalerts/tests/test_contentrules.py b/src/collective/contentalerts/tests/test_contentrules.py index e7e59dc..e30c48d 100644 --- a/src/collective/contentalerts/tests/test_contentrules.py +++ b/src/collective/contentalerts/tests/test_contentrules.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from collective.contentalerts.contentrules import ForbiddenTextAlertCondition +from collective.contentalerts.contentrules import InadequateTextAlertCondition from collective.contentalerts.contentrules import TextAlertCondition from collective.contentalerts.contentrules import TextAlertConditionEditFormView # noqa from collective.contentalerts.interfaces import IAlert @@ -455,6 +457,58 @@ def test_add_and_remove_interface_on_catalog(self): self.assertEqual(len(brains), 0) +class SpecificAlertConditionsTestCase(unittest.TestCase): + + layer = COLLECTIVE_CONTENTALERTS_INTEGRATION_TESTING + + def setUp(self): + self.portal = self.layer['portal'] + self.request = self.layer['request'] + + setRoles(self.portal, TEST_USER_ID, ['Manager']) + + def _set_record_value(self, value, record='inadequate_words'): + api.portal.set_registry_record( + name=record, + interface=IStopWords, + value=value + ) + + def test_inadequate_condition(self): + document = api.content.create( + container=self.portal, + id='doc2', + title='Document 2', + type='Document' + ) + document.text = 'this gives one alert' + condition = InadequateTextAlertCondition() + self._set_record_value(u'one') + + executable = getMultiAdapter( + (self.portal, condition, ContentTypeDummyEvent(document)), + IExecutable + ) + self.assertTrue(executable()) + + def test_forbidden_condition(self): + document = api.content.create( + container=self.portal, + id='doc2', + title='Document 2', + type='Document' + ) + document.text = 'this gives one alert' + condition = ForbiddenTextAlertCondition() + self._set_record_value(u'one', record='forbidden_words') + + executable = getMultiAdapter( + (self.portal, condition, ContentTypeDummyEvent(document)), + IExecutable + ) + self.assertTrue(executable()) + + class ContentRulesSubstitutionsTest(unittest.TestCase): layer = COLLECTIVE_CONTENTALERTS_INTEGRATION_TESTING diff --git a/src/collective/contentalerts/tests/test_utilities.py b/src/collective/contentalerts/tests/test_utilities.py index f42d79f..a7d3c69 100644 --- a/src/collective/contentalerts/tests/test_utilities.py +++ b/src/collective/contentalerts/tests/test_utilities.py @@ -304,6 +304,20 @@ def test_has_forbidden_words_words_found(self): self.utility.has_forbidden_words('and now one is found!') ) + def test_has_inadequate_words_words_found(self): + """Check that has_inadequate_words returns True if words from the + registry are found on the text + """ + api.portal.set_registry_record( + interface=IStopWords, + name='inadequate_words', + value=u'one\ntwo' + ) + + self.assertTrue( + self.utility.has_inadequate_words('and now one is found!') + ) + class HTMLNormalizeTestCase(unittest.TestCase):