Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
9ff9c33f
Commit
9ff9c33f
authored
6 years ago
by
Calen Pennington
Browse files
Options
Downloads
Patches
Plain Diff
Add a test that shows how bad course api query counts are
parent
945debb0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lms/djangoapps/course_api/tests/test_views.py
+58
-0
58 additions, 0 deletions
lms/djangoapps/course_api/tests/test_views.py
openedx/core/djangolib/testing/utils.py
+3
-0
3 additions, 0 deletions
openedx/core/djangolib/testing/utils.py
with
61 additions
and
0 deletions
lms/djangoapps/course_api/tests/test_views.py
+
58
−
0
View file @
9ff9c33f
"""
Tests for Course API views.
"""
from
datetime
import
datetime
import
ddt
from
hashlib
import
md5
...
...
@@ -12,8 +13,14 @@ from search.tests.test_course_discovery import DemoCourse
from
search.tests.tests
import
TEST_INDEX_NAME
from
search.tests.utils
import
SearcherMixin
from
course_modes.models
import
CourseMode
from
course_modes.tests.factories
import
CourseModeFactory
from
edx_django_utils.cache
import
RequestCache
from
openedx.core.lib.tests
import
attr
from
openedx.features.content_type_gating.models
import
ContentTypeGatingConfig
from
openedx.features.course_duration_limits.models
import
CourseDurationLimitConfig
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
,
SharedModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
waffle.testutils
import
override_switch
from
..views
import
CourseDetailView
,
CourseListUserThrottle
...
...
@@ -283,6 +290,7 @@ class CourseListSearchViewTest(CourseApiTestViewMixin, ModuleStoreTestCase, Sear
"""
ENABLED_SIGNALS
=
[
'
course_published
'
]
ENABLED_CACHES
=
ModuleStoreTestCase
.
ENABLED_CACHES
+
[
'
configuration
'
]
def
setUp
(
self
):
super
(
CourseListSearchViewTest
,
self
).
setUp
()
...
...
@@ -298,6 +306,7 @@ class CourseListSearchViewTest(CourseApiTestViewMixin, ModuleStoreTestCase, Sear
self
.
url
=
reverse
(
'
course-list
'
)
self
.
staff_user
=
self
.
create_user
(
username
=
'
staff
'
,
is_staff
=
True
)
self
.
honor_user
=
self
.
create_user
(
username
=
'
honor
'
,
is_staff
=
False
)
self
.
audit_user
=
self
.
create_user
(
username
=
'
audit
'
,
is_staff
=
False
)
def
create_and_index_course
(
self
,
org_code
,
short_description
):
"""
...
...
@@ -348,3 +357,52 @@ class CourseListSearchViewTest(CourseApiTestViewMixin, ModuleStoreTestCase, Sear
self
.
assertIn
(
'
results
'
,
res
.
data
)
self
.
assertNotEqual
(
res
.
data
[
'
results
'
],
[])
self
.
assertEqual
(
res
.
data
[
'
pagination
'
][
'
count
'
],
1
)
# Should list a single course
def
test_too_many_courses
(
self
):
"""
Test that search results are limited to 100 courses, and that they don
'
t
blow up the database.
"""
ContentTypeGatingConfig
.
objects
.
create
(
enabled
=
True
,
enabled_as_of
=
datetime
(
2018
,
1
,
1
),
)
CourseDurationLimitConfig
.
objects
.
create
(
enabled
=
True
,
enabled_as_of
=
datetime
(
2018
,
1
,
1
),
)
course_ids
=
[]
# Create 300 courses across 30 organizations
for
org_num
in
range
(
10
):
org_id
=
'
org{}
'
.
format
(
org_num
)
for
course_num
in
range
(
30
):
course_name
=
'
course{}.{}
'
.
format
(
org_num
,
course_num
)
course_run_name
=
'
run{}.{}
'
.
format
(
org_num
,
course_num
)
course
=
CourseFactory
.
create
(
org
=
org_id
,
number
=
course_name
,
run
=
course_run_name
,
emit_signals
=
True
)
CourseModeFactory
.
create
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
AUDIT
)
CourseModeFactory
.
create
(
course_id
=
course
.
id
,
mode_slug
=
CourseMode
.
VERIFIED
)
course_ids
.
append
(
course
.
id
)
self
.
setup_user
(
self
.
audit_user
)
# These query counts were found empirically
query_counts
=
[
1266
,
349
,
349
,
349
,
349
,
349
,
349
,
349
,
349
,
349
,
322
]
ordered_course_ids
=
sorted
([
str
(
cid
)
for
cid
in
(
course_ids
+
[
c
.
id
for
c
in
self
.
courses
])])
self
.
clear_caches
()
for
page
in
range
(
1
,
12
):
with
self
.
assertNumQueries
(
query_counts
[
page
-
1
]):
response
=
self
.
verify_response
(
params
=
{
'
page
'
:
page
,
'
page_size
'
:
30
})
self
.
assertIn
(
'
results
'
,
response
.
data
)
self
.
assertEqual
(
response
.
data
[
'
pagination
'
][
'
count
'
],
303
)
self
.
assertEqual
(
len
(
response
.
data
[
'
results
'
]),
30
if
page
<
11
else
3
)
self
.
assertEqual
(
[
c
[
'
id
'
]
for
c
in
response
.
data
[
'
results
'
]],
ordered_course_ids
[(
page
-
1
)
*
30
:
page
*
30
]
)
This diff is collapsed.
Click to expand it.
openedx/core/djangolib/testing/utils.py
+
3
−
0
View file @
9ff9c33f
...
...
@@ -73,6 +73,9 @@ class CacheIsolationMixin(object):
'
BACKEND
'
:
'
django.core.cache.backends.locmem.LocMemCache
'
,
'
LOCATION
'
:
cache_name
,
'
KEY_FUNCTION
'
:
'
util.memcache.safe_key
'
,
'
OPTIONS
'
:
{
'
MAX_ENTRIES
'
:
1000
,
},
}
for
cache_name
in
cls
.
ENABLED_CACHES
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment