Skip to content

Commit

Permalink
Merge pull request #436 from edx/unawaz/ECOM-6282-filter-out-unpublis…
Browse files Browse the repository at this point in the history
…hed-courses

adding unpublished check for affiliate window
  • Loading branch information
umar-nawaz authored Nov 15, 2016
2 parents a319863 + ca0e52f commit 5235625
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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

Expand Down Expand Up @@ -142,3 +143,16 @@ def test_permissions(self):
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')))
5 changes: 3 additions & 2 deletions course_discovery/apps/course_metadata/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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


Expand Down Expand Up @@ -45,13 +46,13 @@ def active(self):
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):
Expand Down
12 changes: 12 additions & 0 deletions course_discovery/apps/course_metadata/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand Down Expand Up @@ -78,6 +79,17 @@ def test_marketable_exclusions(self, slug):
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):
Expand Down

0 comments on commit 5235625

Please sign in to comment.