Esempio n. 1
0
 def _add_5_products(self):
     for i in range(5):
         p = Product()
         p.title = 'prod%d' % (i)
         p.description = 'product%d' % (i)
         p.quantity = i
         p.save()
Esempio n. 2
0
 def _add_5_products(self):
     for i in range(5):
         p = Product()
         p.title = 'prod%d'%(i)
         p.description = 'product%d'%(i)
         p.quantity = i
         p.save()
Esempio n. 3
0
 def test_sell_method(self):
     p = Product(title='title', description='desc', quantity=self.randint)
     p.save()
     p.sell()
     p = Product.objects.get(pk=p.pk)
     self.assertEquals(
         p.quantity, self.randint - 1,
         "Testing that the quantity was decreased when calling sell")
Esempio n. 4
0
    def handle(self, *args, **options):
        filename = options['filename']

        try:
            with open(filename, 'r') as stream:
                try:
                    data = yaml.safe_load(stream)
                except yaml.YAMLError as exc:
                    raise CommandError(exc)
        except FileNotFoundError:
            raise CommandError('File "%s" does not exist' % filename)

        shop, created = Shop.objects.get_or_create(
            name=data['shop'],
            url='example.com',
            filename=filename,
        )

        for item in data['categories']:
            category, created = Category.objects.get_or_create(
                id=item['id'],
                name=item['name'],
            )
            category.shops.add(shop)

        for item in data['goods']:
            product = Product(
                id=item['id'],
                name=item['name'],
                category=Category.objects.get(pk=item['category']),
            )
            product.save()

            product_info = ProductInfo(
                name=item['name'],
                quantity=item['quantity'],
                price=item['price'],
                price_rrc=item['price_rrc'],
                product=product,
            )
            product_info.save()
            product_info.shops.add(shop)

            for name, value in item['parameters'].items():
                parameter, created = Parameter.objects.get_or_create(
                    name=name, )

                product_parameter = ProductParameter(
                    value=value,
                    product_info=product_info,
                    parameter=parameter,
                )
                product_parameter.save()
Esempio n. 5
0
 def test_sell_method(self):
     p = Product(title='title', description='desc', quantity=self.randint)
     p.save()
     p.sell()
     p = Product.objects.get(pk=p.pk)
     self.assertEquals(p.quantity, self.randint - 1, "Testing that the quantity was decreased when calling sell")