def test_returns_on_no_content_or_reply(self, mock_filter): add_to_stream_for_users( Content.objects.aggregate(max_id=Max("id")).get("max_id") + 1, PublicStream) self.assertFalse(mock_filter.called) add_to_stream_for_users(self.reply.id, PublicStream) self.assertFalse(mock_filter.called)
def test_returns_on_no_content_or_reply(self, mock_filter): add_to_stream_for_users( Content.objects.aggregate(max_id=Max("id")).get("max_id") + 1, Mock(), PublicStream, self.content.author.id, ) self.assertFalse(mock_filter.called) add_to_stream_for_users(self.reply.id, self.reply.id, PublicStream, self.reply.author.id) self.assertFalse(mock_filter.called)
def test_includes_anonymous_user_for_anonymous_user_streams( self, mock_check): add_to_stream_for_users(self.content.id, "ProfileAllStream", profile=self.profile) anon_call = mock_check.call_args_list[1] self.assertTrue(isinstance(anon_call[1], AnonymousUser))
def test_skips_if_not_cached_stream(self, mock_get): add_to_stream_for_users(self.content.id, self.content.id, "SpamStream", self.content.author.id) self.assertFalse(mock_get.called) add_to_stream_for_users(self.content.id, self.content.id, "PublicStream", self.content.author.id) self.assertFalse(mock_get.called)
def test_calls_check_and_add_to_keys_for_each_user__skipping_inactives(self, mock_check): with freeze_time('2018-01-25'): PublicUserFactory() add_to_stream_for_users(self.content.id, self.content.id, "ProfileAllStream", self.content.author.id) # Would be called twice if inactives were not filtered out mock_check.assert_called_once_with( ProfileAllStream, self.user, self.content, [], self.content.author, set(), False, )
def test_calls_check_and_add_to_keys_for_each_user(self, mock_check): add_to_stream_for_users(self.content.id, "FollowedStream") mock_check.assert_called_once_with(FollowedStream, self.user, self.content, [])
def test_calls_add_to_redis(self, mock_add): add_to_stream_for_users(self.content.id, "FollowedStream") stream = FollowedStream(user=self.user) mock_add.assert_called_once_with(self.content, [stream.get_key()])
def test_includes_anonymous_user_for_anonymous_user_streams( self, mock_check): add_to_stream_for_users(self.content.id, self.content.id, "ProfileAllStream", self.content.author.id) self.assertTrue( isinstance(mock_check.call_args_list[1][0][1], AnonymousUser))
def test_includes_anonymous_user_for_anonymous_user_streams(self, mock_check): add_to_stream_for_users(self.content.id, self.content.id, "ProfileAllStream", self.content.author.id) self.assertTrue(isinstance(mock_check.call_args_list[1][0][1], AnonymousUser))
def test_calls_check_and_add_to_keys_for_each_user__skipping_inactives(self, mock_check): with freeze_time('2018-01-25'): PublicUserFactory() add_to_stream_for_users(self.content.id, self.content.id, "ProfileAllStream", self.content.author.id) # Would be called twice if inactives were not filtered out mock_check.assert_called_once_with(ProfileAllStream, self.user, self.content, [], self.content.author)
def test_calls_check_and_add_to_keys_for_each_user(self, mock_check): add_to_stream_for_users(self.content.id, self.content.id, "FollowedStream", self.content.author.id) mock_check.assert_called_once_with(FollowedStream, self.user, self.content, [], self.content.author)
def test_calls_add_to_redis(self, mock_add): add_to_stream_for_users(self.content.id, self.content.id, "FollowedStream", self.content.author.id) stream = FollowedStream(user=self.user) mock_add.assert_called_once_with(self.content, self.content, [stream.key])
def test_returns_on_no_content(self, mock_filter): add_to_stream_for_users( Content.objects.aggregate(max_id=Max("id")).get("max_id") + 1, Mock(), PublicStream, self.content.author.id, ) self.assertFalse(mock_filter.called)