Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ae1903fe
Commit
ae1903fe
authored
Apr 06, 2017
by
Andy Armstrong
Committed by
GitHub
Apr 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14829 from edx/andya/page-query-tests
Add query count tests for old and new course pages
parents
871c9310
e7a4ed74
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
31 deletions
+94
-31
lms/djangoapps/courseware/tests/test_views.py
+15
-14
lms/djangoapps/courseware/views/views.py
+6
-5
openedx/features/course_experience/tests/views/test_course_home.py
+71
-0
openedx/features/course_experience/tests/views/test_course_outline.py
+2
-12
No files found.
lms/djangoapps/courseware/tests/test_views.py
View file @
ae1903fe
...
...
@@ -205,11 +205,11 @@ class IndexQueryTestCase(ModuleStoreTestCase):
NUM_PROBLEMS
=
20
@ddt.data
(
(
ModuleStoreEnum
.
Type
.
mongo
,
10
),
(
ModuleStoreEnum
.
Type
.
split
,
4
),
(
ModuleStoreEnum
.
Type
.
mongo
,
10
,
147
),
(
ModuleStoreEnum
.
Type
.
split
,
4
,
147
),
)
@ddt.unpack
def
test_index_query_counts
(
self
,
store_type
,
expected_query_count
):
def
test_index_query_counts
(
self
,
store_type
,
expected_
mongo_query_count
,
expected_mysql_
query_count
):
with
self
.
store
.
default_store
(
store_type
):
course
=
CourseFactory
.
create
()
with
self
.
store
.
bulk_operations
(
course
.
id
):
...
...
@@ -224,17 +224,18 @@ class IndexQueryTestCase(ModuleStoreTestCase):
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
password
)
CourseEnrollment
.
enroll
(
self
.
user
,
course
.
id
)
with
check_mongo_calls
(
expected_query_count
):
url
=
reverse
(
'courseware_section'
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
),
'chapter'
:
unicode
(
chapter
.
location
.
name
),
'section'
:
unicode
(
section
.
location
.
name
),
}
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
with
self
.
assertNumQueries
(
expected_mysql_query_count
):
with
check_mongo_calls
(
expected_mongo_query_count
):
url
=
reverse
(
'courseware_section'
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
),
'chapter'
:
unicode
(
chapter
.
location
.
name
),
'section'
:
unicode
(
section
.
location
.
name
),
}
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
@attr
(
shard
=
2
)
...
...
lms/djangoapps/courseware/views/views.py
View file @
ae1903fe
...
...
@@ -495,11 +495,12 @@ class CourseTabView(EdxFragmentView):
Displays a course tab page that contains a web fragment.
"""
course_key
=
CourseKey
.
from_string
(
course_id
)
course
=
get_course_with_access
(
request
.
user
,
'load'
,
course_key
)
tab
=
CourseTabList
.
get_tab_by_type
(
course
.
tabs
,
tab_type
)
page_context
=
self
.
create_page_context
(
request
,
course
=
course
,
tab
=
tab
,
**
kwargs
)
set_custom_metrics_for_course_key
(
course_key
)
return
super
(
CourseTabView
,
self
)
.
get
(
request
,
course
=
course
,
page_context
=
page_context
,
**
kwargs
)
with
modulestore
()
.
bulk_operations
(
course_key
):
course
=
get_course_with_access
(
request
.
user
,
'load'
,
course_key
)
tab
=
CourseTabList
.
get_tab_by_type
(
course
.
tabs
,
tab_type
)
page_context
=
self
.
create_page_context
(
request
,
course
=
course
,
tab
=
tab
,
**
kwargs
)
set_custom_metrics_for_course_key
(
course_key
)
return
super
(
CourseTabView
,
self
)
.
get
(
request
,
course
=
course
,
page_context
=
page_context
,
**
kwargs
)
def
create_page_context
(
self
,
request
,
course
=
None
,
tab
=
None
,
**
kwargs
):
"""
...
...
openedx/features/course_experience/tests/views/test_course_home.py
0 → 100644
View file @
ae1903fe
"""
Tests for the course home page.
"""
from
django.core.urlresolvers
import
reverse
from
openedx.core.djangoapps.content.block_structure.api
import
get_course_in_cache
from
student.models
import
CourseEnrollment
from
student.tests.factories
import
UserFactory
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
,
check_mongo_calls
TEST_PASSWORD
=
'test'
def
course_home_url
(
course
):
"""
Returns the URL for the course's home page
"""
return
reverse
(
'edx.course_experience.course_home'
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
),
}
)
class
TestCourseHomePage
(
SharedModuleStoreTestCase
):
"""
Test the course home page.
"""
@classmethod
def
setUpClass
(
cls
):
"""Set up the simplest course possible."""
# setUpClassAndTestData() already calls setUpClass on SharedModuleStoreTestCase
# pylint: disable=super-method-not-called
with
super
(
TestCourseHomePage
,
cls
)
.
setUpClassAndTestData
():
with
cls
.
store
.
default_store
(
ModuleStoreEnum
.
Type
.
split
):
cls
.
course
=
CourseFactory
.
create
()
with
cls
.
store
.
bulk_operations
(
cls
.
course
.
id
):
chapter
=
ItemFactory
.
create
(
category
=
'chapter'
,
parent_location
=
cls
.
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
.
user
=
UserFactory
(
password
=
TEST_PASSWORD
)
CourseEnrollment
.
enroll
(
cls
.
user
,
cls
.
course
.
id
)
def
setUp
(
self
):
"""
Set up for the tests.
"""
super
(
TestCourseHomePage
,
self
)
.
setUp
()
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
TEST_PASSWORD
)
def
test_queries
(
self
):
"""
Verify that the view's query count doesn't regress.
"""
# Pre-fill the course blocks cache
get_course_in_cache
(
self
.
course
.
id
)
# Fetch the view and verify the query counts
with
self
.
assertNumQueries
(
36
):
with
check_mongo_calls
(
3
):
url
=
course_home_url
(
self
.
course
)
self
.
client
.
get
(
url
)
openedx/features/course_experience/tests/views/test_course_outline.py
View file @
ae1903fe
...
...
@@ -13,19 +13,9 @@ from student.tests.factories import UserFactory
from
xmodule.modulestore.tests.django_utils
import
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
TEST_PASSWORD
=
'test'
from
.test_course_home
import
course_home_url
def
course_home_url
(
course
):
"""
Returns the URL for the course's home page
"""
return
reverse
(
'edx.course_experience.course_home'
,
kwargs
=
{
'course_id'
:
unicode
(
course
.
id
),
}
)
TEST_PASSWORD
=
'test'
class
TestCourseOutlinePage
(
SharedModuleStoreTestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment