Commit 1eb85a23 by Awais

ECOM-1869 adding new attribute credit hours.

parent c2d755a6
......@@ -115,7 +115,7 @@ class Course(models.Model):
return name
def create_or_update_seat(self, certificate_type, id_verification_required, price, credit_provider=None,
expires=None):
expires=None, credit_hours=None):
"""
Creates course seat products.
......@@ -152,6 +152,9 @@ class Course(models.Model):
if credit_provider:
seat.attr.credit_provider = credit_provider
if credit_hours:
seat.attr.credit_hours = credit_hours
seat.save()
# TODO Expose via setting
......
......@@ -138,7 +138,7 @@ class CourseTests(CourseCatalogTestMixin, TestCase):
self.assertEqual(parent.attr.course_key, course.id)
def assert_course_seat_valid(self, seat, course, certificate_type, id_verification_required, price,
credit_provider=None):
credit_provider=None, credit_hours=None):
""" Ensure the given seat has the correct attribute values. """
self.assertEqual(seat.structure, Product.CHILD)
# pylint: disable=protected-access
......@@ -152,6 +152,9 @@ class CourseTests(CourseCatalogTestMixin, TestCase):
if credit_provider:
self.assertEqual(seat.attr.credit_provider, credit_provider)
if credit_hours:
self.assertEqual(seat.attr.credit_hours, credit_hours)
def test_create_or_update_seat(self):
""" Verify the method creates or updates a seat Product. """
course = Course.objects.create(id='a/b/c', name='Test Course')
......@@ -170,12 +173,17 @@ class CourseTests(CourseCatalogTestMixin, TestCase):
# Test update
price = 100
credit_provider = 'MIT'
course.create_or_update_seat(certificate_type, id_verification_required, price, credit_provider)
credit_hours = 2
course.create_or_update_seat(
certificate_type, id_verification_required, price, credit_provider, credit_hours=credit_hours
)
# Again, only two seats with one being the parent seat product.
self.assertEqual(course.products.count(), 2)
seat = course.seat_products[0]
self.assert_course_seat_valid(seat, course, certificate_type, id_verification_required, price, credit_provider)
self.assert_course_seat_valid(
seat, course, certificate_type, id_verification_required, price, credit_provider, credit_hours=credit_hours
)
def test_type(self):
""" Verify the property returns a type value corresponding to the available products. """
......
......@@ -27,6 +27,7 @@ class CheckoutPageTest(UserMixin, CourseCatalogTestMixin, TestCase):
self.provider = 'ASU'
self.price = 100
self.thumbnail_url = 'http://www.edx.org/course.jpg'
self.credit_hours = 2
# Create the course
self.course = Course.objects.create(
id=u'edx/Demo_Course/DemoX',
......@@ -35,7 +36,9 @@ class CheckoutPageTest(UserMixin, CourseCatalogTestMixin, TestCase):
)
# Create the credit seat
self.seat = self.course.create_or_update_seat('credit', True, self.price, self.provider)
self.seat = self.course.create_or_update_seat(
'credit', True, self.price, self.provider, credit_hours=self.credit_hours
)
@property
def path(self):
......@@ -74,3 +77,8 @@ class CheckoutPageTest(UserMixin, CourseCatalogTestMixin, TestCase):
# Verify the payment processors are returned
self.assertEqual(sorted(response.context['payment_processors'].keys()),
sorted([get_processor_class(path).NAME.lower() for path in settings.PAYMENT_PROCESSORS]))
self.assertContains(
response,
'You are purchasing {} credit hours for'.format(self.credit_hours)
)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
def create_credit_hours_attribute(apps, schema_editor):
# Get seat Object
ProductClass = apps.get_model('catalogue', 'ProductClass')
seat = ProductClass.objects.get(name='Seat')
# Create our Product Attributes
ProductAttribute = apps.get_model('catalogue', 'ProductAttribute')
ProductAttribute.objects.create(
product_class=seat,
name='credit_hours',
code='credit_hours',
type='integer',
required=False
)
def delete_credit_hours_attribute(apps, schema_editor):
"""For backward compatibility"""
# Delete our Product Attributes
ProductAttribute = apps.get_model('catalogue', 'ProductAttribute')
ProductAttribute.objects.filter(code='credit_hours').delete()
class Migration(migrations.Migration):
dependencies = [
('catalogue', '0008_auto_20150709_1254'),
]
operations = [
migrations.RunPython(create_credit_hours_attribute, delete_credit_hours_attribute),
]
......@@ -37,6 +37,7 @@ class CourseCatalogTestMixin(object):
('course_key', 'text'),
('credit_provider', 'text'),
('id_verification_required', 'boolean'),
('credit_hours', 'integer'),
)
for code, attr_type in attributes:
......
......@@ -12,7 +12,11 @@
</div>
<div class="col-sm-9">
<h3 class="title">
Purchasing credit for:
{% blocktrans count hours=credit_seats.0.attr.credit_hours %}
You are purchasing 1 credit hour for:
{% plural %}
You are purchasing {{ hours }} credit hours for:
{% endblocktrans %}
<span class="course-title text-nowrap">{{ course.name }}</span>
</h3>
Congratulations, you are eligible to purchase credit from {{ credit_seats.0.attr.credit_provider }} by Feb 05, 2013.
......
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