test_course_info.py 3.07 KB
Newer Older
1 2 3 4
"""
Test the course_info xblock
"""
from django.core.urlresolvers import reverse
5 6 7
from django.test.utils import override_settings
import mock
from opaque_keys.edx.locations import SlashSeparatedCourseKey
8 9

from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
10 11 12
from xmodule.modulestore.tests.django_utils import (
    TEST_DATA_MOCK_MODULESTORE, TEST_DATA_MIXED_CLOSED_MODULESTORE
)
13 14
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory

15 16
from .helpers import LoginEnrollmentTestCase

17 18

class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
19 20 21
    """
    Tests for the Course Info page
    """
22
    def setUp(self):
23
        super(CourseInfoTestCase, self).setUp()
24 25 26 27 28 29
        self.course = CourseFactory.create()
        self.page = ItemFactory.create(
            category="course_info", parent_location=self.course.location,
            data="OOGIE BLOOGIE", display_name="updates"
        )

30
    def test_logged_in_unenrolled(self):
31
        self.setup_user()
32
        url = reverse('info', args=[self.course.id.to_deprecated_string()])
33 34 35
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertIn("OOGIE BLOOGIE", resp.content)
36 37 38 39 40 41 42
        self.assertIn("You are not currently enrolled in this course", resp.content)

    def test_logged_in_enrolled(self):
        self.enroll(self.course)
        url = reverse('info', args=[self.course.id.to_deprecated_string()])
        resp = self.client.get(url)
        self.assertNotIn("You are not currently enrolled in this course", resp.content)
43 44

    def test_anonymous_user(self):
45
        url = reverse('info', args=[self.course.id.to_deprecated_string()])
46 47 48
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertNotIn("OOGIE BLOOGIE", resp.content)
49

Adam Palay committed
50 51

class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
52 53 54
    """
    Tests for the Course Info page for an XML course
    """
55 56
    MODULESTORE = TEST_DATA_MIXED_CLOSED_MODULESTORE

Adam Palay committed
57 58 59
    # The following XML test course (which lives at common/test/data/2014)
    # is closed; we're testing that a course info page still appears when
    # the course is already closed
60
    xml_course_key = SlashSeparatedCourseKey('edX', 'detached_pages', '2014')
Adam Palay committed
61 62 63 64 65

    # this text appears in that course's course info page
    # common/test/data/2014/info/updates.html
    xml_data = "course info 463139"

66 67 68
    @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
    def test_logged_in_xml(self):
        self.setup_user()
69
        url = reverse('info', args=[self.xml_course_key.to_deprecated_string()])
70 71 72 73 74 75
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertIn(self.xml_data, resp.content)

    @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False})
    def test_anonymous_user_xml(self):
76
        url = reverse('info', args=[self.xml_course_key.to_deprecated_string()])
77 78 79
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
        self.assertNotIn(self.xml_data, resp.content)