Exemplo n.º 1
0
def test_lti_playlist_portability_video(page: Page, live_server: LiveServer):
    """Test LTI playlist portability."""
    page, video = _preview_video(live_server, page, video_uploaded=True)

    new_playlist = PlaylistFactory(consumer_site=video.consumer_site, )

    page.click("text=Playlist")

    content = page.text_content("[role=heading]")
    assert (
        content ==
        f"Belongs to playlist {video.playlist.title} ({video.playlist.id})")
    page.fill('[placeholder="Paste playlist id"]', str(new_playlist.id))

    page.click('[aria-label="add share"]')

    # wait for request done
    with page.expect_response(f"**/api/playlists/{video.playlist.id}/"):
        print("put done")

    assert video.playlist.portable_to.get(id=new_playlist.id)
    page.text_content(f"[aria-label='Shared with {new_playlist.title}']")
    page.text_content('[role="status"]:has-text("Playlist updated")')

    # go to new_playlist LTI select view
    lti_consumer_parameters = {
        "roles": random.choice(["instructor", "administrator"]),
        "content_item_return_url": f"{live_server.url}/development/",
        "context_id": new_playlist.lti_id,
        "lti_message_type": "ContentItemSelectionRequest",
        "lti_version": "LTI-1p0",
        "title": "",
        "text": "",
    }
    lti_parameters, passport = generate_passport_and_signed_lti_parameters(
        url=f"{live_server.url}/lti/select/",
        lti_parameters=lti_consumer_parameters,
        passport_attributes={"consumer_site": video.playlist.consumer_site},
    )

    page.goto(f"{live_server.url}/development/")
    lti_select_form = page.query_selector("#lti_select")
    for key, value in lti_parameters.items():
        if key in ("roles", ):
            lti_select_form.query_selector(
                f'select[name="{key}"]').select_option(value)
        else:
            lti_select_form.query_selector(f'input[name="{key}"]').fill(value)
    page.click('#lti_select input[type="submit"]')

    # ensure video is available in new_playlist
    lti_select_iframe = page.frame("lti_select")
    lti_select_iframe.click('button[role="tab"]:has-text("Videos")')
    lti_select_iframe.text_content(f'[title="Select {video.title}"]')
Exemplo n.º 2
0
def test_lti_select_bbb_enabled(page: Page, live_server: LiveServer, settings):
    """Test LTI select."""
    settings.BBB_ENABLED = True
    lti_consumer_parameters = {
        "roles": random.choice(["instructor", "administrator"]),
        "content_item_return_url": f"{live_server.url}/development/",
        "context_id": "sent_lti_context_id",
        "lti_message_type": "ContentItemSelectionRequest",
        "lti_version": "LTI-1p0",
    }
    lti_parameters, passport = generate_passport_and_signed_lti_parameters(
        url=f"{live_server.url}/lti/select/",
        lti_parameters=lti_consumer_parameters,
    )

    playlist = PlaylistFactory(
        lti_id=lti_parameters.get("context_id"),
        consumer_site=passport.consumer_site,
    )
    meeting = MeetingFactory(playlist=playlist, )

    page.goto(f"{live_server.url}/development/")
    lti_select_form = page.query_selector("#lti_select")
    for key, value in lti_parameters.items():
        if key in ("roles", ):
            lti_select_form.query_selector(
                f'select[name="{key}"]').select_option(value)
        else:
            lti_select_form.query_selector(f'input[name="{key}"]').fill(value)
    page.click('#lti_select input[type="submit"]')

    lti_select_iframe = page.frame("lti_select")

    # Select a meeting
    lti_select_iframe.click('button[role="tab"]:has-text("Meetings")')
    meeting_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server.url}/lti/meetings/{meeting.id}",
            "title": f"{meeting.title}",
            "frame": [],
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert meeting_content_items not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click(f'[title="Select {meeting.title}"]')
    lti_select_iframe.wait_for_selector("dd")
    assert meeting_content_items in lti_select_iframe.content()
