def test_basics(self) -> None: """ Verifies the basic behavior of modifying alert words. Also verifies the cache-flushing behavior. """ user = self.example_user('cordelia') realm_alert_words = alert_words_in_realm(user.realm) self.assert_length(realm_alert_words.get(user.id, []), 0) # Add several words, including multi-word and non-ascii words. do_add_alert_words(user, self.interesting_alert_word_list) words = user_alert_words(user) self.assertEqual(set(words), set(self.interesting_alert_word_list)) realm_alert_words = alert_words_in_realm(user.realm) self.assert_length(realm_alert_words[user.id], 3) # Test the case-insensitivity of adding words do_add_alert_words(user, set(["ALert", "ALERT"])) words = user_alert_words(user) self.assertEqual(set(words), set(self.interesting_alert_word_list)) realm_alert_words = alert_words_in_realm(user.realm) self.assert_length(realm_alert_words[user.id], 3) # Test the case-insensitivity of removing words do_remove_alert_words(user, set(["ALert"])) words = user_alert_words(user) self.assertEqual(set(words), set(self.interesting_alert_word_list) - {'alert'}) realm_alert_words = alert_words_in_realm(user.realm) self.assert_length(realm_alert_words[user.id], 2)
def remove_alert_words( request: HttpRequest, user_profile: UserProfile, alert_words: List[str] = REQ(validator=check_list(check_string)), ) -> HttpResponse: do_remove_alert_words(user_profile, alert_words) return json_success({"alert_words": user_alert_words(user_profile)})
def remove_alert_words(request, user_profile, alert_words=REQ(validator=check_list(check_string), default=[])): # type: (HttpRequest, UserProfile, List[str]) -> HttpResponse do_remove_alert_words(user_profile, alert_words) return json_success()
def remove_alert_words( request: HttpRequest, user_profile: UserProfile, alert_words: List[Text] = REQ(validator=check_list(check_string), default=[]) ) -> HttpResponse: do_remove_alert_words(user_profile, alert_words) return json_success()
def test_remove_word(self) -> None: """ Removing alert words works via do_remove_alert_words, even for multi-word and non-ascii words. """ user = self.example_user('cordelia') expected_remaining_alerts = set(self.interesting_alert_word_list) do_add_alert_words(user, self.interesting_alert_word_list) for alert_word in self.interesting_alert_word_list: do_remove_alert_words(user, [alert_word]) expected_remaining_alerts.remove(alert_word) actual_remaining_alerts = user_alert_words(user) self.assertEqual(set(actual_remaining_alerts), expected_remaining_alerts)
def test_alert_words_events(self): alert_words_checker = check_dict([ ('type', equals('alert_words')), ('alert_words', check_list(check_string)), ]) events = self.do_test(lambda: do_add_alert_words(self.user_profile, ["alert_word"])) error = alert_words_checker('events[0]', events[0]) self.assert_on_error(error) events = self.do_test(lambda: do_remove_alert_words(self.user_profile, ["alert_word"])) error = alert_words_checker('events[0]', events[0]) self.assert_on_error(error)
def test_alert_words_events(self): alert_words_checker = check_dict([ ('type', equals('alert_words')), ('alert_words', check_list(check_string)), ]) events = self.do_test(lambda: do_add_alert_words(self.user_profile, ["alert_word"])) error = alert_words_checker('events[0]', events[0]) self.assert_on_error(error) events = self.do_test(lambda: do_remove_alert_words(self.user_profile, ["alert_word"])) error = alert_words_checker('events[0]', events[0]) self.assert_on_error(error)
def remove_alert_words(request, user_profile, alert_words=REQ(validator=check_list(check_string), default=[])): do_remove_alert_words(user_profile, alert_words) return json_success()
def remove_alert_words(request, user_profile, alert_words=REQ(validator=check_list(check_string), default=[])): do_remove_alert_words(user_profile, alert_words) return json_success()
def remove_alert_words(request: HttpRequest, user_profile: UserProfile, alert_words: List[str]=REQ(validator=check_list(check_string), default=[]) ) -> HttpResponse: do_remove_alert_words(user_profile, alert_words) return json_success()
def remove_alert_words(request, user_profile, alert_words=REQ(validator=check_list(check_string), default=[])): # type: (HttpRequest, UserProfile, List[str]) -> HttpResponse do_remove_alert_words(user_profile, alert_words) return json_success()