def test_parse_help(self): """test parsing the help command""" text = "help" self.assertEqual(parse_webhook_text(text), "help")
def post(self, request, *args, **kwargs): try: try: text = request.POST.get("text") rater_uid = f"@{request.POST.get('user_id')}" command = parse_webhook_text(text) except UnrecognizedCommandException: data = HELP_MESSAGE data["text"] = "We don't know that one! Try these: " return JsonResponse(data=data) if command == "create": created_count = do_create(rater_user_id=rater_uid, text=text) data = { "response_type": "ephemeral", "text": f"We logged {created_count} interactions for you. Thanks!", } elif command == "logs": logs = do_logs(rater_user_id=rater_uid, text=text) if isinstance(logs, list): data = { "response_type": "ephemeral", "text": "These are some of your interaction logs!", "attachments": [{ "text": str(interaction) } for interaction in logs] } data["attachments"].append({ "text": "See more by adding an aggregation term" " like `/interactions 90 person`." }) elif isinstance(logs, dict): data = { "response_type": "ephemeral", "text": "These are your aggregated interaction logs!", "attachments": [{ "text": f"{key}:: *positive* {stats['positive']} / *negative* {stats['negative']}" } for key, stats in logs] } else: data = None elif command == "clear": clear_logs(rater_user_id=rater_uid) data = { "response_type": "ephemeral", "text": "You're all clear. Thanks!" } elif command == "help": data = HELP_MESSAGE else: data = None return JsonResponse(data=data) except Exception as e: logger.exception("InteractionsView Exception!") return JsonResponse( data={ "response_type": "ephemeral", "text": "Sorry, that didn't work. :-( " })
def test_all_three_log_params(self): """test parsing getting a log with all three possible params""" text = "90 time -" self.assertEqual(parse_webhook_text(text), "logs")
def test_parse_clear(self): """test parsing the clear command""" text = "clear" self.assertEqual(parse_webhook_text(text), "clear")
def test_parse_get_log_w_time(self): """test parsing getting a log with time argument""" text = "90" self.assertEqual(parse_webhook_text(text), "logs")
def test_parse_get_log_w_time_and_person_aggr(self): """test parsing getting a log with time arg and time aggregation arg""" text = "90 person" self.assertEqual(parse_webhook_text(text), "logs")
def test_parse_get_log_filtered(self): """test parsing getting a log filtering for positive or negative""" texts = ["+", "-", " -", " +", "+ ", "- "] for text in texts: self.assertEqual(parse_webhook_text(text), "logs")
def test_parse_get_log(self): """test parsing getting a log""" text = "" self.assertEqual(parse_webhook_text(text), "logs")
def test_parse_multiple_mixed_interaction(self): """test parsing multiple interaction string with mixed user_id and raw name""" text = "Joseph Curtin + <@U23787> - <@U298333> + Trisha -" self.assertEqual(parse_webhook_text(text), "create")
def test_parse_single_interaction_name(self): """test parsing a single interaction string using raw name""" text = "Joseph Curtin +" self.assertEqual(parse_webhook_text(text), "create")
def test_parse_multiple_interaction_id(self): """test parsing a single interaction string using user_id""" text = "<@U2398577> + <@U2498577> - <@U2598577> +" self.assertEqual(parse_webhook_text(text), "create")