def test_when_get_post_list_pagination_then_success(session,
                                                    normal_user_factory,
                                                    create_categories,
                                                    add_and_commit):
    """
    post list 조회 시 페이지네이션
    """
    user = normal_user_factory(Region=True, UserProfile=True)
    add_and_commit([user])

    categories = create_categories(PostCategoryEnum.get_dict())

    post_list = PostFactory.create_batch(
        size=11,
        Article=True,
        Categories=categories,
        region_group_id=user.region.region_group.id,
        user_id=user.id,
    )
    add_and_commit(post_list)

    dto = GetPostListDto(
        region_group_id=user.region.region_group.id,
        previous_post_id=len(post_list) % PostLimitEnum.LIMIT.value + 1,
        category_ids=[categories[0].id],
    )
    post_list = GetPostListUseCase().execute(dto=dto).value

    assert len(post_list) == 1
    assert post_list[0].region_group_name == user.region.region_group.name
Beispiel #2
0
def get_post_list_view():
    dto = GetPostListRequest(
        **request.get_json()).validate_request_and_make_dto()
    if not dto:
        return failure_response(
            UseCaseFailureOutput(type=FailureType.INVALID_REQUEST_ERROR))

    return PostListPresenter().transform(GetPostListUseCase().execute(dto=dto))
def test_when_get_empty_post_list_then_empty_list(session, normal_user_factory,
                                                  create_categories,
                                                  add_and_commit):
    user = normal_user_factory(Region=True, UserProfile=True)
    add_and_commit([user])

    categories = create_categories(PostCategoryEnum.get_dict())

    dto = GetPostListDto(region_group_id=user.region.region_group.id,
                         category_ids=[categories[0].id])
    result = GetPostListUseCase().execute(dto=dto).value

    assert result == []
def test_when_get_post_list_order_by_desc_then_success(session,
                                                       normal_user_factory,
                                                       create_categories,
                                                       post_factory,
                                                       add_and_commit):
    """
    판매중, 거래완료 최신순으로 조회
    """
    user = normal_user_factory.build(Region=True, UserProfile=True)
    add_and_commit([user])

    categories = create_categories(PostCategoryEnum.get_dict())

    region_group_id = user.region.region_group_id

    post1 = post_factory(
        Article=True,
        Categories=[categories[0]],
        region_group_id=region_group_id,
        user_id=user.id,
        status=PostStatusEnum.SELLING.value,
    )
    post2 = post_factory(
        Article=True,
        Categories=[categories[0]],
        region_group_id=region_group_id,
        user_id=user.id,
        status=PostStatusEnum.COMPLETED.value,
    )
    post3 = post_factory(
        Article=True,
        Categories=[categories[0]],
        region_group_id=region_group_id,
        user_id=user.id,
        status=PostStatusEnum.COMPLETED.value,
    )
    add_and_commit([post1, post2, post3])

    dto = GetPostListDto(
        region_group_id=user.region.region_group_id,
        category_ids=[categories[0].id],
        status=PostStatusEnum.ALL.value,
    )

    post_list = GetPostListUseCase().execute(dto=dto).value

    assert len(post_list) == 3
    assert post_list[0].id == 3
    assert post_list[1].id == 2
    assert post_list[2].id == 1
def test_when_get_post_list_then_include_like_count_and_exclude_like_state(
    session,
    normal_user_factory,
    post_factory,
    like_post,
    create_categories,
    add_and_commit,
):
    """
    post list 조회 시 찜 개수 포함, 찜 상태 제외
    user1 -> post1 찜
    user2 -> post1 찜
    user2 -> post2 찜
    """
    user1 = normal_user_factory(Region=True, UserProfile=True)
    user2 = normal_user_factory(Region=True, UserProfile=True)
    add_and_commit([user1, user2])

    categories = create_categories(PostCategoryEnum.get_dict())

    post1 = post_factory(
        Article=True,
        PostLikeCount=True,
        Categories=categories,
        region_group_id=user1.region.region_group.id,
        user_id=user1.id,
    )
    post2 = post_factory(
        Article=True,
        PostLikeCount=True,
        Categories=categories,
        region_group_id=user1.region.region_group.id,
        user_id=user1.id,
    )
    add_and_commit([post1, post2])

    # 찜하기
    like_post(user_id=user1.id, post_id=post1.id)
    like_post(user_id=user2.id, post_id=post1.id)
    like_post(user_id=user2.id, post_id=post2.id)

    dto = GetPostListDto(
        region_group_id=user1.region.region_group.id,
        category_ids=[categories[0].id],
    )
    post_list = GetPostListUseCase().execute(dto=dto).value

    assert len(post_list) == 2
    assert post_list[0].post_like_count == 1
    assert post_list[1].post_like_count == 2
