tests.py 2.49 KB
Newer Older
1 2
"""Tests for the lms module itself."""

3
import mimetypes
Adam Palay committed
4
from mock import patch
5

6
from django.test import TestCase
Adam Palay committed
7
from django.core.urlresolvers import reverse
8 9 10

from edxmako import add_lookup, LOOKUP
from lms import startup
Adam Palay committed
11
from xmodule.modulestore.tests.factories import CourseFactory
12
from util import keyword_substitution
13

14 15 16 17 18 19 20 21 22 23 24 25 26

class LmsModuleTests(TestCase):
    """
    Tests for lms module itself.
    """

    def test_new_mimetypes(self):
        extensions = ['eot', 'otf', 'ttf', 'woff']
        for extension in extensions:
            mimetype, _ = mimetypes.guess_type('test.' + extension)
            self.assertIsNotNone(mimetype)


27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
class TemplateLookupTests(TestCase):
    """
    Tests for TemplateLookup.
    """

    def test_add_lookup_to_main(self):
        """Test that any template directories added are not cleared when microsites are enabled."""

        add_lookup('main', 'external_module', __name__)
        directories = LOOKUP['main'].directories
        self.assertEqual(len([dir for dir in directories if 'external_module' in dir]), 1)

        # This should not clear the directories list
        startup.enable_microsites()
        directories = LOOKUP['main'].directories
        self.assertEqual(len([dir for dir in directories if 'external_module' in dir]), 1)
Adam Palay committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58


@patch.dict('django.conf.settings.FEATURES', {'ENABLE_FEEDBACK_SUBMISSION': True})
class HelpModalTests(TestCase):
    """Tests for the help modal"""
    def setUp(self):
        self.course = CourseFactory.create()

    def test_simple_test(self):
        """
        Simple test to make sure that you don't get a 500 error when the modal
        is enabled.
        """
        url = reverse('info', args=[self.course.id.to_deprecated_string()])
        resp = self.client.get(url)
        self.assertEqual(resp.status_code, 200)
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76


class KeywordSubConfigTests(TestCase):
    """ Tests for configuring keyword substitution feature """

    def test_keyword_map_not_empty(self):
        """ Ensure that the keyword subsitution map is non-empty """
        self.assertFalse(keyword_substitution.keyword_function_map_is_empty())

    def test_adding_keyword_map_is_noop(self):
        """ Test that trying to add a new keyword mapping is a no-op """

        existing_map = keyword_substitution.KEYWORD_FUNCTION_MAP
        keyword_substitution.add_keyword_function_map({
            '%%USER_ID%%': lambda x: x,
            '%%USER_FULLNAME%%': lambda x: x,
        })
        self.assertDictEqual(existing_map, keyword_substitution.KEYWORD_FUNCTION_MAP)