本文整理汇总了Python中shop.models.productmodel.Product.__unicode__方法的典型用法代码示例。如果您正苦于以下问题:Python Product.__unicode__方法的具体用法?Python Product.__unicode__怎么用?Python Product.__unicode__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shop.models.productmodel.Product
的用法示例。
在下文中一共展示了Product.__unicode__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProductTestCase
# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import __unicode__ [as 别名]
class ProductTestCase(TestCase):
def create_fixtures(self):
self.product = Product()
self.product.name = 'test'
self.product.short_description = 'test'
self.product.long_description = 'test'
self.product.unit_price = Decimal('1.0')
self.product.save()
def test_unicode_returns_proper_stuff(self):
self.create_fixtures()
ret = self.product.__unicode__()
self.assertEqual(ret, self.product.name)
def test_active_filter_returns_only_active_products(self):
self.create_fixtures()
ret1 = len(Product.objects.active())
# Set self.product to be active
self.product.active = True
self.product.save()
ret2 = len(Product.objects.active())
self.assertNotEqual(ret1, ret2)
self.assertEqual(ret1, 0)
self.assertEqual(ret2, 1)
示例2: ProductTestCase
# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import __unicode__ [as 别名]
class ProductTestCase(TestCase):
def setUp(self):
self.product = Product()
self.product.name = 'test'
self.product.unit_price = Decimal('1.0')
self.product.save()
def test_unicode_returns_proper_stuff(self):
ret = self.product.__unicode__()
self.assertEqual(ret, self.product.name)
def test_active_filter_returns_only_active_products(self):
ret1 = len(Product.objects.active())
# Set self.product to be active
self.product.active = True
self.product.save()
ret2 = len(Product.objects.active())
self.assertNotEqual(ret1, ret2)
self.assertEqual(ret1, 0)
self.assertEqual(ret2, 1)
def test_get_name_works_properly_by_default(self):
res = self.product.get_name()
self.assertEqual(res, self.product.name)
示例3: ProductTestCase
# 需要导入模块: from shop.models.productmodel import Product [as 别名]
# 或者: from shop.models.productmodel.Product import __unicode__ [as 别名]
class ProductTestCase(TestCase):
def create_fixtures(self):
self.category = Category()
self.category.name = "test_category"
self.category.save()
self.product = Product()
self.product.name = 'test'
self.product.short_description = 'test'
self.product.long_description = 'test'
self.product.unit_price = Decimal('1.0')
self.product.category = self.category
self.product.save()
def test_01_unicode_returns_proper_stuff(self):
self.create_fixtures()
ret = self.product.__unicode__()
self.assertEqual(ret, self.product.name)
def test_02_specify_returns_self_when_not_a_subclass(self):
self.create_fixtures()
ret = self.product.get_specific()
self.assertEqual(ret, self.product)
def test_03_active_filter_returns_only_active_products(self):
self.create_fixtures()
ret1 = len(Product.objects.active())
# Set self.product to be active
self.product.active = True
self.product.save()
ret2 = len(Product.objects.active())
self.assertNotEqual(ret1, ret2)
self.assertEqual(ret1, 0)
self.assertEqual(ret2, 1)
def test_04_category_unicode_returns_name(self):
self.create_fixtures()
ret = self.category.__unicode__()
self.assertEqual(ret, self.category.name)
def test_05_category_get_products_works(self):
self.create_fixtures()
ret = self.category.get_products()
self.assertEqual(len(ret),1)
cat_product = ret[0]
self.assertEqual(cat_product,self.product)