Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
3dd051a1
Commit
3dd051a1
authored
Sep 20, 2016
by
Renzo Lucioni
Committed by
Clinton Blackburn
Sep 20, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Roll back attempted program list optimizations
parent
54feb857
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
17 additions
and
48 deletions
+17
-48
course_discovery/apps/api/serializers.py
+0
-0
course_discovery/apps/api/tests/test_fields.py
+1
-28
course_discovery/apps/api/tests/test_serializers.py
+0
-0
course_discovery/apps/api/v1/tests/test_views/test_catalogs.py
+1
-1
course_discovery/apps/api/v1/tests/test_views/test_courses.py
+3
-3
course_discovery/apps/api/v1/tests/test_views/test_programs.py
+12
-16
No files found.
course_discovery/apps/api/serializers.py
View file @
3dd051a1
This diff is collapsed.
Click to expand it.
course_discovery/apps/api/tests/test_fields.py
View file @
3dd051a1
from
django.test
import
TestCase
from
course_discovery.apps.api.fields
import
ImageField
,
StdImageSerializerField
from
course_discovery.apps.api.tests.test_serializers
import
make_request
from
course_discovery.apps.core.tests.helpers
import
make_image_file
from
course_discovery.apps.course_metadata.tests.factories
import
ProgramFactory
from
course_discovery.apps.api.fields
import
ImageField
class
ImageFieldTests
(
TestCase
):
...
...
@@ -16,27 +13,3 @@ class ImageFieldTests(TestCase):
'width'
:
None
}
self
.
assertEqual
(
ImageField
()
.
to_representation
(
value
),
expected
)
# pylint: disable=no-member
class
StdImageSerializerFieldTests
(
TestCase
):
def
test_to_representation
(
self
):
request
=
make_request
()
# TODO Create test-only model to avoid unnecessary dependency on Program model.
program
=
ProgramFactory
(
banner_image
=
make_image_file
(
'test.jpg'
))
field
=
StdImageSerializerField
()
field
.
_context
=
{
'request'
:
request
}
# pylint: disable=protected-access
expected
=
{
size_key
:
{
'url'
:
'{}{}'
.
format
(
'http://testserver'
,
getattr
(
program
.
banner_image
,
size_key
)
.
url
),
'width'
:
program
.
banner_image
.
field
.
variations
[
size_key
][
'width'
],
'height'
:
program
.
banner_image
.
field
.
variations
[
size_key
][
'height'
]
}
for
size_key
in
program
.
banner_image
.
field
.
variations
}
self
.
assertDictEqual
(
field
.
to_representation
(
program
.
banner_image
),
expected
)
course_discovery/apps/api/tests/test_serializers.py
View file @
3dd051a1
This diff is collapsed.
Click to expand it.
course_discovery/apps/api/v1/tests/test_views/test_catalogs.py
View file @
3dd051a1
...
...
@@ -141,7 +141,7 @@ class CatalogViewSetTests(ElasticsearchTestMixin, SerializationMixin, OAuth2Mixi
CourseRunFactory
(
enrollment_end
=
enrollment_end
,
course__title
=
'ABC Test Course 2'
)
CourseRunFactory
(
enrollment_end
=
enrollment_end
,
course
=
self
.
course
)
with
self
.
assertNumQueries
(
4
0
):
with
self
.
assertNumQueries
(
4
1
):
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertListEqual
(
response
.
data
[
'results'
],
self
.
serialize_catalog_course
(
courses
,
many
=
True
))
...
...
course_discovery/apps/api/v1/tests/test_views/test_courses.py
View file @
3dd051a1
...
...
@@ -19,7 +19,7 @@ class CourseViewSetTests(SerializationMixin, APITestCase):
""" Verify the endpoint returns the details for a single course. """
url
=
reverse
(
'api:v1:course-detail'
,
kwargs
=
{
'key'
:
self
.
course
.
key
})
with
self
.
assertNumQueries
(
1
8
):
with
self
.
assertNumQueries
(
1
9
):
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
,
self
.
serialize_course
(
self
.
course
))
...
...
@@ -28,7 +28,7 @@ class CourseViewSetTests(SerializationMixin, APITestCase):
""" Verify the endpoint returns a list of all courses. """
url
=
reverse
(
'api:v1:course-list'
)
with
self
.
assertNumQueries
(
2
4
):
with
self
.
assertNumQueries
(
2
5
):
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertListEqual
(
...
...
@@ -55,6 +55,6 @@ class CourseViewSetTests(SerializationMixin, APITestCase):
keys
=
','
.
join
([
course
.
key
for
course
in
courses
])
url
=
'{root}?keys={keys}'
.
format
(
root
=
reverse
(
'api:v1:course-list'
),
keys
=
keys
)
with
self
.
assertNumQueries
(
3
5
):
with
self
.
assertNumQueries
(
3
8
):
response
=
self
.
client
.
get
(
url
)
self
.
assertListEqual
(
response
.
data
[
'results'
],
self
.
serialize_course
(
courses
,
many
=
True
))
course_discovery/apps/api/v1/tests/test_views/test_programs.py
View file @
3dd051a1
...
...
@@ -40,17 +40,15 @@ class ProgramViewSetTests(APITestCase):
def
test_retrieve
(
self
):
""" Verify the endpoint returns the details for a single program. """
program
=
ProgramFactory
()
with
self
.
assertNumQueries
(
34
):
self
.
assert_retrieve_success
(
program
)
self
.
assert_retrieve_success
(
program
)
def
test_retrieve_without_course_runs
(
self
):
""" Verify the endpoint returns data for a program even if the program's courses have no course runs. """
course
=
CourseFactory
()
program
=
ProgramFactory
(
courses
=
[
course
])
with
self
.
assertNumQueries
(
49
):
self
.
assert_retrieve_success
(
program
)
self
.
assert_retrieve_success
(
program
)
def
assert_list_results
(
self
,
url
,
expected
,
expected_query_count
):
def
assert_list_results
(
self
,
url
,
expected
):
"""
Asserts the results serialized/returned at the URL matches those that are expected.
Args:
...
...
@@ -64,9 +62,7 @@ class ProgramViewSetTests(APITestCase):
Returns:
None
"""
with
self
.
assertNumQueries
(
expected_query_count
):
response
=
self
.
client
.
get
(
url
)
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
data
[
'results'
],
ProgramSerializer
(
expected
,
many
=
True
,
context
=
{
'request'
:
self
.
request
})
.
data
...
...
@@ -76,17 +72,17 @@ class ProgramViewSetTests(APITestCase):
""" Verify the endpoint returns a list of all programs. """
expected
=
ProgramFactory
.
create_batch
(
3
)
expected
.
reverse
()
self
.
assert_list_results
(
self
.
list_path
,
expected
,
40
)
self
.
assert_list_results
(
self
.
list_path
,
expected
)
def
test_filter_by_type
(
self
):
""" Verify that the endpoint filters programs to those of a given type. """
program_type_name
=
'foo'
program
=
ProgramFactory
(
type__name
=
program_type_name
)
url
=
self
.
list_path
+
'?type='
+
program_type_name
self
.
assert_list_results
(
url
,
[
program
]
,
18
)
self
.
assert_list_results
(
url
,
[
program
])
url
=
self
.
list_path
+
'?type=bar'
self
.
assert_list_results
(
url
,
[]
,
4
)
self
.
assert_list_results
(
url
,
[])
def
test_filter_by_uuids
(
self
):
""" Verify that the endpoint filters programs to those matching the provided UUIDs. """
...
...
@@ -98,14 +94,14 @@ class ProgramViewSetTests(APITestCase):
# Create a third program, which should be filtered out.
ProgramFactory
()
self
.
assert_list_results
(
url
,
expected
,
29
)
self
.
assert_list_results
(
url
,
expected
)
@ddt.data
(
(
ProgramStatus
.
Unpublished
,
False
,
4
),
(
ProgramStatus
.
Active
,
True
,
40
),
(
ProgramStatus
.
Unpublished
,
False
),
(
ProgramStatus
.
Active
,
True
),
)
@ddt.unpack
def
test_filter_by_marketable
(
self
,
status
,
is_marketable
,
expected_query_count
):
def
test_filter_by_marketable
(
self
,
status
,
is_marketable
):
""" Verify the endpoint filters programs to those that are marketable. """
url
=
self
.
list_path
+
'?marketable=1'
ProgramFactory
(
marketing_slug
=
''
)
...
...
@@ -114,4 +110,4 @@ class ProgramViewSetTests(APITestCase):
expected
=
programs
if
is_marketable
else
[]
self
.
assertEqual
(
list
(
Program
.
objects
.
marketable
()),
expected
)
self
.
assert_list_results
(
url
,
expected
,
expected_query_count
)
self
.
assert_list_results
(
url
,
expected
)
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