# Path: simplestore/products/models/product.py
# class Product(models.Model):
#     name = models.CharField(max_length=255)
#     slug = models.SlugField(unique=True)
#     sku = models.CharField(
#         max_length=50,
#         verbose_name='Reference Number',
#         unique=True
#     )
#     created_at = models.DateTimeField(auto_now=True, db_index=True)
#     updated_at = models.DateTimeField(auto_now_add=True, db_index=True)
#     image = FilerImageField(null=True, blank=True, on_delete=models.DO_NOTHING)
#     price = models.DecimalField(max_digits=10, decimal_places=2)
#     perex = models.TextField(max_length=255)
#     content = models.TextField(verbose_name='Content Description')
#     category = models.ManyToManyField(Category, blank=True)
#     is_active = models.BooleanField(default=True, verbose_name='Active')
#     is_featured = models.BooleanField(default=False, verbose_name='Featured')
# 
#     objects = ProductManager()
# 
#     _metadata = {
#         'description': 'content',
#     }
# 
#     class Meta:
#         ordering = ['-created_at']
# 
#     @property
#     def get_image_url(self):
#         return self.image.url
# 
#     def get_absolute_url(self):
#         return reverse('products:detail', kwargs={'slug': self.slug})
# 
#     def __str__(self):
#         return self.name
# 
# Path: simplestore/products/views.py
# class ProductsListView(ListView):
#     model = Product
#     queryset = Product.objects.all().active().prefetch_related('image')
#     template_name = "product_list.html"
# 
# class ProductDetailView(DetailView):
#     model = Product
#     template_name = "product_detail.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(ProductDetailView, self).get_context_data(**kwargs)
#         context['form'] = AddToCartForm
#         return context


from django.core.urlresolvers import reverse, resolve
from django.test import TestCase, RequestFactory
from simplestore.products.models.product import Product
from simplestore.products.views import ProductsListView, ProductDetailView
            sku='PROD002',
            is_active=True,
        )

        cls.product_third = Product.objects.create(
            name='Test Product 3',
            slug='test-product-3',
            price=160,
            sku='PROD200001',
            is_active=False,
        )

    # Products Category tests
    def test_products_list_resolves_to_product_list_view(self):
        """Check if ProductList URL is matching correct view."""
        product_list = resolve(self.product_list_url)
        self.assertEqual(product_list.func.__name__, ProductsListView.__name__)

    def test_products_list_use_product_list_template(self):
        """
        Check if ProductList URL is using correct template.
        """
        url = self.client.get(self.product_list_url)
        self.assertTemplateUsed(url, template_name='product_list.html')

    def test_products_to_return_success_response(self):
        """
        ProductListView should return success response
        """
        request = self.factory.get(self.product_list_url)

# Path: simplestore/products/models/product.py
# class Product(models.Model):
#     name = models.CharField(max_length=255)
#     slug = models.SlugField(unique=True)
#     sku = models.CharField(
#         max_length=50,
#         verbose_name='Reference Number',
#         unique=True
#     )
#     created_at = models.DateTimeField(auto_now=True, db_index=True)
#     updated_at = models.DateTimeField(auto_now_add=True, db_index=True)
#     image = FilerImageField(null=True, blank=True, on_delete=models.DO_NOTHING)
#     price = models.DecimalField(max_digits=10, decimal_places=2)
#     perex = models.TextField(max_length=255)
#     content = models.TextField(verbose_name='Content Description')
#     category = models.ManyToManyField(Category, blank=True)
#     is_active = models.BooleanField(default=True, verbose_name='Active')
#     is_featured = models.BooleanField(default=False, verbose_name='Featured')
# 
#     objects = ProductManager()
# 
#     _metadata = {
#         'description': 'content',
#     }
# 
#     class Meta:
#         ordering = ['-created_at']
# 
#     @property
#     def get_image_url(self):
#         return self.image.url
# 
#     def get_absolute_url(self):
#         return reverse('products:detail', kwargs={'slug': self.slug})
# 
#     def __str__(self):
#         return self.name
# 
# Path: simplestore/products/views.py
# class ProductsListView(ListView):
#     model = Product
#     queryset = Product.objects.all().active().prefetch_related('image')
#     template_name = "product_list.html"
# 
# class ProductDetailView(DetailView):
#     model = Product
#     template_name = "product_detail.html"
# 
#     def get_context_data(self, **kwargs):
#         context = super(ProductDetailView, self).get_context_data(**kwargs)
#         context['form'] = AddToCartForm
#         return context


# Path: simplestore/products/tests/test_views.py
from django.core.urlresolvers import reverse, resolve
from django.test import TestCase, RequestFactory
from simplestore.products.models.product import Product
from simplestore.products.views import ProductsListView, ProductDetailView

            sku='PROD002',
            is_active=True,
        )

        cls.product_third = Product.objects.create(
            name='Test Product 3',
            slug='test-product-3',
            price=160,
            sku='PROD200001',
            is_active=False,
        )

    # Products Category tests
    def test_products_list_resolves_to_product_list_view(self):
        """Check if ProductList URL is matching correct view."""
        product_list = resolve(self.product_list_url)
        self.assertEqual(product_list.func.__name__, ProductsListView.__name__)

    def test_products_list_use_product_list_template(self):
        """
        Check if ProductList URL is using correct template.
        """
        url = self.client.get(self.product_list_url)
        self.assertTemplateUsed(url, template_name='product_list.html')

    def test_products_to_return_success_response(self):
        """
        ProductListView should return success response
        """
        request = self.factory.get(self.product_list_url)

        response = ProductsListView.as_view()(request)