# 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



class ProductViewsTest(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.product_list_url = reverse('products:index')
        self.product_detail_url = reverse('products:detail', kwargs={
            'slug': self.product_first.slug
        })

    @classmethod
    def setUpTestData(cls):
        """
        Create 3 product objects which one of them is not active
        """
        cls.product_first = Product.objects.create(
            name='Test Product',
            price=100,
            slug='test-product',
            sku='PROD001',
            is_active=True,
        )


# 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




class ProductViewsTest(TestCase):
    def setUp(self):
        self.factory = RequestFactory()
        self.product_list_url = reverse('products:index')
        self.product_detail_url = reverse('products:detail', kwargs={
            'slug': self.product_first.slug
        })

    @classmethod
    def setUpTestData(cls):
        """
        Create 3 product objects which one of them is not active
        """
        cls.product_first = Product.objects.create(
            name='Test Product',
            price=100,
            slug='test-product',
            sku='PROD001',
            is_active=True,
        )


        cls.product_seconds = Product.objects.create(