def test_on_post_viewed_by_count_change_update_card(card_manager, post, user):
    # check starting state
    assert 'viewedByCount' not in post.item
    template = templates.PostViewsCardTemplate(post.user_id, post.id)
    assert card_manager.get_card(template.card_id) is None

    # jump up to five views, process, check no card created
    old_item = post.item.copy()
    post.item['viewedByCount'] = 5
    card_manager.on_post_viewed_by_count_change_update_card(post.id, new_item=post.item, old_item=old_item)
    assert card_manager.get_card(template.card_id) is None

    # go to six views, process, check card created
    old_item = post.item.copy()
    post.item['viewedByCount'] = 6
    card_manager.on_post_viewed_by_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

    # jump up to seven views, process, check no card created
    old_item = post.item.copy()
    post.item['viewedByCount'] = 7
    card_manager.on_post_viewed_by_count_change_update_card(post.id, new_item=post.item, old_item=old_item)
    assert card_manager.get_card(template.card_id) is None
示例#2
0
def test_post_views_card_template(user, post):
    card_id = templates.PostViewsCardTemplate.get_card_id(user.id, post.id)
    assert card_id.split(':') == [user.id, 'POST_VIEWS', post.id]

    template = templates.PostViewsCardTemplate(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}/views'
    assert template.title == 'You have new views'
    assert not template.only_usernames
    assert template.post_id == post.id
    assert not template.comment_id
def post_views_card_template(card_manager, post):
    template = templates.PostViewsCardTemplate(post.user_id, post.id)
    card_manager.add_or_update_card(template)
    yield template
示例#4
0
def post_views_card_template(user, post):
    yield templates.PostViewsCardTemplate(user.id, post.id)