def test_add_and_remove_interface_on_catalog(self): self._add_comment('one alert') # acquisition wrapped version of the comment comment = IConversation(self.document).values()[0] condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' # adds the marker interface executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) executable() brains = api.content.find( self.portal, object_provides=IHasStopWords.__identifier__ ) self.assertEqual(len(brains), 1) comment.text = 'no longer creating an alert' executable() brains = api.content.find( self.portal, object_provides=IHasStopWords.__identifier__ ) self.assertEqual(len(brains), 0)
def test_no_stop_words_no_interface(self): comment = self._add_comment('no alert') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) executable() self.assertFalse(IHasStopWords.providedBy(comment))
def test_alert_text_local_and_registry_stop_words(self): comment = self._add_comment('this gives one alert') condition = TextAlertCondition() self.records.stop_words = u'almost\nlast one' condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) self.assertTrue(executable())
def test_regular_text_local_and_registry_stop_words(self): comment = self._add_comment('regular text') condition = TextAlertCondition() self.records.stop_words = u'yet another\nlast one' condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) self.assertFalse(executable())
def test_no_stop_words_no_interface_on_catalog(self): comment = self._add_comment('no alert') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) executable() brains = api.content.find( self.portal, object_provides=IHasStopWords.__identifier__ ) self.assertEqual(len(brains), 0)
def test_add_and_remove_interface(self): comment = self._add_comment('one alert') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' # adds the marker interface executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) executable() comment.text = 'no longer creating an alert' executable() self.assertFalse(IHasStopWords.providedBy(comment))
def test_stop_words_on_request(self): comment = self._add_comment('whatever') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) executable() self.assertEqual( self.request.get('stop_words'), condition.stop_words )
def test_alert_text_local_stop_words_no_registry_stop_words(self): comment = self._add_comment('this gives one alert') condition = TextAlertCondition() self.assertEqual( getUtility(IAlert)._get_registry_stop_words(), '' ) condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) self.assertTrue(executable())
def test_dexterity_document(self): document = api.content.create( container=self.portal, id='doc1', title='Document 1', type='Document' ) document.text = u'one alert and no more' condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, ContentTypeDummyEvent(document)), IExecutable ) self.assertTrue(executable())
def test_archetypes_document(self): document = api.content.create( container=self.portal, id='doc2', title='Document 2', type='Document' ) document.setText('this gives one alert') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, ContentTypeDummyEvent(document)), IExecutable ) self.assertTrue(executable())
def test_has_stop_words_add_interface_document(self): document = api.content.create( container=self.portal, id='doc2', title='Document 2', type='Document' ) document.setText('this gives one alert') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, ContentTypeDummyEvent(document)), IExecutable ) executable() self.assertTrue(IHasStopWords.providedBy(document))
def test_has_stop_words_add_interface_document_on_catalog(self): document = api.content.create( container=self.portal, id='doc2', title='Document 2', type='Document' ) document.setText('this gives one alert') condition = TextAlertCondition() condition.stop_words = u'one alert\nanother alert' executable = getMultiAdapter( (self.portal, condition, ContentTypeDummyEvent(document)), IExecutable ) executable() brains = api.content.find( self.portal, object_provides=IHasStopWords.__identifier__ ) self.assertEqual(len(brains), 1)
def test_alert_text_local_stop_words_shadow_registry_stop_words(self): """Local stop words list shadows the registry stop words. This basically means that if the text contains stop words from the registry, but there is a local stop words list that does not complain, the text will be reported that it does *not* contain stop words. That's a way to override the general stop words list to provide a completely different set of stop words. """ comment = self._add_comment('this should give one alert') condition = TextAlertCondition() self.records.stop_words = u'one alert\nanother alert' condition.stop_words = u'almost\nlast one' executable = getMultiAdapter( (self.portal, condition, CommentDummyEvent(comment)), IExecutable ) self.assertFalse(executable())