def test_require_delete_permission_ok(self): product = Product(name="Bad Beer") product.save() self.client.login(username="******", password="******") response = self.client.post("/products/delete/{}".format(product.id)) self.assertEqual(response.status_code, 302) self.assertEqual(Product.objects.all().count(), 0)
def test_require_change_permission_fails(self): product = Product(name="Bad Beer") product.save() self.client.login(username="******", password="******") response = self.client.post( "/products/{}".format(product.id), { "name": "Awesome Beer", "unit": "Hectoliter", "unit_price": "5" }, ) self.assertEqual(response.status_code, 403) self.assertEqual(Product.objects.get(id=product.id).name, "Bad Beer")
def user_can_order_product(user: User, product: Product, shift: Shift): """Check if a user can order products in a certain shift.""" if user not in shift.venue.get_users_with_order_perms(): raise OrderException("User does not have permissions to order during this shift.") if not shift.user_can_order_amount(user) and not product.ignore_shift_restrictions: raise OrderException("User can not order more products") if not product.user_can_order_amount(user, shift): raise OrderException(f"User can not order more {product.name}") return True
def handle(self, *args, **options): for file_path in options['file_path']: with open(file_path, 'r') as pricing_file: json_data = json.load(pricing_file) try: vat_bands, products = PricingFormatter.process_product_data( json_data) except PricingException as import_error: raise CommandError(import_error.message) # Update of create vat bands for vat in vat_bands.values(): try: obj = VatBand.objects.get(name=vat.get('name')) obj.rate = vat.get('rate') obj.save() except VatBand.DoesNotExist: obj = VatBand(**vat) obj.save() finally: vat_bands[vat.get('name')].update({'obj': obj}) # Update of create products for product in products.values(): associated_vat = product.pop('vat_band') try: obj = Product.objects.get( product_id=product.get('product_id')) for key, value in product.items(): setattr(obj, key, value) obj.vat_band = vat_bands[associated_vat]['obj'] obj.save() except Product.DoesNotExist: obj = Product( vat_band=vat_bands[associated_vat]['obj'], **product) obj.save() self.stdout.write( self.style.SUCCESS('Successfully imported ' 'data of "%s"' % file_path))
def test_require_name(self): product = Product() self.assertRaises(IntegrityError, product.save)
banquetType.save() lunchType = ProductType(name="AdditionalLunch", description="...") lunchType.save() eventsType = ProductType(name="Events", description="...") eventsType.save() roomsType = ProductType(name="Rooms", description="...") roomsType.save() novaType = ProductType(name="Nova", description="...") novaType.save() standType = ProductType(name="Additional Stand Area", description="...") standType.save() heightType = ProductType(name="Additional Stand Height", description="...") heightType.save() stand1 = Product(fair=fair, name="2x4 meters +14 000", description="...", price=14000, product_type=standType, coa_number=5) stand1.save() stand2 = Product(fair=fair, name="2x5 meters +26 000", description="...", price=26000, product_type=standType, coa_number=5) stand2.save() stand3 = Product(fair=fair, name="2x6 meters + 36 000", description="...", price=36000, product_type=standType, coa_number=5) stand3.save() stand4 = Product(fair=fair, name="2x7 meters +44 000", description="...", price=44000, product_type=standType, coa_number=5) stand4.save() height1 = Product(fair=fair, name="Height 2,31 - 3m +1000", description="...", price=1000, product_type=heightType, coa_number=5) height1.save() height2 = Product(fair=fair, name="Height 3 - 5m +2000", description="...", price=1000, product_type=heightType, coa_number=5) height2.save() lunch1 = Product(fair=fair, name="Additional lunch tickets day 1 (21 November) +125 /Ticket", description="...", price=125, product_type=lunchType, coa_number=5) lunch1.save() lunch2 = Product(fair=fair, name="Additional lunch tickets day 2 (22 November) +125 /Ticket", description="...", price=125, product_type=lunchType, coa_number=5) lunch2.save()