Exemplo n.º 3
0
def test_lti_select(page: Page, live_server: LiveServer):
    """Test LTI select."""
    lti_consumer_parameters = {
        "roles": random.choice(["instructor", "administrator"]),
        "content_item_return_url": f"{live_server.url}/development/",
        "context_id": "sent_lti_context_id",
        "lti_message_type": "ContentItemSelectionRequest",
        "lti_version": "LTI-1p0",
    }
    lti_parameters, passport = generate_passport_and_signed_lti_parameters(
        url=f"{live_server.url}/lti/select/",
        lti_parameters=lti_consumer_parameters,
    )

    resolutions = [144]
    playlist = PlaylistFactory(
        lti_id=lti_parameters.get("context_id"),
        consumer_site=passport.consumer_site,
    )
    video = VideoFactory(
        playlist=playlist,
        uploaded_on=timezone.now(),
        resolutions=resolutions,
    )
    document = DocumentFactory(
        playlist=playlist,
        uploaded_on=timezone.now(),
    )

    page.goto(f"{live_server.url}/development/")
    lti_select_form = page.query_selector("#lti_select")
    for key, value in lti_parameters.items():
        if key in ("roles", ):
            lti_select_form.query_selector(
                f'select[name="{key}"]').select_option(value)
        else:
            lti_select_form.query_selector(f'input[name="{key}"]').fill(value)
    page.click('#lti_select input[type="submit"]')

    lti_select_iframe = page.frame("lti_select")

    # Select a document
    lti_select_iframe.click('button[role="tab"]:has-text("Documents")')
    document_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server.url}/lti/documents/{document.id}",
            "title": f"{document.title}",
            "frame": [],
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert document_content_items not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click(f'[title="Select {document.title}"]')
    lti_select_iframe.wait_for_selector("dd")
    assert document_content_items in lti_select_iframe.content()

    # Select a video
    page.click('#lti_select input[type="submit"]')
    lti_select_iframe.click('button[role="tab"]:has-text("Videos")')
    video_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server}/lti/videos/{video.id}",
            "title": f"{video.title}",
            "frame": [],
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert video_content_items not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click(f'[title="Select {video.title}"]')
    lti_select_iframe.wait_for_selector("dd")
    assert video_content_items in lti_select_iframe.content()
    assert Video.objects.count() == 1
