示例#1
0
def test_three_likes():
    u = make_user()
    liker1 = make_user(name="Liker One")
    liker2 = make_user(name="Liker Two")
    liker3 = make_user(name="Liker Three")
    feedentry = make_feedentry(user_id=u.id, caption="My Post")
    like1 = make_liked(user_id=u.id,
                       liker_id=liker1.id,
                       feedentry_id=feedentry.id)
    like2 = make_liked(user_id=u.id,
                       liker_id=liker2.id,
                       feedentry_id=feedentry.id)
    like3 = make_liked(user_id=u.id,
                       liker_id=liker3.id,
                       feedentry_id=feedentry.id)
    repo = FakeRepo(u, liker1, liker2, liker3, feedentry, like1, like2, like3)
    box = inbox.Inbox(u, repo)

    assert (box.aggregate() == [
        models.AggregatedItem(
            type=models.EventType.LIKED,
            text='Liker One, Liker Two and 1 others liked your post "My Post".',
            published=like3.published,
        )
    ])
    assert box.summarize() == "You have 3 new likes."
示例#2
0
def test_everything():
    u = make_user()
    other = make_user(name="Other", following=[u.id])
    first_entry = make_feedentry(user_id=u.id, caption="My First Post")
    follow = make_followed(user_id=u.id, follower_id=other.id)
    second_entry = make_feedentry(user_id=u.id, caption="Second Post")
    like1 = make_liked(user_id=u.id,
                       liker_id=other.id,
                       feedentry_id=first_entry.id)
    comment = make_commented(user_id=u.id,
                             commenter_id=other.id,
                             feedentry_id=first_entry.id)
    like2 = make_liked(user_id=u.id,
                       liker_id=other.id,
                       feedentry_id=second_entry.id)
    repo = FakeRepo(u, other, first_entry, second_entry, like1, like2, comment,
                    follow)
    box = inbox.Inbox(u, repo)

    assert (box.aggregate() == [
        models.AggregatedItem(
            type=models.EventType.LIKED,
            text='Other liked your post "Second Post".',
            published=like2.published,
        ),
        models.AggregatedItem(
            type=models.EventType.COMMENTED,
            text="Other commented on your post.",
            published=comment.published,
        ),
        models.AggregatedItem(
            type=models.EventType.LIKED,
            text='Other liked your post "My First Post".',
            published=like1.published,
        ),
        models.AggregatedItem(
            type=models.EventType.FOLLOWED,
            text="Other started following you.",
            published=follow.published,
        ),
    ])
    assert box.summarize(
    ) == "You have 2 new likes, 1 new follower and 1 new comment."
示例#3
0
def test_followed():
    u = make_user()
    other = make_user(name="Follower", following=[u.id])
    event = make_followed(user_id=u.id, follower_id=other.id)
    repo = FakeRepo(u, other, event)
    box = inbox.Inbox(u, repo)

    assert (box.aggregate() == [
        models.AggregatedItem(
            type=models.EventType.FOLLOWED,
            text="Follower started following you.",
            published=event.published,
        )
    ])
    assert box.summarize() == "You have 1 new follower."
示例#4
0
def test_one_like():
    u = make_user()
    liker = make_user(name="Liker")
    feedentry = make_feedentry(user_id=u.id, caption="My Post")
    event = make_liked(user_id=u.id,
                       liker_id=liker.id,
                       feedentry_id=feedentry.id)
    repo = FakeRepo(u, liker, feedentry, event)
    box = inbox.Inbox(u, repo)

    assert (box.aggregate() == [
        models.AggregatedItem(
            type=models.EventType.LIKED,
            text='Liker liked your post "My Post".',
            published=event.published,
        )
    ])
    assert box.summarize() == "You have 1 new like."
示例#5
0
def test_commented():
    u = make_user()
    other = make_user(name="Commenter")
    feedentry = make_feedentry(user_id=u.id)
    commented = make_commented(user_id=u.id,
                               feedentry_id=feedentry.id,
                               commenter_id=other.id)
    repo = FakeRepo(u, other, feedentry, commented)
    box = inbox.Inbox(u, repo)

    assert (box.aggregate() == [
        models.AggregatedItem(
            type=models.EventType.COMMENTED,
            text="Commenter commented on your post.",
            published=commented.published,
        )
    ])
    assert box.summarize() == "You have 1 new comment."