test_middleware.py 1.47 KB
Newer Older
1 2 3 4 5
"""
Tests for wiki middleware.
"""

from django.test.client import Client
6
from nose.plugins.attrib import attr
7 8
from wiki.models import URLPath

9 10
from course_wiki.views import get_or_create_root
from courseware.tests.factories import InstructorFactory
11 12 13 14
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory


15
@attr(shard=1)
16 17 18 19 20
class TestWikiAccessMiddleware(ModuleStoreTestCase):
    """Tests for WikiAccessMiddleware."""

    def setUp(self):
        """Test setup."""
21 22
        super(TestWikiAccessMiddleware, self).setUp()

23 24 25
        self.wiki = get_or_create_root()

        self.course_math101 = CourseFactory.create(org='edx', number='math101', display_name='2014', metadata={'use_unique_wiki_id': 'false'})
26
        self.course_math101_instructor = InstructorFactory(course_key=self.course_math101.id, username='instructor', password='secret')
27 28 29 30 31 32 33 34 35 36
        self.wiki_math101 = URLPath.create_article(self.wiki, 'math101', title='math101')

        self.client = Client()
        self.client.login(username='instructor', password='secret')

    def test_url_tranform(self):
        """Test that the correct prefix ('/courses/<course_id>') is added to the urls in the wiki."""
        response = self.client.get('/courses/edx/math101/2014/wiki/math101/')
        self.assertIn('/courses/edx/math101/2014/wiki/math101/_edit/', response.content)
        self.assertIn('/courses/edx/math101/2014/wiki/math101/_settings/', response.content)