Exemplo n.º 1
0
def test_text_comment_list_view_with_various_lengths(
    client,
    django_user_model,
    mocker,
    text_comment_count,
):
    """
    Simple test that lists all text comments for a given track.
    """
    TextComment = apps.get_model("comments", "TextComment")

    # 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_comments = []
    for idx in range(text_comment_count):
        text_comment = TextComment.objects.create(
            user=user,
            format=TextComment.FORMAT_TEXT,
            text="Hello, world!",
            track_id=track.uuid,
            timestamp_ms=4200 + idx,
        )
        assert not text_comment.deleted_at
        text_comments.append(text_comment)

    # List comments
    response_json = response.json()
    url = reverse("comments:text-comment-list")
    data = {"trackUuid": track.uuid}
    response = client.get(url, data)

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

    assert response_json["redux"]["type"] == "textComment/listSet"
    response_text_comments = response_json["redux"]["payload"]["textComments"]

    # This also asserts that the comments are in the expected order
    assert len(response_text_comments) == text_comment_count
    for idx in range(text_comment_count):
        assert response_text_comments[idx]["uuid"] == str(
            text_comments[idx].uuid)
Exemplo n.º 2
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
def test_marker_create_view_happy_path(
    client,
    django_user_model,
    mocker,
):
    """
    Simple case for creating a text comment through the API.
    """
    Marker = apps.get_model("streams", "Marker")

    # 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
    url = reverse("streams:marker-create")
    data = {
        "trackUuid": str(track.uuid),
        "timestampMilliseconds": 420,
        "queueUuid": "foobarbaz",  # Yes, this is on purpose!
        "name": "fooname",
    }
    response = client.post(url, data)

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

    payload = response_json["redux"]["payload"]
    marker = Marker.objects.get(uuid=payload["marker"]["uuid"])
    assert payload["marker"]["uuid"] == str(marker.uuid)
    assert payload["marker"]["name"] == data["name"]
    assert payload["marker"]["trackUuid"] == data["trackUuid"]
    # cast json response to int to match original payload
    assert (int(payload["marker"]["timestampMilliseconds"]) ==
            data["timestampMilliseconds"])

    # Assert database entry
    assert marker.user_id == user.id
    assert marker.name == data["name"]
    assert str(marker.track_id) == data["trackUuid"]
    assert marker.timestamp_ms == data["timestampMilliseconds"]
    assert not marker.deleted_at
Exemplo n.º 4
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
def test_text_comment_delete_view_happy_path(
    client,
    django_user_model,
    mocker,
):
    """
    Simple case for deleting (archiving) a text comment through the API.
    """
    TextComment = apps.get_model("comments", "TextComment")

    # 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

    # Delete comment
    url = reverse("comments:text-comment-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

    text_comment.refresh_from_db()
    assert text_comment.deleted_at
Exemplo n.º 6
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
def test_text_comment_modification_create_view_happy_path(
    client,
    django_user_model,
    mocker,
):
    """
    Simple test that lists all text comments for a given track.
    """
    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
    url = reverse("comments:text-comment-modification-create")
    data = {
        "textCommentUuid": text_comment.uuid,
        "style": TextCommentModification.STYLE_BOLD,
        "anchorOffset": 0,
        "focusOffset": 5,
    }
    response = client.post(url, data)

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

    assert response_json["redux"]["type"] == "textCommentModification/create"
    payload = response_json["redux"]["payload"]

    assert payload["textCommentUuid"] == str(text_comment.uuid)

    # Meaning, no modifications were deleted
    assert not payload["textCommentModifications"]["deleted"]

    TextCommentModification.objects.get(
        uuid=payload["textCommentModifications"]["modified"]["uuid"],
        user=user,
        text_comment=text_comment,
        start_ptr=data["anchorOffset"],
        end_ptr=data["focusOffset"],
        style=data["style"],
        deleted_at__isnull=True,
    )
Exemplo n.º 8
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