def test_on_post_likes_count_change_update_card(card_manager, post, user):
    # configure and check starting state
    assert 'onymousLikeCount' not in post.item
    assert 'anonymousLikeCount' not in post.item
    template = templates.PostLikesCardTemplate(post.user_id, post.id)
    assert card_manager.get_card(template.card_id) is None

    # record a like, verify card is created
    old_item = post.item.copy()
    post.item['anonymousLikeCount'] = 2
    card_manager.on_post_likes_count_change_update_card(post.id, new_item=post.item, old_item=old_item)
    assert card_manager.get_card(template.card_id)

    # delete the card
    card_manager.dynamo.delete_card(template.card_id)
    assert card_manager.get_card(template.card_id) is None

    # record nine likes, verify card is created
    old_item = post.item.copy()
    post.item['onymousLikeCount'] = 7
    card_manager.on_post_likes_count_change_update_card(post.id, new_item=post.item, old_item=old_item)
    assert card_manager.get_card(template.card_id)

    # delete the card
    card_manager.dynamo.delete_card(template.card_id)
    assert card_manager.get_card(template.card_id) is None

    # record a 10th like, verify card is **not** created
    old_item = post.item.copy()
    post.item['anonymousLikeCount'] = 3
    card_manager.on_post_likes_count_change_update_card(post.id, new_item=post.item, old_item=old_item)
    assert card_manager.get_card(template.card_id) is None
Example #2
0
def test_post_likes_card_template(user, post):
    card_id = templates.PostLikesCardTemplate.get_card_id(user.id, post.id)
    assert card_id.split(':') == [user.id, 'POST_LIKES', post.id]

    template = templates.PostLikesCardTemplate(user.id, post.id)
    assert template.card_id == card_id
    assert template.user_id == user.id
    assert template.action == f'https://real.app/user/{user.id}/post/{post.id}/likes'
    assert template.title == 'You have new likes'
    assert not template.only_usernames
    assert template.post_id == post.id
    assert not template.comment_id
def post_likes_card_template(card_manager, post):
    template = templates.PostLikesCardTemplate(post.user_id, post.id)
    card_manager.add_or_update_card(template)
    yield template
Example #4
0
def post_likes_card_template(user, post):
    yield templates.PostLikesCardTemplate(user.id, post.id)