Exemplo n.º 1
0
def test_text_comment_modification_create_modification(django_user_model, ptrs,
                                                       modification_count,
                                                       archived_count):
    """
    Test the custom create method. When creating, existing overlapping objects
    should be condensed.
    """
    TextComment = apps.get_model("comments", "TextComment")
    TextCommentModification = apps.get_model("comments",
                                             "TextCommentModification")

    # Initialize user
    credentials = {
        "username": "******",
        "password": "******",
    }
    user = django_user_model.objects.create_user(**credentials)

    # Create a track object
    track = create_test_track()

    text_comment = TextComment.objects.create(
        user=user,
        format=TextComment.FORMAT_TEXT,
        text="0123456789",
        track_id=track.uuid,
        timestamp_ms=4200,
    )

    style = TextCommentModification.STYLE_BOLD
    with pgtrigger.ignore("comments.TextCommentModification:protect_inserts"):
        for (start_ptr, end_ptr) in ptrs:
            TextCommentModification.objects.create(
                user=user,
                text_comment_id=text_comment.uuid,
                start_ptr=start_ptr,
                end_ptr=end_ptr,
                style=style,
            )

    TextCommentModification.objects.create_modification(
        user=user,
        text_comment_id=text_comment.uuid,
        start_ptr=3,
        end_ptr=7,
        style=style,
    )

    actual_modification_count = TextCommentModification.objects.filter(
        deleted_at__isnull=True).count()
    assert actual_modification_count == modification_count

    actual_archived_count = TextCommentModification.objects.filter(
        deleted_at__isnull=False).count()
    assert actual_archived_count == archived_count
Exemplo n.º 2
0
def test_text_comment_modification_get_container(
    django_user_model,
    start_ptr,
    end_ptr,
    expected_result,
):
    """
    Verify finding the "container" interval with all possible combinations. The
    container modification would be an existing modification that is the same
    or larger than the proposed one.
    """
    TextComment = apps.get_model("comments", "TextComment")
    TextCommentModification = apps.get_model("comments",
                                             "TextCommentModification")

    # Initialize user
    credentials = {
        "username": "******",
        "password": "******",
    }
    user = django_user_model.objects.create_user(**credentials)

    # Create a track object
    track = create_test_track()

    text_comment = TextComment.objects.create(
        user=user,
        format=TextComment.FORMAT_TEXT,
        text="0123456789",
        track_id=track.uuid,
        timestamp_ms=4200,
    )

    style = TextCommentModification.STYLE_BOLD
    with pgtrigger.ignore("comments.TextCommentModification:protect_inserts"):
        TextCommentModification.objects.create(
            user=user,
            text_comment_id=text_comment.uuid,
            start_ptr=3,
            end_ptr=7,
            style=style,
        )

    contained = TextCommentModification.objects.get_container(
        user=user,
        text_comment_id=text_comment.uuid,
        start_ptr=start_ptr,
        end_ptr=end_ptr,
        style=style,
    )
    assert bool(contained) == expected_result
Exemplo n.º 3
0
def test_text_comment_modification_get_upper_overlap(
    django_user_model,
    start_ptr,
    end_ptr,
    expected_result,
):
    """
    Verify each case validate expected upper bound overlap.
    """
    TextComment = apps.get_model("comments", "TextComment")
    TextCommentModification = apps.get_model("comments",
                                             "TextCommentModification")

    # Initialize user
    credentials = {
        "username": "******",
        "password": "******",
    }
    user = django_user_model.objects.create_user(**credentials)

    # Create a track object
    track = create_test_track()

    text_comment = TextComment.objects.create(
        user=user,
        format=TextComment.FORMAT_TEXT,
        text="0123456789",
        track_id=track.uuid,
        timestamp_ms=4200,
    )

    style = TextCommentModification.STYLE_BOLD
    with pgtrigger.ignore("comments.TextCommentModification:protect_inserts"):
        TextCommentModification.objects.create(
            user=user,
            text_comment_id=text_comment.uuid,
            start_ptr=3,
            end_ptr=7,
            style=style,
        )

    upper_overlap = TextCommentModification.objects.get_upper_overlap(
        user=user,
        text_comment_id=text_comment.uuid,
        start_ptr=start_ptr,
        end_ptr=end_ptr,
        style=style,
    )
    assert bool(upper_overlap) == expected_result
Exemplo n.º 4
0
def test_text_comment_modification_list_delete_view_happy_path(
    client,
    django_user_model,
    mocker,
    text_comment_modification_count,
):
    """
    Assert that /comments/text-comment/create/ only allows requests of type
    PUT.
    """
    TextComment = apps.get_model("comments", "TextComment")
    TextCommentModification = apps.get_model("comments",
                                             "TextCommentModification")

    # Initialize user
    credentials = {
        "username": "******",
        "password": "******",
    }
    user = django_user_model.objects.create_user(**credentials)

    # Login
    response = client.login(**credentials)

    # Initialize stream
    url = reverse("streams:stream-initialize")
    response = client.post(url)

    # Create a track object
    track = create_test_track()

    # Create comment
    text_comment = TextComment.objects.create(
        user=user,
        format=TextComment.FORMAT_TEXT,
        text="Hello, world!",
        track_id=track.uuid,
        timestamp_ms=4200,
    )
    assert not text_comment.deleted_at

    # Create text comment modification
    with pgtrigger.ignore("comments.TextCommentModification:protect_inserts"):
        text_comment_modifications = []
        for idx in range(text_comment_modification_count):
            text_comment_modification = TextCommentModification.objects.create(
                user=user,
                text_comment=text_comment,
                start_ptr=(idx * 2),
                end_ptr=(idx * 2 + 2),
                style=TextCommentModification.STYLE_BOLD,
            )
            assert not text_comment_modification.deleted_at
            text_comment_modifications.append(text_comment_modification)

    # Create text comment modification
    url = reverse("comments:text-comment-modification-list-delete")
    data = {
        "textCommentUuid": text_comment.uuid,
    }
    response = client.post(url, data)

    # Verify response
    response_json = response.json()
    assert response_json["system"]["status"] == 200
    assert False

    for text_comment_modification in text_comment_modifications:
        text_comment_modification.refresh_from_db()
        assert text_comment_modification.deleted_at