def test_update_middlewaress_helper(self): """ Ensures that the helper preserves the middleware location. """ updated_middlewares = update_middlewares(( 'dummy1', EDX_MIDDLEWARE, 'dummy2', )) self.assertNotIn(EDX_MIDDLEWARE, updated_middlewares) self.assertIn(UNLOCKERX_MIDDLEWARE, updated_middlewares) self.assertEquals( 1, updated_middlewares.index(UNLOCKERX_MIDDLEWARE), msg= 'Should have the UlockerX middleware in the same position where the edX middleware was.' )
def test_update_middleware(self, middlewares): expected = [UNLOCKERX_MIDDLEWARE] self.assertEquals(update_middlewares(middlewares), expected)
def test_call_update_middleware_twice(self): expected = [UNLOCKERX_MIDDLEWARE] assert update_middlewares([UNLOCKERX_MIDDLEWARE]) == expected
def test_missing_middleware_on_update(self): with self.assertRaises(ValueError): update_middlewares(('backend1', 'backend2'))
""" Get the absolute path of the given path relative to the project root. """ return join(abspath(dirname(__file__)), *args) # Calling `update_middlewares` to mock the behaviour of the Open edX plugins system. # Ref: https://github.com/edx/edx-platform/blob/ac4845d/openedx/core/djangoapps/plugins/README.rst # Keep in parity with `unlockerx.settings.common` to ensure proper testing environment. MIDDLEWARE_CLASSES = update_middlewares([ 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', # Enable SessionAuthenticationMiddleware in order to invalidate # user sessions after a password change. 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', # catches any uncaught RateLimitExceptions and returns a 403 instead of a 500 'ratelimitbackend.middleware.RateLimitMiddleware', ]) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'default.db', 'USER': '', 'PASSWORD': '', 'HOST': '',
def plugin_settings(settings): """ Enable the UnlockerX customizations for all environments. """ settings.MIDDLEWARE_CLASSES = update_middlewares(settings.MIDDLEWARE_CLASSES)