def testValidTitle(self): """ Test valid_title(). """ # everything is okay self.assert_(valid_title('@#$!@#$%^')) self.assert_(valid_title('....')) self.assert_(valid_title('a;3irjq;3 jra;ijaij a;a')) self.assert_(valid_title('thisis a pass')) self.assert_(valid_title('a' * NEWS_MAX_TITLE_LENGTH)) # unless it is too long or blank self.assertFalse(valid_title('a' * (NEWS_MAX_TITLE_LENGTH + 1))) self.assertFalse(valid_title(''))
def check_submission(title, url, text): """ This will check a submission for errors and return a string containing the first error found, or '' if there are no errors. """ if not valid_title(title): return 'Title must be between 1 and ' + \ str(news_settings.NEWS_MAX_TITLE_LENGTH) + ' characters' if not url and not text: return 'Enter url or text' if url and text: return 'Only url OR text (not both)' if url and not valid_url(url): return 'URL not valid' if text and not valid_text(text): return 'Text not valid' # no error return ''