Commit 815c2816 by Vedran Karačić Committed by GitHub

Merge pull request #984 from edx/vkaracic/SOL-2074

[SOL-2074] Omit expired professional courses from offer landing page.
parents f81f6bf7 c12a5aaa
...@@ -34,6 +34,7 @@ class CourseCatalogMockMixin(object): ...@@ -34,6 +34,7 @@ class CourseCatalogMockMixin(object):
"image": { "image": {
"src": "/path/to/image.jpg", "src": "/path/to/image.jpg",
}, },
'enrollment_end': None
} }
course_run_info_json = json.dumps(course_run_info) course_run_info_json = json.dumps(course_run_info)
...@@ -61,10 +62,12 @@ class CourseCatalogMockMixin(object): ...@@ -61,10 +62,12 @@ class CourseCatalogMockMixin(object):
'start': '2016-05-01T00:00:00Z', 'start': '2016-05-01T00:00:00Z',
'image': { 'image': {
'src': 'path/to/the/course/image' 'src': 'path/to/the/course/image'
} },
'enrollment_end': None
}] if course_run else [{ }] if course_run else [{
'key': 'test', 'key': 'test',
'title': 'Test course', 'title': 'Test course',
'enrollment_end': None
}], }],
} }
course_run_info_json = json.dumps(course_run_info) course_run_info_json = json.dumps(course_run_info)
......
...@@ -9,6 +9,7 @@ import httpretty ...@@ -9,6 +9,7 @@ import httpretty
import pytz import pytz
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import Http404 from django.http import Http404
from django.utils.timezone import now
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from oscar.core.loading import get_model from oscar.core.loading import get_model
from oscar.test.factories import ( from oscar.test.factories import (
...@@ -93,6 +94,7 @@ class VoucherViewSetTests(CourseCatalogMockMixin, CourseCatalogTestMixin, LmsApi ...@@ -93,6 +94,7 @@ class VoucherViewSetTests(CourseCatalogMockMixin, CourseCatalogTestMixin, LmsApi
'key': seat.course_id, 'key': seat.course_id,
'start': '2016-05-01T00:00:00Z', 'start': '2016-05-01T00:00:00Z',
'title': seat.title, 'title': seat.title,
'enrollment_end': None
}) })
new_range.add_product(seat) new_range.add_product(seat)
else: else:
...@@ -105,6 +107,7 @@ class VoucherViewSetTests(CourseCatalogMockMixin, CourseCatalogTestMixin, LmsApi ...@@ -105,6 +107,7 @@ class VoucherViewSetTests(CourseCatalogMockMixin, CourseCatalogTestMixin, LmsApi
'key': course.id, 'key': course.id,
'start': '2016-05-01T00:00:00Z', 'start': '2016-05-01T00:00:00Z',
'title': course.name, 'title': course.name,
'enrollment_end': None
}) })
new_range.add_product(seat) new_range.add_product(seat)
products.append(seat) products.append(seat)
...@@ -180,6 +183,28 @@ class VoucherViewSetTests(CourseCatalogMockMixin, CourseCatalogTestMixin, LmsApi ...@@ -180,6 +183,28 @@ class VoucherViewSetTests(CourseCatalogMockMixin, CourseCatalogTestMixin, LmsApi
self.assertTrue(offer['multiple_credit_providers']) self.assertTrue(offer['multiple_credit_providers'])
self.assertIsNone(offer['credit_provider_price']) self.assertIsNone(offer['credit_provider_price'])
def test_omitting_expired_courses(self):
"""Verify professional courses who's enrollment end datetime have passed are omitted."""
no_date_seat = CourseFactory().create_or_update_seat('professional', False, 100, partner=self.partner)
valid_seat = CourseFactory().create_or_update_seat('professional', False, 100, partner=self.partner)
expired_seat = CourseFactory().create_or_update_seat('professional', False, 100, partner=self.partner)
course_discovery_results = [{
'key': no_date_seat.attr.course_key,
'enrollment_end': None,
}, {
'key': valid_seat.attr.course_key,
'enrollment_end': str(now() + datetime.timedelta(days=1)),
}, {
'key': expired_seat.attr.course_key,
'enrollment_end': str(now() - datetime.timedelta(days=1)),
}]
products, __ = VoucherViewSet().retrieve_course_objects(course_discovery_results, 'professional')
self.assertIn(no_date_seat, products)
self.assertIn(valid_seat, products)
self.assertNotIn(expired_seat, products)
@ddt.ddt @ddt.ddt
@httpretty.activate @httpretty.activate
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
import logging import logging
from urlparse import urlparse from urlparse import urlparse
from django.shortcuts import get_object_or_404
import django_filters import django_filters
from dateutil import parser
from django.shortcuts import get_object_or_404
from django.utils.timezone import now
from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.keys import CourseKey
from oscar.core.loading import get_model from oscar.core.loading import get_model
from requests.exceptions import ConnectionError, Timeout from requests.exceptions import ConnectionError, Timeout
...@@ -91,7 +93,8 @@ class VoucherViewSet(NonDestroyableModelViewSet): ...@@ -91,7 +93,8 @@ class VoucherViewSet(NonDestroyableModelViewSet):
def retrieve_course_objects(self, results, course_seat_types): def retrieve_course_objects(self, results, course_seat_types):
""" Helper method to retrieve all the courses, products and stock records """ Helper method to retrieve all the courses, products and stock records
from course IDs in course catalog response results. from course IDs in course catalog response results. Professional courses
which have a set enrollment end date and which has passed are omitted.
Args: Args:
results(dict): Course catalog response results. results(dict): Course catalog response results.
...@@ -100,12 +103,22 @@ class VoucherViewSet(NonDestroyableModelViewSet): ...@@ -100,12 +103,22 @@ class VoucherViewSet(NonDestroyableModelViewSet):
Returns: Returns:
Querysets of products and stock records retrieved from results. Querysets of products and stock records retrieved from results.
""" """
course_ids = [result['key'] for result in results] all_course_ids = []
products = Product.objects.filter( nonexpired_course_ids = []
course_id__in=course_ids, for result in results:
attributes__name='certificate_type', all_course_ids.append(result['key'])
attribute_values__value_text__in=course_seat_types.split(',') if not result['enrollment_end'] or (
) result['enrollment_end'] and parser.parse(result['enrollment_end']) > now()
):
nonexpired_course_ids.append(result['key'])
products = []
for seat_type in course_seat_types.split(','):
products.extend(Product.objects.filter(
course_id__in=nonexpired_course_ids if seat_type == 'professional' else all_course_ids,
attributes__name='certificate_type',
attribute_values__value_text=seat_type
))
stock_records = StockRecord.objects.filter(product__in=products) stock_records = StockRecord.objects.filter(product__in=products)
return products, stock_records return products, stock_records
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment