Exemplo n.º 1
0
class CartViewTest(TestCase):
    def setUp(self):
        self.producer = Producer(name='Tine meierier')
        self.producer.save()
        self.product = Product(name='Jarlsberg med 27% fett',
                               price=121.,
                               mass=700.,
                               massUnit=Product.GRAM,
                               producer=self.producer)
        self.product.save()

    def test_cart_widget(self):
        client = Client()
        client.post(reverse('cart_add'), {'product_id': self.product.id, 'quantity': 1})
        response = client.get(reverse('cart_widget'))
        self.assertContains(response, 'Jarlsberg med 27% fett')
Exemplo n.º 2
0
 def setUp(self):
     self.producer = Producer(name='Tine meierier')
     self.producer.save()
     self.product = Product(name='Jarlsberg med 27% fett',
                            price=121.,
                            mass=700.,
                            massUnit=Product.GRAM,
                            producer=self.producer)
     self.product.save()
Exemplo n.º 3
0
class ProductTest(TestCase):

    def setUp(self):
        self.producer = Producer(name='Tine meierier')
        self.producer.save()
        self.product = Product(name='Jarlsberg med 27% fett',
                               price=121.,
                               mass=700.,
                               massUnit=Product.GRAM,
                               producer=self.producer)
        self.product.save()

    def test_product_detail_view_should_contain_the_correct_data(self):
        client = Client()
        response = client.get(reverse('product_detail', args=[self.product.id]))
        self.assertContains(response, 'Jarlsberg med 27% fett')
        self.assertContains(response, '121')
        self.assertContains(response, '700')
        self.assertContains(response, Product.GRAM)
        self.assertContains(response, 'Tine meierier')
        self.assertContains(response, '172.86 kr/kg')

    def test_pretty_price_per_mass(self):
        self.assertEqual(self.product.pretty_price_per_mass(), u'172.86 kr/kg')
Exemplo n.º 4
0
 name = datas[3].string
 description_box = datas[4].string
 attribute_description = datas[5].string
 product_sub = datas[6].string
 bullet_points = datas[7].string
 img = datas[8].string
 product_category = datas[10].string
 product_category_parent = datas[9].string
 photo_caption = datas[11].string
 
 product = None
 try:
     product = Product.objects.filter(sku=sku).get()
         
 except:
     product = Product(sku=sku)
     product.category_id = find_category_by_name(product_category,product_category_parent)
     if(product.category_id >= 0):
         pass
     else:
         categories_not_found.append(product.sku)
     product.img = img
     product.weight = 5
 
 #            accumulate all products with same name
 similar_rows = []
 similar_rows.append(datas)
 row_offset = i
 for row1 in rows[i+1:]:
     datas1 = row1.findAll("data")
     
from Products.models import Product
from Ebooks.models import Ebook
import csv
with open('static/csv/final_ebooks.csv', encoding="utf-8") as csv_file:
    reader = csv.reader(csv_file, delimiter=';')
    for row in reader:
        product = Product(SKU=row[0],
                          Title=row[1],
                          Author=row[2],
                          Genre=row[3],
                          Price=row[4],
                          Image_URL=row[5])
        ebook = Ebook(product=product)
        try:
            product.save()
            ebook.save()
        except:
            pass
            if(prev_category and len(product['categories']) < 4):
                prev_category.children_ids += str(c.id) + ','
                prev_category.save()
            prev_category = c
    except:
#         print "no categories for " + str(product['name'])
        pass


            
for product_sku in products_json.keys():
    product = products_json[product_sku]
    try:      
        category_name = product['categories'][len(product['categories'])-1]     
        category_id = Category.objects.get(name=category_name).id
    except:
        category_id = -1
    name = product['name']
    sku = product_sku
    price = product['price']
    short_description = product['short_description']
    if(not short_description):
        short_description = ""
    description = product['description']
    if(not description):
        description = ""
    
    p = Product(sku=sku,name=name,category_id=category_id,price=price,short_description=short_description,description=description,attribute_type=0)
    p.save()