def test_calls_update_streams_with_content(self, mock_update): # Calls on create content = ContentFactory() mock_update.assert_called_once_with(content) mock_update.reset_mock() # Does not call on update content.text = "update!" content.save() self.assertFalse(mock_update.called)
def test_content_save_calls_streamconsumer_group_send(self, mock_consumer): mock_consumer.group_send = Mock() # Public post no tags or followers content = ContentFactory() data = json.dumps({"event": "new", "id": content.id}) calls = [ call("streams_public", data), call("streams_profile__%s" % content.author.id, data), call("streams_profile_all__%s" % content.author.id, data), ] mock_consumer.group_send.assert_has_calls(calls, any_order=True) mock_consumer.group_send.reset_mock() # Private post with tags content = ContentFactory(visibility=Visibility.LIMITED, text="#foobar #barfoo") data = json.dumps({"event": "new", "id": content.id}) calls = [ call("streams_tag__%s_foobar" % Tag.objects.get(name="foobar").id, data), call("streams_tag__%s_barfoo" % Tag.objects.get(name="barfoo").id, data), call("streams_profile__%s" % content.author.id, data), call("streams_profile_all__%s" % content.author.id, data), ] mock_consumer.group_send.assert_has_calls(calls, any_order=True) mock_consumer.group_send.reset_mock() # Public post with followers follower = UserFactory() follower2 = UserFactory() profile = ProfileFactory() follower.profile.following.add(content.author) follower2.profile.following.add(content.author) profile.following.add(content.author) content = ContentFactory(author=content.author) data = json.dumps({"event": "new", "id": content.id}) calls = [ call("streams_public", data), call("streams_profile__%s" % content.author.id, data), call("streams_profile_all__%s" % content.author.id, data), call("streams_followed__%s" % follower.username, data), call("streams_followed__%s" % follower2.username, data), ] mock_consumer.group_send.assert_has_calls(calls, any_order=True) mock_consumer.group_send.reset_mock() # Replies reply = ContentFactory(parent=content) data = json.dumps({"event": "new", "id": reply.id}) mock_consumer.group_send.assert_called_once_with( "streams_content__%s" % content.channel_group_name, data) mock_consumer.group_send.reset_mock() # Update shouldn't cause a group send content.text = "foo" content.save() self.assertFalse(mock_consumer.group_send.called)
def test_content_save_calls_streamconsumer_group_send(self, mock_consumer): mock_consumer.group_send = Mock() content = ContentFactory() mock_consumer.group_send.assert_called_once_with( "streams_public", json.dumps({"event": "new", "id": content.id}) ) mock_consumer.group_send.reset_mock() # Update shouldn't cause a group send content.text = "foo" content.save() self.assertFalse(mock_consumer.group_send.called)
def test_content_save_calls_streamconsumer_group_send(self, mock_consumer): mock_consumer.group_send = Mock() # Public post no tags or followers content = ContentFactory() data = json.dumps({"event": "new", "id": content.id}) calls = [ call("streams_public", data), call("streams_profile__%s" % content.author.id, data), call("streams_profile_all__%s" % content.author.id, data), ] mock_consumer.group_send.assert_has_calls(calls, any_order=True) mock_consumer.group_send.reset_mock() # Private post with tags content = ContentFactory(visibility=Visibility.LIMITED, text="#foobar #barfoo") data = json.dumps({"event": "new", "id": content.id}) calls = [ call("streams_tag__%s_foobar" % Tag.objects.get(name="foobar").id, data), call("streams_tag__%s_barfoo" % Tag.objects.get(name="barfoo").id, data), call("streams_profile__%s" % content.author.id, data), call("streams_profile_all__%s" % content.author.id, data), ] mock_consumer.group_send.assert_has_calls(calls, any_order=True) mock_consumer.group_send.reset_mock() # Public post with followers follower = UserFactory() follower2 = UserFactory() profile = ProfileFactory() follower.profile.following.add(content.author) follower2.profile.following.add(content.author) profile.following.add(content.author) content = ContentFactory(author=content.author) data = json.dumps({"event": "new", "id": content.id}) calls = [ call("streams_public", data), call("streams_profile__%s" % content.author.id, data), call("streams_profile_all__%s" % content.author.id, data), call("streams_followed__%s" % follower.username, data), call("streams_followed__%s" % follower2.username, data), ] mock_consumer.group_send.assert_has_calls(calls, any_order=True) mock_consumer.group_send.reset_mock() # Replies reply = ContentFactory(parent=content) data = json.dumps({"event": "new", "id": reply.id}) mock_consumer.group_send.assert_called_once_with("streams_content__%s" % content.channel_group_name, data) mock_consumer.group_send.reset_mock() # Update shouldn't cause a group send content.text = "foo" content.save() self.assertFalse(mock_consumer.group_send.called)
def test_local_content_update_gets_sent(self, mock_update, mock_send): user = UserFactory() content = ContentFactory(author=user.profile) self.assertTrue(content.local) mock_send.reset_mock() content.text = "foobar edit" content.save() self.assertEqual(mock_send.call_count, 1) args, kwargs = mock_send.call_args_list[0] self.assertEqual(args[0], send_content) self.assertEqual(args[1], content.id) self.assertEqual(kwargs, {'recipient_id': None}) activity = content.activities.order_by('-created').first() self.assertEqual(args[2], activity.fid) self.assertEqual(activity.type, ActivityType.UPDATE)