def test_all_unread(db, redis): """After marking a post unread, it shows up in all_unread set.""" post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post, profile) assert unread.all_unread(post.student, profile) == {str(post.id)}
def test_unread(db, redis): """After marking a post unread, it shows up as unread.""" post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post, profile) assert unread.is_unread(post, profile)
def test_mark_read(db, redis): """Can mark a post as read.""" post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post, profile) unread.mark_read(post, profile) assert not unread.is_unread(post, profile)
def test_unread_count(db, redis): post1 = factories.PostFactory.create() factories.PostFactory.create(student=post1.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(other_village_post, profile) # Only post1; the second is read, and other is wrong village assert unread.unread_count(post1.student, profile) == 1
def test_unread_count(self, no_csrf_client): """Each post has an unread boolean in the API response.""" rel = factories.RelationshipFactory.create() post = factories.PostFactory.create(student=rel.student) unread.mark_unread(post, rel.elder) response = no_csrf_client.get( self.detail_url(post), user=rel.elder.user) assert response.json['unread'] == True
def test_unread_count(self, no_csrf_client): """Each profile has an unread_count in the API response.""" rel = factories.RelationshipFactory.create( from_profile__school_staff=True) post = factories.PostFactory.create(student=rel.student) unread.mark_unread(post, rel.elder) response = no_csrf_client.get( self.list_url() + '?elders=%s' % rel.elder.pk, user=rel.elder.user, ) assert [o['unread_count'] for o in response.json['objects']] == [1]
def test_unread_count(self, no_csrf_client): """Each group has an unread_count in the API response.""" rel = factories.RelationshipFactory.create() post = factories.PostFactory.create(student=rel.student) other_rel = factories.RelationshipFactory.create(from_profile=rel.elder) other_post = factories.PostFactory.create(student=other_rel.student) group = factories.GroupFactory.create(owner=rel.elder) group.students.add(rel.student) group.students.add(other_rel.student) unread.mark_unread(post, rel.elder) unread.mark_unread(other_post, rel.elder) response = no_csrf_client.get(self.list_url(), user=rel.elder.user) assert response.json['objects'][1]['unread_count'] == 2 # all-students group also has unread count assert response.json['objects'][0]['unread_count'] == 2
def test_unread_count_prefetched(self, no_csrf_client, redis): """Unread counts are prefetched in a single Redis query.""" rel = factories.RelationshipFactory.create() post = factories.PostFactory.create(student=rel.student) other_rel = factories.RelationshipFactory.create(from_profile=rel.elder) other_post = factories.PostFactory.create(student=other_rel.student) group = factories.GroupFactory.create(owner=rel.elder) group.students.add(rel.student) group.students.add(other_rel.student) unread.mark_unread(post, rel.elder) unread.mark_unread(other_post, rel.elder) with utils.assert_num_calls(redis, 1): response = no_csrf_client.get(self.list_url(), user=rel.elder.user) assert response.json['objects'][1]['unread_count'] == 2 # all-students group also has unread count assert response.json['objects'][0]['unread_count'] == 2
def test_unread_count_prefetched(self, no_csrf_client, redis): """Unread counts for all profiles fetched in single Redis query.""" rel = factories.RelationshipFactory.create( from_profile__school_staff=True) rel2 = factories.RelationshipFactory.create( from_profile=rel.elder) post = factories.PostFactory.create(student=rel.student) post2 = factories.PostFactory.create(student=rel2.student) unread.mark_unread(post, rel.elder) unread.mark_unread(post2, rel.elder) with utils.assert_num_calls(redis, 1): response = no_csrf_client.get( self.list_url() + '?elders=%s' % rel.elder.pk, user=rel.elder.user, ) assert [o['unread_count'] for o in response.json['objects']] == [1, 1]
def test_unread_counts(db, redis): post1 = factories.PostFactory.create() factories.PostFactory.create(student=post1.student) post2 = factories.PostFactory.create() post3 = factories.PostFactory.create(student=post2.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(post2, profile) unread.mark_unread(post3, profile) unread.mark_unread(other_village_post, profile) assert unread.unread_counts([post1.student, post2.student], profile) == { post1.student: 1, post2.student: 2}
def test_unread_counts(db, redis): post1 = factories.PostFactory.create() factories.PostFactory.create(student=post1.student) post2 = factories.PostFactory.create() post3 = factories.PostFactory.create(student=post2.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(post2, profile) unread.mark_unread(post3, profile) unread.mark_unread(other_village_post, profile) assert unread.unread_counts([post1.student, post2.student], profile) == { post1.student: 1, post2.student: 2 }
def test_group_unread_count(db, redis): post1 = factories.PostFactory.create() factories.PostFactory.create(student=post1.student) post2 = factories.PostFactory.create() group = factories.GroupFactory.create() group.students.add(post1.student, post2.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(post2, profile) unread.mark_unread(other_village_post, profile) assert unread.group_unread_count(group, profile) == 2
def test_mark_village_read(db, redis): """Marks posts only in given village read.""" post1 = factories.PostFactory.create() post2 = factories.PostFactory.create(student=post1.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(post2, profile) unread.mark_unread(other_village_post, profile) unread.mark_village_read(post1.student, profile) assert not unread.is_unread(post1, profile) assert not unread.is_unread(post2, profile) assert unread.is_unread(other_village_post, profile)
def test_group_unread_counts(db, redis): post1 = factories.PostFactory.create() factories.PostFactory.create(student=post1.student) post2 = factories.PostFactory.create() post3 = factories.PostFactory.create() post4 = factories.PostFactory.create(student=post3.student) post5 = factories.PostFactory.create() factories.PostFactory.create(student=post5.student) groupa = factories.GroupFactory.create() groupa.students.add(post1.student, post2.student) groupb = factories.GroupFactory.create() groupb.students.add(post3.student, post5.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(post2, profile) unread.mark_unread(post3, profile) unread.mark_unread(post4, profile) unread.mark_unread(post5, profile) unread.mark_unread(other_village_post, profile) assert unread.group_unread_counts([groupa, groupb], profile) == { groupa: 2, groupb: 3}
def test_group_unread_counts(db, redis): post1 = factories.PostFactory.create() factories.PostFactory.create(student=post1.student) post2 = factories.PostFactory.create() post3 = factories.PostFactory.create() post4 = factories.PostFactory.create(student=post3.student) post5 = factories.PostFactory.create() factories.PostFactory.create(student=post5.student) groupa = factories.GroupFactory.create() groupa.students.add(post1.student, post2.student) groupb = factories.GroupFactory.create() groupb.students.add(post3.student, post5.student) other_village_post = factories.PostFactory.create() profile = factories.ProfileFactory.create() unread.mark_unread(post1, profile) unread.mark_unread(post2, profile) unread.mark_unread(post3, profile) unread.mark_unread(post4, profile) unread.mark_unread(post5, profile) unread.mark_unread(other_village_post, profile) assert unread.group_unread_counts([groupa, groupb], profile) == { groupa: 2, groupb: 3 }