How to use XBlock - 10 common examples

To help you get started, we’ve selected a few XBlock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / coursebuilder_xblock_module / tests / xblock_module.py View on Github external
self.assertEqual(1, len(node))

        self.assertEqual('div', node[0].tag)
        self.assertEqual(1, len(node[0]))

        node = node[0][0]
        self.assertEqual('div', node.tag)
        self.assertEqual('xblock', node.attrib['class'])
        self.assertEqual('thumbs', node.attrib['data-block-type'])

        xsrf_token = utils.XsrfTokenManager.create_xsrf_token(
            xblock_module.XBLOCK_XSRF_TOKEN_NAME)
        self.assertEqual(xsrf_token, node.attrib['data-xsrf-token'])

        self.assertEqual(1, len(cxt.env['fragment_list']))
        self.assertIsInstance(cxt.env['fragment_list'][0], fragment.Fragment)
github google / appengine_xblock_runtime / tests / test_runtime.py View on Github external
def test_html_block(self):
        """Test persistence of fields in content scope."""
        usage_id = self.runtime.parse_xml_string(
            'text', self.id_generator)
        block = self.runtime.get_block(usage_id)

        key = xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.content,
            user_id=None,
            block_scope_id=block.scope_ids.def_id,
            field_name='content')

        self.assertEqual('text', store.KeyValueStore().get(key))
github google / appengine_xblock_runtime / tests / test_store.py View on Github external
def _user_state_key(self):
        return xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.user_state, user_id='123',
            block_scope_id='456', field_name='my_field')
github google / coursebuilder_xblock_module / tests / xblock_module.py View on Github external
def get_key(self, scope, user_id, block_scope_id, field_name):
        xblock_key = xblock.runtime.KeyValueStore.Key(
            scope=scope,
            user_id=user_id,
            block_scope_id=block_scope_id,
            field_name=field_name)
        key_str = xblock_module.store.key_string(xblock_key)
        db_key = db.Key.from_path('KeyValueEntity', key_str)
        return db_key
github google / appengine_xblock_runtime / tests / test_runtime.py View on Github external
def test_slider_block(self):
        """Test peristence of fields in user scope."""
        usage_id = self.runtime.parse_xml_string(
            '', self.id_generator)
        block = self.runtime.get_block(usage_id)

        block.value = 50
        block.save()

        key = xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.user_state,
            user_id=self.STUDENT_ID,
            block_scope_id=block.scope_ids.usage_id,
            field_name='value')

        self.assertEqual(50, store.KeyValueStore().get(key))
github google / appengine_xblock_runtime / tests / test_store.py View on Github external
def _user_state_key(self):
        return xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.user_state, user_id='123',
            block_scope_id='456', field_name='my_field')
github google / coursebuilder_xblock_module / tests / xblock_module.py View on Github external
def test_for_export_transforms_value_for_student_data(self):
        key = self.get_key(
            xblock.fields.Scope.user_state, '1234567890',
            '0d40c9be8e254416b4782bf8e19a538f', 'my_field')
        orig_model = dbmodels.KeyValueEntity(key=key, data='{"value": 1}')
        safe_model = orig_model.for_export(self.transform)
        self.assertEquals('tr_{"value": 1}', safe_model.data)
github google / appengine_xblock_runtime / tests / test_runtime.py View on Github external
def test_slider_block(self):
        """Test peristence of fields in user scope."""
        usage_id = self.runtime.parse_xml_string(
            '', self.id_generator)
        block = self.runtime.get_block(usage_id)

        block.value = 50
        block.save()

        key = xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.user_state,
            user_id=self.STUDENT_ID,
            block_scope_id=block.scope_ids.usage_id,
            field_name='value')

        self.assertEqual(50, store.KeyValueStore().get(key))
github google / appengine_xblock_runtime / tests / test_runtime.py View on Github external
def test_html_block(self):
        """Test persistence of fields in content scope."""
        usage_id = self.runtime.parse_xml_string(
            'text', self.id_generator)
        block = self.runtime.get_block(usage_id)

        key = xblock.runtime.KeyValueStore.Key(
            scope=xblock.fields.Scope.content,
            user_id=None,
            block_scope_id=block.scope_ids.def_id,
            field_name='content')

        self.assertEqual('text', store.KeyValueStore().get(key))
github google / coursebuilder_xblock_module / tests / xblock_module.py View on Github external
def test_runtime_prevents_student_writes_to_non_student_fields(self):
        rt = xblock_module.Runtime(MockHandler(), is_admin=True)
        usage_id = parse_xml_string(rt, 'Test')

        # Load the block in student role
        rt = xblock_module.Runtime(MockHandler(), student_id='s23')
        block = rt.get_block(usage_id)
        self.assertEqual('Test', block.content)
        block.content = 'Something else'
        try:
            block.save()
            self.fail('Expected InvalidScopeError')
        except xblock.exceptions.InvalidScopeError:
            pass  # Expected exception

        # Load the block in admin role
        rt = xblock_module.Runtime(MockHandler(), is_admin=True)
        block = rt.get_block(usage_id)
        block.content = 'Something else'
        block.save()  # No exception