def test_product_init(self): product = Product(PRODUCT_DATA) self.assertEquals(product.id, 123) self.assertEquals(product.type, 'app') self.assertEquals(product.status, 1) self.assertEquals(product.title, 'FooBar') self.assertEquals(product.created, '2013-12-12T14:40:02.000Z') self.assertEquals(product.changed, '2014-12-12T14:40:02.000Z') self.assertEquals(product.author.id, 111) self.assertEquals(product.author.first_name, 'Foo') self.assertEquals(product.author.last_name, 'Bar')
def test_get_grade_range(self): # Test for multiple grades. data = { 'grades': [ { 'name': 'Pre-K' }, { 'name': 'K' }, { 'name': '1' }, { 'name': '2' }, ] } product = Product(data) grade_range = product.get_grade_range() self.assertEquals(grade_range, 'Pre-K - 2') # Test for single grade. data = { 'grades': [ { 'name': 'Pre-K' }, ] } product = Product(data) grade_range = product.get_grade_range() self.assertEquals(grade_range, 'Pre-K')
def test_get_pricing_summary(self): # Test for pricing structure only. data = { 'pricing_structure': [ { 'name': 'Paid' }, { 'name': 'Freemium' }, ] } product = Product(data) summary = product.get_pricing_summary() self.assertEquals(', '.join(summary), 'Paid, Freemium') # Test for pricing only. data = { 'price': '$19.99', } product = Product(data) summary = product.get_pricing_summary() self.assertEquals(', '.join(summary), '$19.99') # Test for pricing structure and price. data = { 'price': '$19.99', 'pricing_structure': [ { 'name': 'Paid' }, { 'name': 'Freemium' }, ] } product = Product(data) summary = product.get_pricing_summary() self.assertEquals(', '.join(summary), 'Paid, Freemium, $19.99')
def get_product(self, id): """ Get product detail data. """ endpoint = '/v3/educator/products/%s' % id result = self.request(endpoint) data = result.response # Dynamically load product instance. class_name = data.type.capitalize() product = Product.instance(class_name, data) return product
def get_products(self, query_args={}): """ Get a list of product data. """ endpoint = '/v3/educator/products' result = self.request(endpoint, query_args) products = [] for data in result.response: # Dynamically load product instance. class_name = data.type.capitalize() product = Product.instance(class_name, data) products.append(product) return products