Exemplo n.º 1
0
 def setUp(self):
     super(MasqueradingKeyValueStoreTest, self).setUp()
     self.ro_kvs = ReadOnlyKeyValueStore({
         'a': 42,
         'b': None,
         'c': 'OpenCraft'
     })
     self.session = FakeSession()
     self.kvs = MasqueradingKeyValueStore(self.ro_kvs, self.session)
Exemplo n.º 2
0
def get_module_for_descriptor(user,
                              request,
                              descriptor,
                              field_data_cache,
                              course_key,
                              position=None,
                              wrap_xmodule_display=True,
                              grade_bucket_type=None,
                              static_asset_path='',
                              disable_staff_debug_info=False,
                              course=None):
    """
    Implements get_module, extracting out the request-specific functionality.

    disable_staff_debug_info : If this is True, exclude staff debug information in the rendering of the module.

    See get_module() docstring for further details.
    """
    track_function = make_track_function(request)
    xqueue_callback_url_prefix = get_xqueue_callback_url_prefix(request)

    user_location = getattr(request, 'session', {}).get('country_code')

    student_kvs = DjangoKeyValueStore(field_data_cache)
    if is_masquerading_as_specific_student(user, course_key):
        student_kvs = MasqueradingKeyValueStore(student_kvs, request.session)
    student_data = KvsFieldData(student_kvs)

    return get_module_for_descriptor_internal(
        user=user,
        descriptor=descriptor,
        student_data=student_data,
        course_id=course_key,
        track_function=track_function,
        xqueue_callback_url_prefix=xqueue_callback_url_prefix,
        position=position,
        wrap_xmodule_display=wrap_xmodule_display,
        grade_bucket_type=grade_bucket_type,
        static_asset_path=static_asset_path,
        user_location=user_location,
        request_token=xblock_request_token(request),
        disable_staff_debug_info=disable_staff_debug_info,
        course=course)
Exemplo n.º 3
0
 def setUp(self):
     super(MasqueradingKeyValueStoreTest, self).setUp()
     self.ro_kvs = ReadOnlyKeyValueStore({'a': 42, 'b': None, 'c': 'OpenCraft'})
     self.session = FakeSession()
     self.kvs = MasqueradingKeyValueStore(self.ro_kvs, self.session)
Exemplo n.º 4
0
class MasqueradingKeyValueStoreTest(TestCase):
    """
    Unit tests for the MasqueradingKeyValueStore class.
    """
    def setUp(self):
        super(MasqueradingKeyValueStoreTest, self).setUp()
        self.ro_kvs = ReadOnlyKeyValueStore({'a': 42, 'b': None, 'c': 'OpenCraft'})
        self.session = FakeSession()
        self.kvs = MasqueradingKeyValueStore(self.ro_kvs, self.session)

    def test_all(self):
        self.assertEqual(self.kvs.get('a'), 42)
        self.assertEqual(self.kvs.get('b'), None)
        self.assertEqual(self.kvs.get('c'), 'OpenCraft')
        with self.assertRaises(KeyError):
            self.kvs.get('d')

        self.assertTrue(self.kvs.has('a'))
        self.assertTrue(self.kvs.has('b'))
        self.assertTrue(self.kvs.has('c'))
        self.assertFalse(self.kvs.has('d'))

        self.kvs.set_many({'a': 'Norwegian Blue', 'd': 'Giraffe'})
        self.kvs.set('b', 7)

        self.assertEqual(self.kvs.get('a'), 'Norwegian Blue')
        self.assertEqual(self.kvs.get('b'), 7)
        self.assertEqual(self.kvs.get('c'), 'OpenCraft')
        self.assertEqual(self.kvs.get('d'), 'Giraffe')

        for key in 'abd':
            self.assertTrue(self.kvs.has(key))
            self.kvs.delete(key)
            with self.assertRaises(KeyError):
                self.kvs.get(key)

        self.assertEqual(self.kvs.get('c'), 'OpenCraft')
Exemplo n.º 5
0
 def setUp(self):
     super(MasqueradingKeyValueStoreTest, self).setUp()
     self.ro_kvs = ReadOnlyKeyValueStore({"a": 42, "b": None, "c": "OpenCraft"})
     self.session = FakeSession()
     self.kvs = MasqueradingKeyValueStore(self.ro_kvs, self.session)
Exemplo n.º 6
0
class MasqueradingKeyValueStoreTest(TestCase):
    """
    Unit tests for the MasqueradingKeyValueStore class.
    """

    def setUp(self):
        super(MasqueradingKeyValueStoreTest, self).setUp()
        self.ro_kvs = ReadOnlyKeyValueStore({"a": 42, "b": None, "c": "OpenCraft"})
        self.session = FakeSession()
        self.kvs = MasqueradingKeyValueStore(self.ro_kvs, self.session)

    def test_all(self):
        self.assertEqual(self.kvs.get("a"), 42)
        self.assertEqual(self.kvs.get("b"), None)
        self.assertEqual(self.kvs.get("c"), "OpenCraft")
        with self.assertRaises(KeyError):
            self.kvs.get("d")

        self.assertTrue(self.kvs.has("a"))
        self.assertTrue(self.kvs.has("b"))
        self.assertTrue(self.kvs.has("c"))
        self.assertFalse(self.kvs.has("d"))

        self.kvs.set_many({"a": "Norwegian Blue", "d": "Giraffe"})
        self.kvs.set("b", 7)

        self.assertEqual(self.kvs.get("a"), "Norwegian Blue")
        self.assertEqual(self.kvs.get("b"), 7)
        self.assertEqual(self.kvs.get("c"), "OpenCraft")
        self.assertEqual(self.kvs.get("d"), "Giraffe")

        for key in "abd":
            self.assertTrue(self.kvs.has(key))
            self.kvs.delete(key)
            with self.assertRaises(KeyError):
                self.kvs.get(key)

        self.assertEqual(self.kvs.get("c"), "OpenCraft")
Exemplo n.º 7
0
class MasqueradingKeyValueStoreTest(TestCase):
    """
    Unit tests for the MasqueradingKeyValueStore class.
    """
    def setUp(self):
        super(MasqueradingKeyValueStoreTest, self).setUp()
        self.ro_kvs = ReadOnlyKeyValueStore({
            'a': 42,
            'b': None,
            'c': 'OpenCraft'
        })
        self.session = FakeSession()
        self.kvs = MasqueradingKeyValueStore(self.ro_kvs, self.session)

    def test_all(self):
        self.assertEqual(self.kvs.get('a'), 42)
        self.assertEqual(self.kvs.get('b'), None)
        self.assertEqual(self.kvs.get('c'), 'OpenCraft')
        with self.assertRaises(KeyError):
            self.kvs.get('d')

        self.assertTrue(self.kvs.has('a'))
        self.assertTrue(self.kvs.has('b'))
        self.assertTrue(self.kvs.has('c'))
        self.assertFalse(self.kvs.has('d'))

        self.kvs.set_many({'a': 'Norwegian Blue', 'd': 'Giraffe'})
        self.kvs.set('b', 7)

        self.assertEqual(self.kvs.get('a'), 'Norwegian Blue')
        self.assertEqual(self.kvs.get('b'), 7)
        self.assertEqual(self.kvs.get('c'), 'OpenCraft')
        self.assertEqual(self.kvs.get('d'), 'Giraffe')

        for key in 'abd':
            self.assertTrue(self.kvs.has(key))
            self.kvs.delete(key)
            with self.assertRaises(KeyError):
                self.kvs.get(key)

        self.assertEqual(self.kvs.get('c'), 'OpenCraft')