def process_comment(content): ''' Process the comment to determine if help is requested within the comment body Parameters: content (string): The body of the comment Returns: asking_for_help (boolean): The content is asking for a project difficulty (string): The difficulty requested ''' # Acceptable phrases to trigger the bot phrases = [] phrases.append('u/' + app.config['username']) phrases.append('!projectbot') # Put to lowercase and remove extras content = content.lower().replace('*', '').replace('_', ' ') difficulty = 'all' for phrase in phrases: if phrase in content: # Get the difficulty assuming it is the end of the phrase and the next word index = content.index(phrase) + len(phrase) if index < len(content): difficulty = content[index:].split()[0] if not is_recongized_difficulty(difficulty): difficulty = 'all' return True, difficulty return False, ''
def get_random_idea(self, ideas, desired_difficulty='all'): ''' Get a random idea from the list Argument: ideas (list<csvrow>): The list of ideas parsed from database desired_difficulty (string): The default difficulty. Defaults to all. Returns: idea (csvrow): A random idea ''' # Check ideas is filled if len(ideas['all']) == 0: return None if is_recongized_difficulty(desired_difficulty): tmp_ideas = ideas[desired_difficulty] else: tmp_ideas = ideas['all'] num = random.randrange(0, len(tmp_ideas)) return tmp_ideas[num]
def test_recnogized_difficulty_easy(self): is_recognized = is_recongized_difficulty('easy') self.assertTrue(is_recognized, 'Is not a reconigzed difficulty')
def test_recnogized_difficulty_uppercase_hard(self): is_recognized = is_recongized_difficulty('HARD') self.assertTrue(is_recognized, 'Is not a reconigzed difficulty')
def test_recnogized_difficulty_uppercase_medium(self): is_recognized = is_recongized_difficulty('MEDIUM') self.assertTrue(is_recognized, 'Is not a reconigzed difficulty')
def test_recnogized_difficulty_none(self): is_recognized = is_recongized_difficulty(None) self.assertFalse(is_recognized, 'Is wrongly a reconigzed difficulty')