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))
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))
def get_content(self): stream = LocalStream(last_id=self.last_id, user=self.request.user) return stream.get_content()
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_get_target_streams(self): self.assertEqual( len(LocalStream.get_target_streams(self.public_content, self.other_user, self.public_content.author)), 1, )
def setUp(self): super().setUp() self.stream = LocalStream(user=self.other_user)