Commit 6f5249d3 by Diana Huang Committed by Brian Jacobel

Beginning of python unit tests.

parent 55905759
...@@ -231,18 +231,18 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase): ...@@ -231,18 +231,18 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase):
# # of sql queries to default, # # of sql queries to default,
# # of mongo queries, # # of mongo queries,
# ) # )
('no_overrides', 1, True, False): (21, 6), ('no_overrides', 1, True, False): (22, 6),
('no_overrides', 2, True, False): (21, 6), ('no_overrides', 2, True, False): (22, 6),
('no_overrides', 3, True, False): (21, 6), ('no_overrides', 3, True, False): (22, 6),
('ccx', 1, True, False): (21, 6), ('ccx', 1, True, False): (22, 6),
('ccx', 2, True, False): (21, 6), ('ccx', 2, True, False): (22, 6),
('ccx', 3, True, False): (21, 6), ('ccx', 3, True, False): (22, 6),
('no_overrides', 1, False, False): (21, 6), ('no_overrides', 1, False, False): (22, 6),
('no_overrides', 2, False, False): (21, 6), ('no_overrides', 2, False, False): (22, 6),
('no_overrides', 3, False, False): (21, 6), ('no_overrides', 3, False, False): (22, 6),
('ccx', 1, False, False): (21, 6), ('ccx', 1, False, False): (22, 6),
('ccx', 2, False, False): (21, 6), ('ccx', 2, False, False): (22, 6),
('ccx', 3, False, False): (21, 6), ('ccx', 3, False, False): (22, 6),
} }
...@@ -254,19 +254,19 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase): ...@@ -254,19 +254,19 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase):
__test__ = True __test__ = True
TEST_DATA = { TEST_DATA = {
('no_overrides', 1, True, False): (21, 3), ('no_overrides', 1, True, False): (22, 3),
('no_overrides', 2, True, False): (21, 3), ('no_overrides', 2, True, False): (22, 3),
('no_overrides', 3, True, False): (21, 3), ('no_overrides', 3, True, False): (22, 3),
('ccx', 1, True, False): (21, 3), ('ccx', 1, True, False): (22, 3),
('ccx', 2, True, False): (21, 3), ('ccx', 2, True, False): (22, 3),
('ccx', 3, True, False): (21, 3), ('ccx', 3, True, False): (22, 3),
('ccx', 1, True, True): (22, 3), ('ccx', 1, True, True): (23, 3),
('ccx', 2, True, True): (22, 3), ('ccx', 2, True, True): (23, 3),
('ccx', 3, True, True): (22, 3), ('ccx', 3, True, True): (23, 3),
('no_overrides', 1, False, False): (21, 3), ('no_overrides', 1, False, False): (22, 3),
('no_overrides', 2, False, False): (21, 3), ('no_overrides', 2, False, False): (22, 3),
('no_overrides', 3, False, False): (21, 3), ('no_overrides', 3, False, False): (22, 3),
('ccx', 1, False, False): (21, 3), ('ccx', 1, False, False): (22, 3),
('ccx', 2, False, False): (21, 3), ('ccx', 2, False, False): (22, 3),
('ccx', 3, False, False): (21, 3), ('ccx', 3, False, False): (22, 3),
} }
## mako
<%page expression_filter="h"/>
<%!
from openedx.core.djangolib.markup import HTML
%>
<%inherit file="/main.html" />
<%block name="bodyclass">view-in-course view-statictab ${course.css_class or ''}</%block>
<%namespace name='static' file='/static_content.html'/>
<%block name="headextra">
<%static:css group='style-course-vendor'/>
<%static:css group='style-course'/>
${HTML(fragment.head_html())}
</%block>
<%block name="js_extra">
<%include file="/mathjax_include.html" args="disable_fast_preview=True"/>
${HTML(fragment.foot_html())}
</%block>
<%block name="pagetitle">${tab['name']} | ${course.display_number_with_default}</%block>
<%include file="/courseware/course_navigation.html" args="active_page=active_page" />
<main id="main" aria-label="Content" tabindex="-1">
<section class="container">
<div class="static_tab_wrapper">
${HTML(fragment.body_html())}
</div>
</section>
</main>
"""
Tests for the Course Outline view and supporting views.
"""
from django.core.urlresolvers import reverse
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
class TestCourseOutlinePage(SharedModuleStoreTestCase):
"""
Test the new course outline view.
"""
@classmethod
def setUpClass(cls):
"""Set up the simplest course possible."""
# setUpClassAndTestData() already calls setUpClass on SharedModuleStoreTestCase
# pylint: disable=super-method-not-called
with super(TestCourseOutlinePage, cls).setUpClassAndTestData():
cls.courses = []
course = CourseFactory.create()
with cls.store.bulk_operations(course.id):
chapter = ItemFactory.create(category='chapter', parent_location=course.location)
section = ItemFactory.create(category='sequential', parent_location=chapter.location)
ItemFactory.create(category='vertical', parent_location=section.location)
cls.courses.append(course)
course = CourseFactory.create()
with cls.store.bulk_operations(course.id):
chapter = ItemFactory.create(category='chapter', parent_location=course.location)
section = ItemFactory.create(category='sequential', parent_location=chapter.location)
section2 = ItemFactory.create(category='sequential', parent_location=chapter.location)
ItemFactory.create(category='vertical', parent_location=section.location)
ItemFactory.create(category='vertical', parent_location=section2.location)
@classmethod
def setUpTestData(cls):
"""Set up and enroll our fake user in the course."""
cls.password = 'test'
cls.user = UserFactory(password=cls.password)
for course in cls.courses:
CourseEnrollment.enroll(cls.user, course.id)
def setUp(self):
"""
Set up for the tests.
"""
super(TestCourseOutlinePage, self).setUp()
self.client.login(username=self.user.username, password=self.password)
def test_render(self):
for course in self.courses:
url = reverse(
'unified_course_view',
kwargs={
'course_id': unicode(course.id),
}
)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response_content = response.content.decode("utf-8")
for chapter in course.children:
self.assertIn(chapter.display_name, response_content)
for section in chapter.children:
self.assertIn(section.display_name, response_content)
for vertical in section.children:
self.assertNotIn(vertical.display_name, response_content)
...@@ -1419,17 +1419,17 @@ class ProgressPageTests(ModuleStoreTestCase): ...@@ -1419,17 +1419,17 @@ class ProgressPageTests(ModuleStoreTestCase):
"""Test that query counts remain the same for self-paced and instructor-paced courses.""" """Test that query counts remain the same for self-paced and instructor-paced courses."""
SelfPacedConfiguration(enabled=self_paced_enabled).save() SelfPacedConfiguration(enabled=self_paced_enabled).save()
self.setup_course(self_paced=self_paced) self.setup_course(self_paced=self_paced)
with self.assertNumQueries(38), check_mongo_calls(4): with self.assertNumQueries(39), check_mongo_calls(4):
self._get_progress_page() self._get_progress_page()
def test_progress_queries(self): def test_progress_queries(self):
self.setup_course() self.setup_course()
with self.assertNumQueries(38), check_mongo_calls(4): with self.assertNumQueries(39), check_mongo_calls(4):
self._get_progress_page() self._get_progress_page()
# subsequent accesses to the progress page require fewer queries. # subsequent accesses to the progress page require fewer queries.
for _ in range(2): for _ in range(2):
with self.assertNumQueries(24), check_mongo_calls(4): with self.assertNumQueries(25), check_mongo_calls(4):
self._get_progress_page() self._get_progress_page()
@patch( @patch(
......
...@@ -1647,7 +1647,7 @@ class UnifiedCourseView(View): ...@@ -1647,7 +1647,7 @@ class UnifiedCourseView(View):
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True) course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
# Render the outline as a fragment # Render the outline as a fragment
outline_fragment = CourseOutlineFragmentView().render_fragment(request, course_id=course_id) outline_fragment = CourseOutlineFragmentView().render_to_fragment(request, course_id=course_id)
# Render the entire unified course view # Render the entire unified course view
context = { context = {
...@@ -1680,7 +1680,7 @@ class CourseOutlineFragmentView(FragmentView): ...@@ -1680,7 +1680,7 @@ class CourseOutlineFragmentView(FragmentView):
return block return block
def render_fragment(self, request, course_id=None, **kwargs): def render_to_fragment(self, request, course_id=None, **kwargs):
""" """
Renders the course outline as a fragment. Renders the course outline as a fragment.
""" """
......
...@@ -111,9 +111,7 @@ django-ratelimit-backend==1.0 ...@@ -111,9 +111,7 @@ django-ratelimit-backend==1.0
unicodecsv==0.9.4 unicodecsv==0.9.4
django-require==1.0.11 django-require==1.0.11
pyuca==1.1 pyuca==1.1
web-fragments==0.1.0
wrapt==1.10.5 wrapt==1.10.5
XBlock==0.4.14
zendesk==1.1.1 zendesk==1.1.1
# This needs to be installed *after* Cython, which is in pre.txt # This needs to be installed *after* Cython, which is in pre.txt
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment