Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Jul 27, 2016
1 parent b726b12 commit cb0b5df
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
54 changes: 54 additions & 0 deletions 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
Expand Down Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/collective/contentalerts/tests/test_utilities.py
Expand Up @@ -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):

Expand Down

0 comments on commit cb0b5df

Please sign in to comment.