Пример #1
0
    def setUp(self):
        super().setUp()

        self.rsa_key_id = "1"
        # Generate RSA and save exports
        rsa_key = RSA.generate(2048)
        self.key = RSAKey(key=rsa_key, kid=self.rsa_key_id)
        self.public_key = rsa_key.publickey().export_key()

        self.xblock_attributes = {
            'lti_version': 'lti_1p3',
            'lti_1p3_launch_url': 'http://tool.example/launch',
            'lti_1p3_oidc_url': 'http://tool.example/oidc',
            # We need to set the values below because they are not automatically
            # generated until the user selects `lti_version == 'lti_1p3'` on the
            # Studio configuration view.
            'lti_1p3_tool_public_key': self.public_key,
            'has_score': True,
        }
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock,
                                  self.xblock_attributes)
        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'

        # Creates an LTI configuration objects for testing
        self.lti_1p1_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P1)

        self.lti_1p3_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P3)
 def setUp(self):
     super(TestLtiConsumerXBlock, self).setUp()
     self.xblock_attributes = {
         'launch_url': 'http://www.example.com',
     }
     self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock,
                               self.xblock_attributes)
Пример #3
0
    def setUp(self):
        super().setUp()

        # patch things related to LtiAgsScore post_save signal receiver
        compat_mock = patch("lti_consumer.signals.compat")
        self.addCleanup(compat_mock.stop)
        self._compat_mock = compat_mock.start()
        self._compat_mock.load_block_as_anonymous_user.return_value = make_xblock(
            'lti_consumer', LtiConsumerXBlock, {
                'due': timezone.now(),
                'graceperiod': timedelta(days=2),
            })

        self.dummy_location = 'block-v1:course+test+2020+type@problem+block@test'
        self.line_item = LtiAgsLineItem.objects.create(
            lti_configuration=None,
            resource_id="test-id",
            label="this-is-a-test",
            resource_link_id=self.dummy_location,
            score_maximum=100,
        )
        self.score = LtiAgsScore.objects.create(
            line_item=self.line_item,
            timestamp='2020-10-04T18:54:46.736+00:00',
            score_given=10,
            score_maximum=100,
            comment='Better luck next time',
            grading_progress=LtiAgsScore.FULLY_GRADED,
            activity_progress=LtiAgsScore.COMPLETED,
            user_id='test-user')
Пример #4
0
    def setUp(self):
        super().setUp()

        # Create custom LTI Block
        self.rsa_key_id = "1"
        rsa_key = RSA.generate(2048)
        self.key = RSAKey(
            key=rsa_key,
            kid=self.rsa_key_id
        )
        self.public_key = rsa_key.publickey().export_key()

        self.xblock_attributes = {
            'lti_version': 'lti_1p3',
            'lti_1p3_launch_url': 'http://tool.example/launch',
            'lti_1p3_oidc_url': 'http://tool.example/oidc',
            # Intentionally using the same key for tool key to
            # allow using signing methods and make testing easier.
            'lti_1p3_tool_public_key': self.public_key,

            # LTI NRPS related attributes
            'lti_1p3_enable_nrps': True
        }

        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, self.xblock_attributes)

        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'

        # Create configuration
        self.lti_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P3,
        )
        # Preload XBlock to avoid calls to modulestore
        self.lti_config.block = self.xblock

        # Patch internal method to avoid calls to modulestore
        patcher = patch(
            'lti_consumer.models.LtiConfiguration.block',
            new_callable=PropertyMock,
            return_value=self.xblock
        )
        self.addCleanup(patcher.stop)
        self._lti_block_patch = patcher.start()

        self.context_membership_endpoint = reverse(
            'lti_consumer:lti-nrps-memberships-view-list',
            kwargs={
                "lti_config_id": self.lti_config.id
            }
        )

        batch_external_id_patcher = patch(
            'lti_consumer.plugin.views.compat.batch_get_or_create_externalids',
            return_value=ExternalIDMapping()
        )

        self._batch_external_id_patcher = batch_external_id_patcher.start()
    def setUp(self):
        super().setUp()

        # Create custom LTI Block
        self.rsa_key_id = "1"
        rsa_key = RSA.generate(2048)
        self.key = RSAKey(
            key=rsa_key,
            kid=self.rsa_key_id
        )
        self.public_key = rsa_key.publickey().export_key()

        self.xblock_attributes = {
            'lti_version': 'lti_1p3',
            'lti_1p3_launch_url': 'http://tool.example/launch',
            'lti_1p3_oidc_url': 'http://tool.example/oidc',
            # Intentionally using the same key for tool key to
            # allow using signing methods and make testing easier.
            'lti_1p3_tool_public_key': self.public_key,

            # xblock due date related attributes
            'due': timezone.now(),
            'graceperiod': timedelta(days=2),
            'accept_grades_past_due': False,
        }
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, self.xblock_attributes)

        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'

        # Create configuration
        self.lti_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P3,
        )
        # Preload XBlock to avoid calls to modulestore
        self.lti_config.block = self.xblock

        # Patch internal method to avoid calls to modulestore
        patcher = patch(
            'lti_consumer.models.LtiConfiguration.block',
            new_callable=PropertyMock,
            return_value=self.xblock
        )
        self.addCleanup(patcher.stop)
        self._lti_block_patch = patcher.start()

        self._mock_user = Mock()
        compat_mock = patch("lti_consumer.signals.compat")
        self.addCleanup(compat_mock.stop)
        self._compat_mock = compat_mock.start()
        self._compat_mock.get_user_from_external_user_id.return_value = self._mock_user
        self._compat_mock.load_block_as_anonymous_user.return_value = self.xblock