Exemplo n.º 4
0
def test_lti_select_bbb_enabled(page: Page, live_server: LiveServer, settings):
    """Test LTI select."""
    settings.BBB_ENABLED = True

    responses.add(
        responses.GET,
        "https://10.7.7.1/bigbluebutton/api/getMeetingInfo",
        body="""<response>
            <returncode>FAILED</returncode>
            <messageKey>notFound</messageKey>
            <message>We could not find a meeting with that meeting ID</message>
        </response>
        """,
        status=200,
    )

    lti_consumer_parameters = {
        "roles": random.choice(["instructor", "administrator"]),
        "content_item_return_url": f"{live_server.url}/development/",
        "context_id": "sent_lti_context_id",
        "lti_message_type": "ContentItemSelectionRequest",
        "lti_version": "LTI-1p0",
        "title": "Sent LMS activity title",
        "text": "Sent LMS activity text",
    }
    lti_parameters, passport = generate_passport_and_signed_lti_parameters(
        url=f"{live_server.url}/lti/select/",
        lti_parameters=lti_consumer_parameters,
    )

    playlist = PlaylistFactory(
        lti_id=lti_parameters.get("context_id"),
        consumer_site=passport.consumer_site,
    )
    classroom = ClassroomFactory(playlist=playlist, )

    page.goto(f"{live_server.url}/development/")
    lti_select_form = page.query_selector("#lti_select")
    for key, value in lti_parameters.items():
        if key in ("roles", ):
            lti_select_form.query_selector(
                f'select[name="{key}"]').select_option(value)
        else:
            lti_select_form.query_selector(f'input[name="{key}"]').fill(value)
    page.click('#lti_select input[type="submit"]')

    lti_select_iframe = page.frame("lti_select")

    # Select a classroom
    lti_select_iframe.click('button[role="tab"]:has-text("Classrooms")')
    classroom_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server.url}/lti/classrooms/{classroom.id}",
            "frame": [],
            "title": lti_consumer_parameters.get("title"),
            "text": lti_consumer_parameters.get("text"),
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert classroom_content_items not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click(f'[title="Select {classroom.title}"]')
    lti_select_iframe.wait_for_selector("dd")
    assert classroom_content_items in lti_select_iframe.content()

    # Select a new classroom
    page.click('#lti_select input[type="submit"]')

    lti_select_iframe.click('button[role="tab"]:has-text("Classrooms")')
    sent_title_and_text = (f'"title":"{lti_consumer_parameters.get("title")}",'
                           f'"text":"{lti_consumer_parameters.get("text")}"')
    assert sent_title_and_text not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click("text=Add a classroom")
    lti_select_iframe.wait_for_selector("dd")

    # assert sent_title_and_text in lti_select_iframe.content()
    # assert Classroom.objects.count() == 1

    # added classroom is created
    assert Classroom.objects.count() == 2
    added_classroom = Classroom.objects.exclude(id=classroom.id).first()
    assert added_classroom.title == lti_consumer_parameters.get("title")
    assert added_classroom.description == lti_consumer_parameters.get("text")
    classroom_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server}/lti/classrooms/{added_classroom.id}",
            "frame": [],
            "title": lti_consumer_parameters.get("title"),
            "text": lti_consumer_parameters.get("text"),
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert classroom_content_items in lti_select_iframe.content()
Exemplo n.º 5
0
def test_lti_select_default_title_no_text(page: Page, live_server: LiveServer):
    """When the request has a default title don't use it in the created resource,
    and send the ressource title in the LTI response."""
    lti_consumer_parameters = {
        "roles": random.choice(["instructor", "administrator"]),
        "content_item_return_url": f"{live_server.url}/development/",
        "context_id": "sent_lti_context_id",
        "lti_message_type": "ContentItemSelectionRequest",
        "lti_version": "LTI-1p0",
        "title": settings.LTI_CONFIG_TITLE,
        "text": "",
    }
    lti_parameters, passport = generate_passport_and_signed_lti_parameters(
        url=f"{live_server.url}/lti/select/",
        lti_parameters=lti_consumer_parameters,
    )

    resolutions = [144]
    playlist = PlaylistFactory(
        lti_id=lti_parameters.get("context_id"),
        consumer_site=passport.consumer_site,
    )
    video = VideoFactory(
        playlist=playlist,
        uploaded_on=timezone.now(),
        resolutions=resolutions,
    )
    document = DocumentFactory(
        description="Document description",
        playlist=playlist,
        uploaded_on=timezone.now(),
    )

    page.goto(f"{live_server.url}/development/")
    lti_select_form = page.query_selector("#lti_select")
    for key, value in lti_parameters.items():
        if key in ("roles", ):
            lti_select_form.query_selector(
                f'select[name="{key}"]').select_option(value)
        else:
            lti_select_form.query_selector(f'input[name="{key}"]').fill(value)
    page.click('#lti_select input[type="submit"]')

    lti_select_iframe = page.frame("lti_select")

    # Select a document
    lti_select_iframe.click('button[role="tab"]:has-text("Documents")')
    # Use the document title and description in the response to fill the activity title and text
    document_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server.url}/lti/documents/{document.id}",
            "frame": [],
            "title": document.title,
            "text": document.description,
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert document_content_items not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click(f'[title="Select {document.title}"]')
    lti_select_iframe.wait_for_selector("dd")
    assert document_content_items in lti_select_iframe.content()

    # Select a video
    page.click('#lti_select input[type="submit"]')
    lti_select_iframe.click('button[role="tab"]:has-text("Videos")')
    # Use the video title and description in the response to fill the activity title and text
    video_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server}/lti/videos/{video.id}",
            "frame": [],
            "title": video.title,
            "text": video.description,
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert video_content_items not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click(f'[title="Select {video.title}"]')
    lti_select_iframe.wait_for_selector("dd")
    assert video_content_items in lti_select_iframe.content()
    assert Video.objects.count() == 1

    # Select a new video
    page.click('#lti_select input[type="submit"]')
    lti_select_iframe.click('button[role="tab"]:has-text("Videos")')
    sent_title = f'"title":"{lti_consumer_parameters.get("title")}"'
    assert sent_title not in lti_select_iframe.content()
    with page.expect_request("**/lti/respond/"):
        lti_select_iframe.click("text=Add a video")
    lti_select_iframe.wait_for_selector("dd")

    # added video is created
    assert Video.objects.count() == 2
    added_video = Video.objects.exclude(id=video.id).first()
    assert added_video.title != lti_consumer_parameters.get("title")
    assert added_video.description == lti_consumer_parameters.get("text")
    # Don't send title nor text in the response
    video_content_items = (json.dumps({
        "@context":
        "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
        "@graph": [{
            "@type": "ContentItem",
            "url": f"{live_server}/lti/videos/{added_video.id}",
            "frame": [],
        }],
    }).replace(", ", ",").replace(": ", ":"))
    assert video_content_items in lti_select_iframe.content()