def test_get_target_streams(self): self.assertEqual( len( TagStream.get_target_streams(self.limited_tagged, self.user, self.limited_tagged.author)), 3, )
def get_content(self): stream = TagStream(last_id=self.last_id, tag=self.tag, user=self.request.user) return stream.get_content()
def setUp(self): super().setUp() self.stream = TagStream(tag=self.tag, user=self.user) self.anon_stream = TagStream(tag=self.tag, user=AnonymousUser()) self.local_stream = TagStream(tag=self.tag, user=self.local_user)
class TestTagStream(SocialhomeTestCase): @classmethod def setUpTestData(cls): super().setUpTestData() cls.create_local_and_remote_user() cls.local_user = UserFactory() cls.create_content_set() cls.public_tagged = PublicContentFactory(text="#foobar", author=cls.profile) cls.site_tagged = SiteContentFactory(text="#foobar", author=cls.profile) cls.self_tagged = SelfContentFactory(text="#foobar", author=cls.profile) cls.limited_tagged = LimitedContentFactory(text="#foobar", author=cls.profile) cls.tag = cls.public_tagged.tags.first() def setUp(self): super().setUp() self.stream = TagStream(tag=self.tag, user=self.user) self.anon_stream = TagStream(tag=self.tag, user=AnonymousUser()) self.local_stream = TagStream(tag=self.tag, user=self.local_user) def test_get_content_ids_does_not_use_cached_ids(self): with patch.object(self.stream, "get_cached_content_ids") as mock_cached: self.stream.get_content_ids() self.assertFalse(mock_cached.called) def test_get_key(self): self.assertEqual(self.stream.get_key(), "socialhome:streams:tag:%s" % self.user.id) stream = PublicStream(user=AnonymousUser()) self.assertEqual(stream.get_key(), "socialhome:streams:public:anonymous") def test_only_tagged_content_returned(self): self.assertEqual( {self.public_tagged}, set(self.anon_stream.get_content()), ) self.assertEqual( { self.public_tagged, self.site_tagged, self.self_tagged, self.limited_tagged }, set(self.stream.get_content()), ) self.assertEqual( {self.public_tagged, self.site_tagged}, set(self.local_stream.get_content()), ) def test_raises_if_no_user(self): self.stream.user = None with self.assertRaises(AttributeError): self.stream.get_content() def test_raises_if_no_tag(self): self.stream.tag = None with self.assertRaises(AttributeError): self.stream.get_content() def test_should_cache_content(self): # self.user stream self.assertTrue(self.stream.should_cache_content(self.public_tagged)) self.assertTrue(self.stream.should_cache_content(self.site_tagged)) self.assertTrue(self.stream.should_cache_content(self.limited_tagged)) self.assertTrue(self.stream.should_cache_content(self.self_tagged)) self.assertFalse(self.stream.should_cache_content(self.public_content)) self.assertFalse(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)) # anon stream self.assertTrue( self.anon_stream.should_cache_content(self.public_tagged)) self.assertFalse( self.anon_stream.should_cache_content(self.site_tagged)) self.assertFalse( self.anon_stream.should_cache_content(self.limited_tagged)) self.assertFalse( self.anon_stream.should_cache_content(self.self_tagged)) self.assertFalse( self.anon_stream.should_cache_content(self.public_content)) self.assertFalse( self.anon_stream.should_cache_content(self.site_content)) self.assertFalse( self.anon_stream.should_cache_content(self.limited_content)) self.assertFalse( self.anon_stream.should_cache_content(self.self_content)) # self.local_user stream self.assertTrue( self.local_stream.should_cache_content(self.public_tagged)) self.assertTrue( self.local_stream.should_cache_content(self.site_tagged)) self.assertFalse( self.local_stream.should_cache_content(self.limited_tagged)) self.assertFalse( self.local_stream.should_cache_content(self.self_tagged)) self.assertFalse( self.local_stream.should_cache_content(self.public_content)) self.assertFalse( self.local_stream.should_cache_content(self.site_content)) self.assertFalse( self.local_stream.should_cache_content(self.limited_content)) self.assertFalse( self.local_stream.should_cache_content(self.self_content))
def test_key(self): self.assertEqual(self.stream.key, "sh:streams:tag:%s:%s" % (self.tag.id, self.user.id)) stream = TagStream(tag=self.tag, user=AnonymousUser()) self.assertEqual(stream.key, "sh:streams:tag:%s:anonymous" % self.tag.id)
def test_get_target_streams(self): self.assertEqual( len(TagStream.get_target_streams(self.limited_tagged, self.user, self.limited_tagged.author)), 3, )
class TestTagStream(SocialhomeTestCase): @classmethod def setUpTestData(cls): super().setUpTestData() cls.create_local_and_remote_user() cls.local_user = UserFactory() cls.create_content_set() cls.public_tagged = PublicContentFactory(text="#foobar", author=cls.profile) cls.site_tagged = SiteContentFactory(text="#foobar", author=cls.profile) cls.self_tagged = SelfContentFactory(text="#foobar", author=cls.profile) cls.limited_tagged = LimitedContentFactory(text="#foobar #spam #eggs", author=cls.profile) cls.tag = cls.public_tagged.tags.first() def setUp(self): super().setUp() self.stream = TagStream(tag=self.tag, user=self.user) self.anon_stream = TagStream(tag=self.tag, user=AnonymousUser()) self.local_stream = TagStream(tag=self.tag, user=self.local_user) def test_get_content_ids_does_not_use_cached_ids(self): with patch.object(self.stream, "get_cached_content_ids") as mock_cached: self.stream.get_content_ids() self.assertFalse(mock_cached.called) def test_get_target_streams(self): self.assertEqual( len(TagStream.get_target_streams(self.limited_tagged, self.user, self.limited_tagged.author)), 3, ) def test_key(self): self.assertEqual(self.stream.key, "sh:streams:tag:%s:%s" % (self.tag.id, self.user.id)) stream = TagStream(tag=self.tag, user=AnonymousUser()) self.assertEqual(stream.key, "sh:streams:tag:%s:anonymous" % self.tag.id) def test_only_tagged_content_returned(self): qs, _throughs = self.anon_stream.get_content() self.assertEqual( set(qs), {self.public_tagged}, ) qs, _throughs = self.stream.get_content() self.assertEqual( set(qs), {self.public_tagged, self.site_tagged, self.self_tagged, self.limited_tagged}, ) qs, _throughs = self.local_stream.get_content() self.assertEqual( set(qs), {self.public_tagged, self.site_tagged}, ) def test_raises_if_no_user(self): self.stream.user = None with self.assertRaises(AttributeError): self.stream.get_content() def test_raises_if_no_tag(self): self.stream.tag = None with self.assertRaises(AttributeError): self.stream.get_content() def test_should_cache_content(self): # self.user stream self.assertTrue(self.stream.should_cache_content(self.public_tagged)) self.assertTrue(self.stream.should_cache_content(self.site_tagged)) self.assertTrue(self.stream.should_cache_content(self.limited_tagged)) self.assertTrue(self.stream.should_cache_content(self.self_tagged)) self.assertFalse(self.stream.should_cache_content(self.public_content)) self.assertFalse(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)) # anon stream self.assertTrue(self.anon_stream.should_cache_content(self.public_tagged)) self.assertFalse(self.anon_stream.should_cache_content(self.site_tagged)) self.assertFalse(self.anon_stream.should_cache_content(self.limited_tagged)) self.assertFalse(self.anon_stream.should_cache_content(self.self_tagged)) self.assertFalse(self.anon_stream.should_cache_content(self.public_content)) self.assertFalse(self.anon_stream.should_cache_content(self.site_content)) self.assertFalse(self.anon_stream.should_cache_content(self.limited_content)) self.assertFalse(self.anon_stream.should_cache_content(self.self_content)) # self.local_user stream self.assertTrue(self.local_stream.should_cache_content(self.public_tagged)) self.assertTrue(self.local_stream.should_cache_content(self.site_tagged)) self.assertFalse(self.local_stream.should_cache_content(self.limited_tagged)) self.assertFalse(self.local_stream.should_cache_content(self.self_tagged)) self.assertFalse(self.local_stream.should_cache_content(self.public_content)) self.assertFalse(self.local_stream.should_cache_content(self.site_content)) self.assertFalse(self.local_stream.should_cache_content(self.limited_content)) self.assertFalse(self.local_stream.should_cache_content(self.self_content))