Пример #6
0
    def setUp(self):
        super().setUp()

        self.xblock_attributes = {'lti_version': 'lti_1p3'}
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, self.xblock_attributes)
        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'

        self.lti_1p3_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P3
        )
    def test_xblock_grade_publish_accept_passed_due_date(self, timezone_patcher):
        """
        Test grade publish after due date when accept_grades_past_due is True. Grade should publish.
        """
        xblock_attrs = {
            'accept_grades_past_due': True,
        }
        xblock_attrs.update(self.xblock_attributes)
        xblock = make_xblock('lti_consumer', LtiConsumerXBlock, xblock_attrs)
        self._compat_mock.load_block_as_anonymous_user.return_value = xblock

        timezone_patcher.now.return_value = timezone.now() + timedelta(days=30)

        self._post_lti_score()

        self._compat_mock.load_block_as_anonymous_user.assert_called_once()

        self._compat_mock.get_user_from_external_user_id.assert_not_called()
        self._compat_mock.publish_grade.assert_not_called()
    def setUp(self):
        super(TestLtiCofigurationModel, self).setUp()

        self.rsa_key_id = "1"
        # Generate RSA and save exports
        rsa_key = RSA.generate(2048)
        self.key = RSAKey(key=rsa_key, kid=self.rsa_key_id)
        self.public_key = rsa_key.publickey().export_key()

        self.xblock_attributes = {
            'lti_version': 'lti_1p3',
            'lti_1p3_launch_url': 'http://tool.example/launch',
            'lti_1p3_oidc_url': 'http://tool.example/oidc',
            # We need to set the values below because they are not automatically
            # generated until the user selects `lti_version == 'lti_1p3'` on the
            # Studio configuration view.
            'lti_1p3_client_id': self.rsa_key_id,
            'lti_1p3_block_key': rsa_key.export_key('PEM'),
            # Use same key for tool key to make testing easier
            'lti_1p3_tool_public_key': self.public_key,
        }
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock,
                                  self.xblock_attributes)
        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'

        # Patch settings calls to modulestore
        self._settings_mock = patch('lti_consumer.utils.settings',
                                    LMS_ROOT_URL="https://example.com")
        self.addCleanup(self._settings_mock.stop)
        self._settings_mock.start()

        # Creates an LTI configuration objects for testing
        self.lti_1p1_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P1)

        self.lti_1p3_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P3)
    def setUp(self):
        super(LtiAgsLineItemViewSetTestCase, self).setUp()

        # Create custom LTI Block
        self.rsa_key_id = "1"
        rsa_key = RSA.generate(2048)
        self.key = RSAKey(key=rsa_key, kid=self.rsa_key_id)
        self.public_key = rsa_key.publickey().export_key()

        self.xblock_attributes = {
            'lti_version': 'lti_1p3',
            'lti_1p3_launch_url': 'http://tool.example/launch',
            'lti_1p3_oidc_url': 'http://tool.example/oidc',
            # Intentionally using the same key for tool key to
            # allow using signing methods and make testing easier.
            'lti_1p3_tool_public_key': self.public_key,
        }
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock,
                                  self.xblock_attributes)

        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'

        # Create configuration
        self.lti_config = LtiConfiguration.objects.create(
            location=str(self.xblock.location),
            version=LtiConfiguration.LTI_1P3)
        # Preload XBlock to avoid calls to modulestore
        self.lti_config.block = self.xblock

        # Patch internal method to avoid calls to modulestore
        patcher = patch('lti_consumer.models.LtiConfiguration.block',
                        new_callable=PropertyMock,
                        return_value=self.xblock)
        self.addCleanup(patcher.stop)
        self._lti_block_patch = patcher.start()
