Ejemplo n.º 1
0
    def test_when_user_isnt_authorized(self, value, expected):
        request = DummyRequest()
        request.lti_user = factories.LTIUser(roles="Learner")
        predicate = AuthorizedToConfigureAssignments(value,
                                                     mock.sentinel.config)

        assert predicate(mock.sentinel.context, request) is expected
Ejemplo n.º 2
0
    def test_h_user(self, HUser):
        lti_user = factories.LTIUser()

        h_user = lti_user.h_user

        HUser.from_lti_user.assert_called_once_with(lti_user)
        assert h_user == HUser.from_lti_user.return_value
Ejemplo n.º 3
0
def pyramid_request(db_session):
    """
    Return a dummy Pyramid request object.

    This is the same dummy request object as is used by the pyramid_config
    fixture below.

    """
    pyramid_request = testing.DummyRequest(db=db_session)
    pyramid_request.POST.update({
        "oauth_consumer_key": "TEST_OAUTH_CONSUMER_KEY",
        "oauth_timestamp": "TEST_TIMESTAMP",
        "oauth_nonce": "TEST_NONCE",
        "oauth_signature_method": "SHA256",
        "oauth_signature": "TEST_OAUTH_SIGNATURE",
        "oauth_version": "1p0p0",
        "user_id": "TEST_USER_ID",
        "roles": "Instructor",
        "tool_consumer_instance_guid": "TEST_GUID",
        "tool_consumer_info_product_family_code": "whiteboard",
        "content_item_return_url": "https://www.example.com",
        "lti_version": "TEST",
        "resource_link_id": "TEST_RESOURCE_LINK_ID",
    })
    pyramid_request.feature = mock.create_autospec(
        lambda feature: False,
        return_value=False  # pragma: no cover
    )
    pyramid_request.lti_user = factories.LTIUser()

    # The DummyRequest request lacks a content_type property which the real
    # request has
    pyramid_request.content_type = None

    return pyramid_request
Ejemplo n.º 4
0
    def test_it_does_not_call_grading_info_upsert_if_instructor(
        self, context, pyramid_request, grading_info_service, view_caller
    ):
        pyramid_request.lti_user = factories.LTIUser(roles="instructor")

        view_caller(context, pyramid_request)

        grading_info_service.upsert_from_request.assert_not_called()
Ejemplo n.º 5
0
    def test_from_lti_user(self):
        lti_user = factories.LTIUser(
            tool_consumer_instance_guid="test_tool_consumer_instance_guid",
            user_id="test_user_id",
        )

        assert HUser.from_lti_user(lti_user) == HUser(
            username="******",
            display_name=lti_user.display_name,
            provider=lti_user.tool_consumer_instance_guid,
            provider_unique_id=lti_user.user_id,
        )
Ejemplo n.º 6
0
class TestAuthenticatedUserID:
    @pytest.mark.parametrize(
        "lti_user,expected_userid",
        [
            (
                factories.LTIUser(
                    user_id="sam",
                    oauth_consumer_key=
                    "Hypothesisf301584250a2dece14f021ab8424018a",
                ),
                "c2Ft:Hypothesisf301584250a2dece14f021ab8424018a",
            ),
            (
                factories.LTIUser(
                    user_id="Sam:Smith",
                    oauth_consumer_key=
                    "Hypothesisf301584250a2dece14f021ab8424018a",
                ),
                "U2FtOlNtaXRo:Hypothesisf301584250a2dece14f021ab8424018a",
            ),
        ],
    )
    def test_it(self, lti_user, expected_userid):
        assert authenticated_userid(lti_user) == expected_userid
Ejemplo n.º 7
0
    def test_is_learner(self, roles, is_learner):
        lti_user = factories.LTIUser(roles=roles)

        assert lti_user.is_learner == is_learner
Ejemplo n.º 8
0
    def test_is_instructor(self, roles, is_instructor):
        lti_user = factories.LTIUser(roles=roles)

        assert lti_user.is_instructor == is_instructor  # pylint:disable=no-member
Ejemplo n.º 9
0
def lti_user():
    return factories.LTIUser()
Ejemplo n.º 10
0
def lti_user():
    return factories.LTIUser(oauth_consumer_key="matching_oauth_consumer_key")
Ejemplo n.º 11
0
def lti_user():
    """Return the original LTIUser that was encoded as a JWT in the request."""
    return factories.LTIUser()