Ejemplo n.º 1
0
def notify_listeners(content):
    """Send out to listening consumers."""
    # TODO: add sending for tags and pinned user profile content
    if content.visibility == Visibility.PUBLIC:
        StreamConsumer.group_send(
            "streams_public", json.dumps({
                "event": "new",
                "id": content.id,
            }))
Ejemplo n.º 2
0
def notify_listeners(sender, **kwargs):
    if kwargs.get("created"):
        content = kwargs.get("instance")
        if content.visibility == Visibility.PUBLIC:
            StreamConsumer.group_send(
                "streams_public",
                json.dumps({
                    "event": "new",
                    "id": content.id,
                }))
Ejemplo n.º 3
0
 def test__get_stream_class(self, mock_consumer):
     consumer = StreamConsumer()
     with patch.object(consumer,
                       "_get_stream_info",
                       return_value=("public", None)):
         self.assertEqual(consumer._get_stream_class(), PublicStream)
     with patch.object(consumer,
                       "_get_stream_info",
                       return_value=("followed", None)):
         self.assertEqual(consumer._get_stream_class(), FollowedStream)
     with patch.object(consumer,
                       "_get_stream_info",
                       return_value=("tag", None)):
         self.assertEqual(consumer._get_stream_class(), TagStream)
Ejemplo n.º 4
0
 def test__get_stream_instance(self, mock_consumer):
     consumer = StreamConsumer()
     consumer.kwargs = {"stream": "public"}
     instance = consumer._get_stream_instance()
     self.assertTrue(isinstance(instance, PublicStream))
     consumer.kwargs = {"stream": "followed"}
     consumer.message = Mock(user=self.user)
     instance = consumer._get_stream_instance()
     self.assertTrue(isinstance(instance, FollowedStream))
     self.assertTrue(instance.user, self.user)
     consumer.kwargs = {"stream": "tag__%s" % self.tag.id}
     instance = consumer._get_stream_instance()
     self.assertTrue(isinstance(instance, TagStream))
     self.assertEqual(instance.tag, self.tag)
Ejemplo n.º 5
0
def notify_listeners(content):
    """Send out to listening consumers."""
    data = json.dumps({"event": "new", "id": content.id})
    if content.content_type == ContentType.REPLY:
        # Content reply
        StreamConsumer.group_send(
            "streams_content__%s" % content.parent.channel_group_name, data)
    elif content.content_type == ContentType.SHARE:
        # Share
        # TODO do we need to do much?
        pass
    else:
        # Public stream
        if content.visibility == Visibility.PUBLIC:
            StreamConsumer.group_send("streams_public", data)
        # Tag streams
        for tag in content.tags.all():
            StreamConsumer.group_send(
                "streams_tag__%s" % tag.channel_group_name, data)
        # Profile streams
        StreamConsumer.group_send("streams_profile__%s" % content.author.id,
                                  data)
        StreamConsumer.group_send(
            "streams_profile_all__%s" % content.author.id, data)
        # Followed stream
        followed_qs = Profile.objects.followers(
            content.author).filter(user__isnull=False)
        for username in followed_qs.values_list("user__username", flat=True):
            StreamConsumer.group_send("streams_followed__%s" % username, data)
Ejemplo n.º 6
0
 def test__get_stream_qs(self, mock_qs, mock_consumer):
     consumer = StreamConsumer()
     consumer.kwargs = {"stream": "public"}
     self.assertEqual(consumer._get_stream_qs(), "spam")
Ejemplo n.º 7
0
 def test__get_stream_info(self, mock_consumer):
     consumer = StreamConsumer()
     consumer.kwargs = {"stream": "spam"}
     self.assertEqual(consumer._get_stream_info(), ("spam", None))
     consumer.kwargs = {"stream": "spam__eggs"}
     self.assertEqual(consumer._get_stream_info(), ("spam", "eggs"))
Ejemplo n.º 8
0
 def test_connection_groups(self, mock_consumer):
     consumer = StreamConsumer()
     self.assertEqual(consumer.connection_groups(stream="foobar"),
                      ["streams_foobar"])
Ejemplo n.º 9
0
 def test_connection_groups(self, mock_consumer):
     consumer = StreamConsumer()
     self.assertEqual(consumer.connection_groups(stream="foobar"), ["streams_foobar"])
Ejemplo n.º 10
0
def notify_listeners(content):
    """Send out to listening consumers."""
    data = json.dumps({"event": "new", "id": content.id})
    if content.content_type == ContentType.REPLY:
        # Content reply
        StreamConsumer.group_send("streams_content__%s" % content.parent.channel_group_name, data)
    elif content.content_type == ContentType.SHARE:
        # Share
        # TODO do we need to do much?
        pass
    else:
        # Public stream
        if content.visibility == Visibility.PUBLIC:
            StreamConsumer.group_send("streams_public", data)
        # Tag streams
        for tag in content.tags.all():
            StreamConsumer.group_send("streams_tag__%s" % tag.channel_group_name, data)
        # Profile streams
        StreamConsumer.group_send("streams_profile__%s" % content.author.id, data)
        StreamConsumer.group_send("streams_profile_all__%s" % content.author.id, data)
        # Followed stream
        followed_qs = Profile.objects.followers(content.author).filter(user__isnull=False)
        for username in followed_qs.values_list("user__username", flat=True):
            StreamConsumer.group_send("streams_followed__%s" % username, data)
Ejemplo n.º 11
0
 def test__get_stream_qs(self, mock_qs, mock_consumer):
     consumer = StreamConsumer()
     consumer.stream_name = "public"
     self.assertEqual(consumer._get_stream_qs(), "spam")
Ejemplo n.º 12
0
    def test__get_stream_instance(self, mock_consumer):
        consumer = StreamConsumer()
        consumer.stream_name = "public"
        instance = consumer._get_stream_instance()
        self.assertTrue(isinstance(instance, PublicStream))

        consumer.stream_name = "followed"
        consumer.message = Mock(user=self.user)
        instance = consumer._get_stream_instance()
        self.assertTrue(isinstance(instance, FollowedStream))
        self.assertTrue(instance.user, self.user)

        consumer.stream_name = "tag"
        consumer.stream_info = str(self.tag.id)
        instance = consumer._get_stream_instance()
        self.assertTrue(isinstance(instance, TagStream))
        self.assertEqual(instance.tag, self.tag)

        consumer.stream_name = "profile_all"
        consumer.stream_info = str(self.profile.id)
        instance = consumer._get_stream_instance()
        self.assertTrue(isinstance(instance, ProfileAllStream))
        self.assertEqual(instance.profile, self.profile)

        consumer.stream_name = "profile_pinned"
        consumer.stream_info = str(self.profile.id)
        instance = consumer._get_stream_instance()
        self.assertTrue(isinstance(instance, ProfilePinnedStream))
        self.assertEqual(instance.profile, self.profile)
Ejemplo n.º 13
0
 def test__get_stream_class(self, mock_consumer):
     consumer = StreamConsumer()
     consumer.stream_name = "public"
     self.assertEqual(consumer._get_stream_class(), PublicStream)
     consumer.stream_name = "followed"
     self.assertEqual(consumer._get_stream_class(), FollowedStream)
     consumer.stream_name = "tag"
     self.assertEqual(consumer._get_stream_class(), TagStream)
     consumer.stream_name = "profile_all"
     self.assertEqual(consumer._get_stream_class(), ProfileAllStream)
     consumer.stream_name = "profile_pinned"
     self.assertEqual(consumer._get_stream_class(), ProfilePinnedStream)