test_alert_words: Use set comparisons for alert word sets.

This is important, because we're going to relax how fixed ordering is
with the migration away from a JSON list inside UserProfile.
This commit is contained in:
Tim Abbott 2020-04-18 16:06:46 -07:00
parent c83f147a9a
commit 178ce4ae6a
1 changed files with 12 additions and 12 deletions

View File

@ -34,7 +34,7 @@ class AlertWordTests(ZulipTestCase):
self.assert_json_success(result)
user = self.example_user(user_name)
words = user_alert_words(user)
self.assertEqual(words, ['milk', 'cookies'])
self.assertEqual(set(words), {'milk', 'cookies'})
def test_default_no_words(self) -> None:
"""
@ -54,7 +54,7 @@ class AlertWordTests(ZulipTestCase):
add_user_alert_words(user, self.interesting_alert_word_list)
words = user_alert_words(user)
self.assertEqual(words, self.interesting_alert_word_list)
self.assertEqual(set(words), set(self.interesting_alert_word_list))
def test_remove_word(self) -> None:
"""
@ -71,8 +71,8 @@ class AlertWordTests(ZulipTestCase):
remove_user_alert_words(user, alert_word)
theoretical_remaining_alerts.remove(alert_word)
actual_remaining_alerts = user_alert_words(user)
self.assertEqual(actual_remaining_alerts,
theoretical_remaining_alerts)
self.assertEqual(set(actual_remaining_alerts),
set(theoretical_remaining_alerts))
def test_realm_words(self) -> None:
"""
@ -90,9 +90,9 @@ class AlertWordTests(ZulipTestCase):
realm_words = alert_words_in_realm(user2.realm)
self.assertEqual(len(realm_words), 2)
self.assertEqual(set(realm_words.keys()), {user1.id, user2.id})
self.assertEqual(realm_words[user1.id],
self.interesting_alert_word_list)
self.assertEqual(realm_words[user2.id], ['another'])
self.assertEqual(set(realm_words[user1.id]),
set(self.interesting_alert_word_list))
self.assertEqual(set(realm_words[user2.id]), {'another'})
def test_json_list_default(self) -> None:
self.login('hamlet')
@ -108,25 +108,25 @@ class AlertWordTests(ZulipTestCase):
self.login('hamlet')
result = self.client_get('/json/users/me/alert_words')
self.assert_json_success(result)
self.assertEqual(result.json()['alert_words'], ['one', 'two', 'three'])
self.assertEqual(set(result.json()['alert_words']), {'one', 'two', 'three'})
def test_json_list_add(self) -> None:
self.login('hamlet')
result = self.client_post('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one ', '\n two', 'three'])})
self.assert_json_success(result)
self.assertEqual(result.json()['alert_words'], ['one', 'two', 'three'])
self.assertEqual(set(result.json()['alert_words']), {'one', 'two', 'three'})
def test_json_list_remove(self) -> None:
self.login('hamlet')
result = self.client_post('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
self.assert_json_success(result)
self.assertEqual(result.json()['alert_words'], ['one', 'two', 'three'])
self.assertEqual(set(result.json()['alert_words']), {'one', 'two', 'three'})
result = self.client_delete('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one'])})
self.assert_json_success(result)
self.assertEqual(result.json()['alert_words'], ['two', 'three'])
self.assertEqual(set(result.json()['alert_words']), {'two', 'three'})
def message_does_alert(self, user_profile: UserProfile, message: str) -> bool:
"""Send a bunch of messages as othello, so Hamlet is notified"""
@ -140,7 +140,7 @@ class AlertWordTests(ZulipTestCase):
result = self.client_post('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
self.assert_json_success(result)
self.assertEqual(result.json()['alert_words'], ['one', 'two', 'three'])
self.assertEqual(set(result.json()['alert_words']), {'one', 'two', 'three'})
# Alerts in the middle of messages work.
self.assertTrue(self.message_does_alert(user_profile_hamlet, "Normal alert one time"))