Пример #10
0
    def _setup_lti_block(self):
        """
        Set's up an LTI block that is used in some tests.
        """
        # Generate RSA and save exports
        rsa_key = RSA.generate(1024)
        public_key = rsa_key.publickey().export_key()

        xblock_attributes = {
            'lti_version': 'lti_1p3',
            'lti_1p3_launch_url': 'http://tool.example/launch',
            'lti_1p3_oidc_url': 'http://tool.example/oidc',
            # We need to set the values below because they are not automatically
            # generated until the user selects `lti_version == 'lti_1p3'` on the
            # Studio configuration view.
            'lti_1p3_tool_public_key': public_key,
        }
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, xblock_attributes)
        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = 'block-v1:course+test+2020+type@problem+block@test'
        # Create lti configuration
        self.lti_config = LtiConfiguration.objects.create(
            location=self.xblock.location
        )
    def setUp(self):
        super().setUp()

        self.location = 'block-v1:course+test+2020+type@problem+block@test'

        # Create configuration
        self.lti_config = LtiConfiguration.objects.create(
            location=self.location,
            version=LtiConfiguration.LTI_1P3,
        )

        # Create custom LTI Block
        rsa_key = RSA.import_key(self.lti_config.lti_1p3_private_key)
        self.key = RSAKey(
            # Using the same key ID as client id
            # This way we can easily serve multiple public
            # keys on teh same endpoint and keep all
            # LTI 1.3 blocks working
            kid=self.lti_config.lti_1p3_private_key_id,
            key=rsa_key)
        self.public_key = rsa_key.publickey().export_key()

        self.xblock_attributes = {
            'lti_version':
            'lti_1p3',
            'lti_1p3_launch_url':
            'http://tool.example/launch',
            'lti_1p3_oidc_url':
            'http://tool.example/oidc',
            # Intentionally using the same key for tool key to
            # allow using signing methods and make testing easier.
            'lti_1p3_tool_public_key':
            self.public_key,

            # xblock due date related attributes
            'lti_advantage_deep_linking_enabled':
            True,
            'lti_advantage_deep_linking_launch_url':
            'http://tool.example/deep_link_launch',
        }
        self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock,
                                  self.xblock_attributes)

        # Set dummy location so that UsageKey lookup is valid
        self.xblock.location = self.location

        # Preload XBlock to avoid calls to modulestore
        self.lti_config.block = self.xblock

        # Patch internal method to avoid calls to modulestore
        patcher = patch('lti_consumer.models.LtiConfiguration.block',
                        new_callable=PropertyMock,
                        return_value=self.xblock)
        self.addCleanup(patcher.stop)
        self._lti_block_patch = patcher.start()

        self._mock_user = Mock()
        compat_mock = patch("lti_consumer.signals.compat")
        self.addCleanup(compat_mock.stop)
        self._compat_mock = compat_mock.start()
        self._compat_mock.get_user_from_external_user_id.return_value = self._mock_user
        self._compat_mock.load_block_as_anonymous_user.return_value = self.xblock
 def setUp(self):
     super(TestLtiConsumerXBlock, self).setUp()
     self.xblock_attributes = {
         'launch_url': 'http://www.example.com',
     }
     self.xblock = make_xblock('lti_consumer', LtiConsumerXBlock, self.xblock_attributes)