def test_user_ids_muting_topic(self) -> None: hamlet = self.example_user('hamlet') cordelia = self.example_user('cordelia') realm = hamlet.realm stream = get_stream(u'Verona', realm) recipient = get_stream_recipient(stream.id) topic_name = 'teST topic' stream_topic_target = StreamTopicTarget( stream_id=stream.id, topic_name=topic_name, ) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, set()) def mute_user(user: UserProfile) -> None: add_topic_mute( user_profile=user, stream_id=stream.id, recipient_id=recipient.id, topic_name='test TOPIC', ) mute_user(hamlet) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, {hamlet.id}) mute_user(cordelia) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, {hamlet.id, cordelia.id})
def test_user_ids_muting_topic(self) -> None: hamlet = self.example_user("hamlet") cordelia = self.example_user("cordelia") realm = hamlet.realm stream = get_stream("Verona", realm) recipient = stream.recipient topic_name = "teST topic" stream_topic_target = StreamTopicTarget( stream_id=stream.id, topic_name=topic_name, ) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, set()) def mute_topic_for_user(user: UserProfile) -> None: assert recipient is not None add_topic_mute( user_profile=user, stream_id=stream.id, recipient_id=recipient.id, topic_name="test TOPIC", date_muted=timezone_now(), ) mute_topic_for_user(hamlet) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, {hamlet.id}) hamlet_date_muted = UserTopic.objects.filter( user_profile=hamlet, visibility_policy=UserTopic.MUTED)[0].last_updated self.assertTrue( timezone_now() - hamlet_date_muted <= timedelta(seconds=100)) mute_topic_for_user(cordelia) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, {hamlet.id, cordelia.id}) cordelia_date_muted = UserTopic.objects.filter( user_profile=cordelia, visibility_policy=UserTopic.MUTED)[0].last_updated self.assertTrue( timezone_now() - cordelia_date_muted <= timedelta(seconds=100))
def test_user_ids_muting_topic(self) -> None: hamlet = self.example_user('hamlet') cordelia = self.example_user('cordelia') realm = hamlet.realm stream = get_stream('Verona', realm) recipient = stream.recipient topic_name = 'teST topic' stream_topic_target = StreamTopicTarget( stream_id=stream.id, topic_name=topic_name, ) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, set()) def mute_user(user: UserProfile) -> None: add_topic_mute( user_profile=user, stream_id=stream.id, recipient_id=recipient.id, topic_name='test TOPIC', date_muted=timezone_now(), ) mute_user(hamlet) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, {hamlet.id}) hamlet_date_muted = MutedTopic.objects.filter( user_profile=hamlet)[0].date_muted self.assertTrue( timezone_now() - hamlet_date_muted <= timedelta(seconds=100)) mute_user(cordelia) user_ids = stream_topic_target.user_ids_muting_topic() self.assertEqual(user_ids, {hamlet.id, cordelia.id}) cordelia_date_muted = MutedTopic.objects.filter( user_profile=cordelia)[0].date_muted self.assertTrue( timezone_now() - cordelia_date_muted <= timedelta(seconds=100))