コード例 #1
0
class TestLocalStream(SocialhomeTestCase):
    @classmethod
    def setUpTestData(cls):
        super().setUpTestData()
        cls.user = UserFactory()
        cls.other_user = UserFactory()
        cls.create_content_set(author=cls.user.profile)
        cls.remote_content = PublicContentFactory()

    def setUp(self):
        super().setUp()
        self.stream = LocalStream(user=self.other_user)

    def test_get_target_streams(self):
        self.assertEqual(
            len(
                LocalStream.get_target_streams(self.public_content,
                                               self.other_user,
                                               self.public_content.author)),
            1,
        )

    def test_key(self):
        self.assertEqual(self.stream.key,
                         "sh:streams:local:%s" % self.other_user.id)
        stream = LocalStream(user=AnonymousUser())
        self.assertEqual(stream.key, "sh:streams:local:anonymous")

    def test_only_local_content_returned(self):
        qs, _throughs = self.stream.get_content()
        self.assertEqual(
            set(qs),
            {self.public_content, self.site_content},
        )

    def test_should_cache_content(self):
        self.assertTrue(self.stream.should_cache_content(self.public_content))
        self.assertTrue(self.stream.should_cache_content(self.site_content))
        self.assertFalse(self.stream.should_cache_content(
            self.limited_content))
        self.assertFalse(self.stream.should_cache_content(self.self_content))
        self.assertFalse(self.stream.should_cache_content(self.remote_content))
コード例 #2
0
ファイル: test_streams.py プロジェクト: jaywink/socialhome
class TestLocalStream(SocialhomeTestCase):
    @classmethod
    def setUpTestData(cls):
        super().setUpTestData()
        cls.user = UserFactory()
        cls.other_user = UserFactory()
        cls.create_content_set(author=cls.user.profile)
        cls.remote_content = PublicContentFactory()

    def setUp(self):
        super().setUp()
        self.stream = LocalStream(user=self.other_user)

    def test_get_target_streams(self):
        self.assertEqual(
            len(LocalStream.get_target_streams(self.public_content, self.other_user, self.public_content.author)), 1,
        )

    def test_key(self):
        self.assertEqual(self.stream.key, "sh:streams:local:%s" % self.other_user.id)
        stream = LocalStream(user=AnonymousUser())
        self.assertEqual(stream.key, "sh:streams:local:anonymous")

    def test_only_local_content_returned(self):
        qs, _throughs = self.stream.get_content()
        self.assertEqual(
            set(qs),
            {self.public_content, self.site_content},
        )

    def test_should_cache_content(self):
        self.assertTrue(self.stream.should_cache_content(self.public_content))
        self.assertTrue(self.stream.should_cache_content(self.site_content))
        self.assertFalse(self.stream.should_cache_content(self.limited_content))
        self.assertFalse(self.stream.should_cache_content(self.self_content))
        self.assertFalse(self.stream.should_cache_content(self.remote_content))
コード例 #3
0
 def get_content(self):
     stream = LocalStream(last_id=self.last_id, user=self.request.user)
     return stream.get_content()
コード例 #4
0
 def test_key(self):
     self.assertEqual(self.stream.key, "sh:streams:local:%s" % self.other_user.id)
     stream = LocalStream(user=AnonymousUser())
     self.assertEqual(stream.key, "sh:streams:local:anonymous")
コード例 #5
0
 def test_get_target_streams(self):
     self.assertEqual(
         len(LocalStream.get_target_streams(self.public_content, self.other_user, self.public_content.author)), 1,
     )
コード例 #6
0
 def setUp(self):
     super().setUp()
     self.stream = LocalStream(user=self.other_user)