Esempio n. 1
0
def test_on_first_story_post_id_change_fire_gql_notifications(follower_manager, users, their_post):
    # create a followed first story item to test with
    our_user, their_user = users
    follower_manager.first_story_dynamo.set_all(iter([our_user.id]), their_post.item)
    fs_key = follower_manager.first_story_dynamo.key(their_user.id, our_user.id)
    fs_item = follower_manager.first_story_dynamo.client.get_item(fs_key)

    # trigger for item creation, verify calls
    with patch.object(follower_manager, 'appsync_client') as appsync_client_mock:
        follower_manager.on_first_story_post_id_change_fire_gql_notifications(their_user.id, new_item=fs_item)
    assert appsync_client_mock.mock_calls == [
        call.fire_notification(
            our_user.id,
            GqlNotificationType.USER_FOLLOWED_USERS_WITH_STORIES_CHANGED,
            postId=their_post.id,
            followedUserId=their_user.id,
        )
    ]

    # trigger for item update, verify calls
    new_post_id = str(uuid4())
    new_item = {**fs_item, 'postId': new_post_id}
    with patch.object(follower_manager, 'appsync_client') as appsync_client_mock:
        follower_manager.on_first_story_post_id_change_fire_gql_notifications(
            their_user.id, new_item=new_item, old_item=fs_item
        )
    assert appsync_client_mock.mock_calls == [
        call.fire_notification(
            our_user.id,
            GqlNotificationType.USER_FOLLOWED_USERS_WITH_STORIES_CHANGED,
            postId=new_post_id,
            followedUserId=their_user.id,
        )
    ]

    # trigger for item delete, verify calls
    with patch.object(follower_manager, 'appsync_client') as appsync_client_mock:
        follower_manager.on_first_story_post_id_change_fire_gql_notifications(their_user.id, old_item=fs_item)
    assert appsync_client_mock.mock_calls == [
        call.fire_notification(
            our_user.id,
            GqlNotificationType.USER_FOLLOWED_USERS_WITH_STORIES_CHANGED,
            followedUserId=their_user.id,
        )
    ]
Esempio n. 2
0
def test_on_post_status_change_sync_feed_post_completed(feed_manager, post):
    assert post.item['postStatus'] == PostStatus.COMPLETED
    user_ids = [str(uuid4()), str(uuid4())]
    with patch.object(feed_manager,
                      'add_post_to_followers_feeds',
                      return_value=user_ids) as add_post_mock:
        with patch.object(feed_manager, 'dynamo') as dynamo_mock:
            with patch.object(feed_manager,
                              'appsync_client') as appsync_client_mock:
                feed_manager.on_post_status_change_sync_feed(
                    post.id, new_item=post.item)
    assert add_post_mock.mock_calls == [call(post.user_id, post.item)]
    assert dynamo_mock.mock_calls == []
    assert appsync_client_mock.mock_calls == [
        call.fire_notification(user_ids[0],
                               GqlNotificationType.USER_FEED_CHANGED),
        call.fire_notification(user_ids[1],
                               GqlNotificationType.USER_FEED_CHANGED),
    ]
Esempio n. 3
0
def test_on_post_status_change_sync_feed_post_uncompleted(
        feed_manager, post, status):
    old_item = {**post.item, 'postStatus': 'COMPLETED'}
    new_item = {**post.item, 'postStatus': status}
    user_ids = [str(uuid4()), str(uuid4())]
    with patch.object(feed_manager,
                      'add_post_to_followers_feeds') as add_post_mock:
        with patch.object(feed_manager, 'dynamo',
                          **{'delete_by_post.return_value':
                             user_ids}) as dynamo_mock:
            with patch.object(feed_manager,
                              'appsync_client') as appsync_client_mock:
                feed_manager.on_post_status_change_sync_feed(post.id,
                                                             new_item=new_item,
                                                             old_item=old_item)
    assert add_post_mock.mock_calls == []
    assert dynamo_mock.mock_calls == [call.delete_by_post(post.id)]
    assert appsync_client_mock.mock_calls == [
        call.fire_notification(user_ids[0],
                               GqlNotificationType.USER_FEED_CHANGED),
        call.fire_notification(user_ids[1],
                               GqlNotificationType.USER_FEED_CHANGED),
    ]
Esempio n. 4
0
def test_on_user_follow_status_change_sync_feed_stops_following(
        feed_manager, follower, user1, user2, status):
    follower.item['followStatus'] = status
    with patch.object(
            feed_manager,
            'add_users_posts_to_feed') as add_users_posts_to_feed_mock:
        with patch.object(feed_manager, 'dynamo') as dynamo_mock:
            with patch.object(feed_manager,
                              'appsync_client') as appsync_client_mock:
                feed_manager.on_user_follow_status_change_sync_feed(
                    user2.id, new_item=follower.item)
    assert add_users_posts_to_feed_mock.mock_calls == []
    assert dynamo_mock.mock_calls == [
        call.delete_by_post_owner(user1.id, user2.id)
    ]
    assert appsync_client_mock.mock_calls == [
        call.fire_notification(user1.id,
                               GqlNotificationType.USER_FEED_CHANGED),
    ]