Commit c37181b9 by Vedran Karačić

Merge pull request #766 from edx/dynamic-coupon-fixes

Dynamic catalog coupon fixes.
parents 9fd6f149 af181c9b
...@@ -108,8 +108,8 @@ class CouponMixin(object): ...@@ -108,8 +108,8 @@ class CouponMixin(object):
catalog(Catalog): Catalog of courses for which the coupon applies catalog(Catalog): Catalog of courses for which the coupon applies
code(str): Custom coupon code code(str): Custom coupon code
benefit_value(int): The voucher benefit value benefit_value(int): The voucher benefit value
catalog_query(str): course query string catalog_query(str): Course query string
course_seat_types(JSONField): List of seat types course_seat_types(str): A string of comma-separated list of seat types
Returns: Returns:
coupon (Coupon) coupon (Coupon)
......
...@@ -21,19 +21,19 @@ class CouponUtilsTests(CouponMixin, CourseCatalogTestMixin, CatalogPreviewMockMi ...@@ -21,19 +21,19 @@ class CouponUtilsTests(CouponMixin, CourseCatalogTestMixin, CatalogPreviewMockMi
def setUp(self): def setUp(self):
super(CouponUtilsTests, self).setUp() super(CouponUtilsTests, self).setUp()
self.query = 'key:*' self.query = 'key:*'
self.seat_types = 'verified' self.seat_type = 'verified'
self.course_id = 'course-v1:test+test+test' self.course_id = 'course-v1:test+test+test'
def test_get_seat_from_query(self): def test_get_seat_from_query(self):
""" Verify right seat is returned. """ """ Verify right seat is returned. """
course, seat = self.create_course_and_seat(course_id=self.course_id) course, seat = self.create_course_and_seat(course_id=self.course_id)
self.mock_dynamic_catalog_course_runs_api(query=self.query, course_run=course) self.mock_dynamic_catalog_course_runs_api(query=self.query, course_run=course)
response = get_seats_from_query(self.site, self.query, self.seat_types) response = get_seats_from_query(self.site, self.query, self.seat_type)
self.assertEqual(seat, response[0]) self.assertEqual(seat, response[0])
def test_get_seat_from_query_no_product(self): def test_get_seat_from_query_no_product(self):
""" Verify an empty list is returned for no matched seats. """ """ Verify an empty list is returned for no matched seats. """
course, __ = self.create_course_and_seat(seat_type='professional', course_id=self.course_id) course, __ = self.create_course_and_seat(seat_type='professional', course_id=self.course_id)
self.mock_dynamic_catalog_course_runs_api(query=self.query, course_run=course) self.mock_dynamic_catalog_course_runs_api(query=self.query, course_run=course)
response = get_seats_from_query(self.site, self.query, self.seat_types) response = get_seats_from_query(self.site, self.query, self.seat_type)
self.assertEqual(response, []) self.assertEqual(response, [])
...@@ -13,7 +13,7 @@ def get_seats_from_query(site, query, seat_types): ...@@ -13,7 +13,7 @@ def get_seats_from_query(site, query, seat_types):
Arguments: Arguments:
site (Site): current site site (Site): current site
query (str): course catalog query query (str): course catalog query
seat_types (JSON): JSON object of accepted seat types seat_types (str): a string with comma-separated accepted seat type names
Returns: Returns:
List of seat products retrieved from the course catalog query. List of seat products retrieved from the course catalog query.
......
...@@ -174,7 +174,7 @@ class CouponViewSet(EdxOrderPlacementMixin, viewsets.ModelViewSet): ...@@ -174,7 +174,7 @@ class CouponViewSet(EdxOrderPlacementMixin, viewsets.ModelViewSet):
- note (str) - note (str)
- max_uses (int) - max_uses (int)
- catalog_query (str) - catalog_query (str)
- course_seat_types (list of strings) - course_seat_types (str)
Returns: Returns:
A coupon product object. A coupon product object.
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('offer', '0003_auto_20160517_1247'),
]
operations = [
migrations.AlterField(
model_name='range',
name='course_seat_types',
field=models.CharField(max_length=255, null=True, blank=True),
),
]
...@@ -357,7 +357,7 @@ class UtilTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin, TestCase): ...@@ -357,7 +357,7 @@ class UtilTests(CouponMixin, CourseCatalogTestMixin, LmsApiMockMixin, TestCase):
title='Query coupon', title='Query coupon',
quantity=1, quantity=1,
catalog_query='course:*', catalog_query='course:*',
course_seat_types={'verified': 1} course_seat_types='verified'
) )
query_coupon.history.all().update(history_user=self.user) query_coupon.history.all().update(history_user=self.user)
self.mock_course_api_response(course=self.course) self.mock_course_api_response(course=self.course)
......
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