class CategoryDetailViewTestCase(TestCase):
    def setUp(self):
        self.cat = Category()
        self.cat.name = 'Test Category'
        self.cat.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.save()
        self.product.categories.add(self.cat)
    
    def test_01_get_context_works(self):
        #self.create_fixtures()
        view = CategoryDetailView(kwargs={'pk':self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 1)
        
    def test_02_get_context_works_with_list_of_products(self):
        #self.create_fixtures()
        self.product.active = True
        self.product.save()
        view = CategoryDetailView(kwargs={'pk':self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 2)
Exemple #2
0
class CategoryDetailViewTestCase(TestCase):
    def create_fixtures(self):
        self.cat = Category()
        self.cat.name = 'Test Category'
        self.cat.save()

        self.product = Product()
        self.product.category = self.cat
        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_01_get_context_works(self):
        self.create_fixtures()
        view = CategoryDetailView(kwargs={'pk': self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 1)

    def test_02_get_context_works_with_list_of_products(self):
        self.create_fixtures()
        self.product.active = True
        self.product.save()
        view = CategoryDetailView(kwargs={'pk': self.cat.id})
        setattr(view, 'object', view.get_object())
        ret = view.get_context_data()
        self.assertEqual(len(ret), 2)
Exemple #3
0
class CategoriesTestCase(TestCase):
    def setUp(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.save()
        self.product.categories.add(self.category)
        
    def test_01_category_unicode_returns_name(self):
        #self.create_fixtures()
        ret = self.category.__unicode__()
        self.assertEqual(ret, self.category.name)
        
    def test_02_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)
Exemple #4
0
    def create_fixtures(self):
        self.cat = Category()
        self.cat.name = 'Test Category'
        self.cat.save()

        self.product = Product()
        self.product.category = self.cat
        self.product.name = 'test'
        self.product.short_description = 'test'
        self.product.long_description = 'test'
        self.product.unit_price = Decimal('1.0')
        self.product.save()
Exemple #5
0
 def setUp(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.save()
     self.product.categories.add(self.category)
 def setUp(self):
     self.cat = Category()
     self.cat.name = 'Test Category'
     self.cat.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.save()
     self.product.categories.add(self.cat)
 def create_fixtures(self):
     self.cat = Category()
     self.cat.name = 'Test Category'
     self.cat.save()
     
     self.product = Product()
     self.product.category = self.cat
     self.product.name = 'test'
     self.product.short_description = 'test'
     self.product.long_description = 'test'
     self.product.unit_price = Decimal('1.0')
     self.product.save()