def test_when_get_post_list_then_success(session, normal_user_factory,
                                         post_factory, create_categories,
                                         add_and_commit):
    """
    post list 조회 시 region에 맞는 관련 table 목록 가져옴.
    """
    user = normal_user_factory(Region=True, UserProfile=True)
    add_and_commit([user])

    categories = create_categories(PostCategoryEnum.get_dict())

    post1 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user.region.region_group.id,
        user_id=user.id,
    )
    post2 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user.region.region_group.id,
        user_id=user.id,
    )

    user2 = normal_user_factory(Region=True, UserProfile=True)
    add_and_commit([user2])
    post3 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user2.region.region_group.id,
        user_id=user2.id,
    )
    post4 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user2.region.region_group.id,
        user_id=user2.id,
    )

    add_and_commit([post1, post2, post3, post4])

    dto = GetPostListDto(
        region_group_id=user.region.region_group.id,
        category_ids=[categories[0].id],
    )
    post_list = GetPostListUseCase().execute(dto=dto).value

    assert len(post_list) == 2
    for post in post_list:
        post.region_group_name = user.region.region_group.name
def test_when_get_post_list_by_status(
    post_status,
    input_status,
    result_count,
    session,
    normal_user_factory,
    post_factory,
    create_categories,
    add_and_commit,
):
    """
    post list 조회 시 판매중, 거래완료 상태에 따라 응답
    """
    user = normal_user_factory.build(Region=True, UserProfile=True)
    add_and_commit([user])

    region_group_id = user.region.region_group_id

    categories = create_categories(PostCategoryEnum.get_dict())

    post1 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user.id,
    )
    post2 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user.id,
        status=post_status,
    )

    add_and_commit([post1, post2])

    dto = GetPostListDto(
        region_group_id=region_group_id,
        category_ids=[categories[0].id],
        status=input_status,
    )

    post_list = GetPostListUseCase().execute(dto=dto).value

    assert len(post_list) == result_count
def test_when_deleted_or_blocked_post_then_except(session, normal_user_factory,
                                                  post_factory,
                                                  create_categories,
                                                  add_and_commit):
    """
    post list 조회 시 삭제, 차단된 게시글 제외
    """
    user = normal_user_factory(Region=True, UserProfile=True)
    add_and_commit([user])

    categories = create_categories(PostCategoryEnum.get_dict())

    post = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user.region.region_group.id,
        user_id=user.id,
    )
    deleted_post = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user.region.region_group.id,
        user_id=user.id,
        is_deleted=True,
    )
    blocked_post = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user.region.region_group.id,
        user_id=user.id,
        is_blocked=True,
    )

    add_and_commit([post, deleted_post, blocked_post])

    dto = GetPostListDto(
        region_group_id=user.region.region_group.id,
        category_ids=[categories[0].id],
    )
    post_list = GetPostListUseCase().execute(dto=dto).value

    assert len(post_list) == 1
def test_when_search_post_list_then_success(session, normal_user_factory,
                                            post_factory, create_categories,
                                            add_and_commit):
    """
    post 검색. user1 post 2개, user2 post 2개, user3 post 1개, 다른 지역 user4 post 1개
    총 5개 post 응답
    """
    user_list = normal_user_factory.build_batch(size=4,
                                                Region=True,
                                                UserProfile=True)
    add_and_commit(user_list)

    region_group_id = user_list[0].region.region_group_id

    categories = create_categories(PostCategoryEnum.get_dict())

    post1 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user_list[0].id,
    )
    post2 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user_list[0].id,
    )
    post3 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user_list[1].id,
    )
    post4 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user_list[1].id,
    )
    post5 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=region_group_id,
        user_id=user_list[2].id,
    )
    post6 = post_factory(
        Article=True,
        Categories=categories,
        region_group_id=user_list[3].region.region_group_id,
        user_id=user_list[3].id,
    )

    add_and_commit([post1, post2, post3, post4, post5, post6])

    dto = GetPostListDto(
        region_group_id=region_group_id,
        title=post1.title[2:6],
        category_ids=[categories[0].id],
    )

    post_list = GetPostListUseCase().execute(dto=dto).value

    for post in post_list:
        assert post.region_group_id == region_group_id
        assert post1.title[2:6] in post.title
    assert len(post_list) == 5