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
ca0e52f7
Commit
ca0e52f7
authored
Nov 11, 2016
by
unawaz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding upblished check for affiliate window
parent
a3198631
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
+29
-2
course_discovery/apps/api/v1/tests/test_views/test_affiliate_window.py
+14
-0
course_discovery/apps/course_metadata/query.py
+3
-2
course_discovery/apps/course_metadata/tests/test_query.py
+12
-0
No files found.
course_discovery/apps/api/v1/tests/test_views/test_affiliate_window.py
View file @
ca0e52f7
...
...
@@ -14,6 +14,7 @@ from course_discovery.apps.api.v1.tests.test_views.mixins import SerializationMi
from
course_discovery.apps.catalogs.tests.factories
import
CatalogFactory
from
course_discovery.apps.core.tests.factories
import
UserFactory
from
course_discovery.apps.core.tests.mixins
import
ElasticsearchTestMixin
from
course_discovery.apps.course_metadata.choices
import
CourseRunStatus
from
course_discovery.apps.course_metadata.models
import
Seat
from
course_discovery.apps.course_metadata.tests.factories
import
CourseRunFactory
,
SeatFactory
...
...
@@ -142,3 +143,16 @@ class AffiliateWindowViewSetTests(ElasticsearchTestMixin, SerializationMixin, AP
with
self
.
assertNumQueries
(
8
):
response
=
self
.
client
.
get
(
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_unpublished_status
(
self
):
""" Verify the endpoint does not return CourseRuns in a non-published state. """
self
.
course_run
.
status
=
CourseRunStatus
.
Unpublished
self
.
course_run
.
save
()
CourseRunFactory
(
course
=
self
.
course
,
status
=
CourseRunStatus
.
Unpublished
)
response
=
self
.
client
.
get
(
self
.
affiliate_url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
root
=
ET
.
fromstring
(
response
.
content
)
self
.
assertEqual
(
0
,
len
(
root
.
findall
(
'product'
)))
course_discovery/apps/course_metadata/query.py
View file @
ca0e52f7
...
...
@@ -4,6 +4,7 @@ import pytz
from
django.db
import
models
from
django.db.models.query_utils
import
Q
from
course_discovery.apps.course_metadata.choices
import
CourseRunStatus
from
course_discovery.apps.course_metadata.choices
import
ProgramStatus
...
...
@@ -45,13 +46,13 @@ class CourseRunQuerySet(models.QuerySet):
def
marketable
(
self
):
""" Returns CourseRuns that can be marketed to learners.
A CourseRun is considered marketable if it has a defined slug.
A CourseRun is considered marketable if it has a defined slug
and has been published
.
Returns:
QuerySet
"""
return
self
.
exclude
(
slug__isnull
=
True
)
.
exclude
(
slug
=
''
)
return
self
.
exclude
(
slug__isnull
=
True
)
.
exclude
(
slug
=
''
)
.
filter
(
status
=
CourseRunStatus
.
Published
)
class
ProgramQuerySet
(
models
.
QuerySet
):
...
...
course_discovery/apps/course_metadata/tests/test_query.py
View file @
ca0e52f7
...
...
@@ -4,6 +4,7 @@ import ddt
import
pytz
from
django.test
import
TestCase
from
course_discovery.apps.course_metadata.choices
import
CourseRunStatus
from
course_discovery.apps.course_metadata.choices
import
ProgramStatus
from
course_discovery.apps.course_metadata.models
import
Course
,
CourseRun
,
Program
from
course_discovery.apps.course_metadata.tests.factories
import
CourseRunFactory
,
ProgramFactory
...
...
@@ -78,6 +79,17 @@ class CourseRunQuerySetTests(TestCase):
CourseRunFactory
(
slug
=
slug
)
self
.
assertEqual
(
CourseRun
.
objects
.
marketable
()
.
count
(),
0
)
@ddt.data
(
(
CourseRunStatus
.
Unpublished
,
0
),
(
CourseRunStatus
.
Published
,
1
)
)
@ddt.unpack
def
test_marketable_unpublished_exclusions
(
self
,
status
,
count
):
""" Verify the method excludes CourseRuns with Unpublished status. """
CourseRunFactory
(
status
=
status
)
self
.
assertEqual
(
CourseRun
.
objects
.
marketable
()
.
count
(),
count
)
@ddt.ddt
class
ProgramQuerySetTests
(
TestCase
):
...
...
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