def test_badwords(self): db = Mock() db.query = Mock(return_value=[{ 'kill_words': 'asshole other dirty words', 'warn_words': 'jerk kinda bad stuff', }]) self.assertEqual(censor.badwords(db, "asshole"), 2) self.assertEqual(censor.badwords(db, "jerk"), 1) self.assertEqual(censor.badwords(db, "unicorn"), 0)
def test_badwords(self): db = Mock() db.query = Mock(return_value=[{ 'kill_words' : 'asshole other dirty words', 'warn_words' : 'jerk kinda bad stuff', }]) self.assertEqual(censor.badwords(db, "asshole"), 2) self.assertEqual(censor.badwords(db, "jerk"), 1) self.assertEqual(censor.badwords(db, "unicorn"), 0)
def updateProjectResourceTextData(db, projectResourceId, field, text): isHidden = (censor.badwords(db, text) > 0) try: sql = "update project_resource set %s = $text, is_hidden = $isHidden where project_resource_id = $id" % field db.query(sql, {'id':projectResourceId, 'text':text, 'isHidden':isHidden}) return True except Exception, e: log.info("*** couldn't update project %s" % field) log.error(e) return False
def updateProjectResourceTextData(db, projectResourceId, field, text): isHidden = (censor.badwords(db, text) > 0) try: sql = "update project_resource set %s = $text, is_hidden = $isHidden where project_resource_id = $id" % field db.query(sql, { 'id': projectResourceId, 'text': text, 'isHidden': isHidden }) return True except Exception, e: log.info("*** couldn't update project %s" % field) log.error(e) return False
def createIdea(db, description, locationId, submissionType, userId=None, email=None, phone=None): try: # censor behavior numFlags = censor.badwords(db, description) isActive = 0 if numFlags == 2 else 1 ideaId = db.insert('idea', description = description, location_id = locationId, submission_type = submissionType, user_id = userId, email = email, phone = phone, is_active = isActive, num_flags = numFlags) except Exception, e: log.info("*** problem creating idea") log.error(e) return None