def init(request): def getSpeed(n,start,stop): return str(math.floor(n/(stop-start))) html = "" n_articles = 1000 n_customers = 1000 start = time.time() articles = Article.init(n_articles) stop = time.time() html += getSpeed(n_articles,start,stop) + " articles/s" html += "<br><br>" start = time.time() customers = Customer.init(n_customers) stop = time.time() html += getSpeed(n_customers,start,stop) + " customers/s" html += "<br><br>" start = time.time() Rent.init(articles, customers) stop = time.time() html += getSpeed(n_articles * n_customers,start,stop) + " rents/s" return HttpResponse(html)
def setUp(self): self.user = User(username='******', password='******') self.user.save() self.game = Game( name='BANG', description='Juego de mesa extremadamente satisfactorio', status="Nuevo", price=22.5, picture='http://www.foto.com/foto.png', owner=self.user) self.game.save() self.rent = Rent(ticker='ABC-1234', days=4, initial_date=parse_date("2020-07-13"), game=self.game, user=self.user, rentable=True) self.rent.save() self.contend = Contend( owner=self.user, rent=self.rent, status='Buen método de pago', description='El pago se efectua de forma segura', price=55.75) self.contend.save()
def rent_game(request, id_game): dato = get_object_or_404(Game, pk=id_game) user = get_object_or_404(User, pk=request.user.id) letters = string.ascii_uppercase digits = string.digits ramdomLetters = ''.join(random.choice(letters) for i in range(3)) ramdomNumber = ''.join(random.choice(digits) for i in range(4)) ticker = ramdomLetters + '-' + ramdomNumber rent = Rent(ticker=ticker, game=dato, user=user, rentable=False) rent.save()
def setUp(self): self.user = User(username='******', password='******') self.user.save() self.game = Game(name='BANG', description='descripcion', status=Status.PE, price=2.5, picture='http://www.foto.com/foto.png', address='Los remedios', owner=self.user) self.game.save() self.rent = Rent(ticker='ABC-1234', game=self.game, user=self.user, rentable=True) self.rent.save()
def rentproduct(request, id): category = Category.objects.all() product = Product.objects.get(pk=id) current_user = request.user url=request.META.get('HTTP_REFERER') profile = UserProfile.objects.get(user_id=current_user.id) shopcart = ShopCart.objects.filter(user_id=current_user.id) total=0 for rs in shopcart: total = (rs.end_date-rs.start_date).days*rs.price if request.method == 'POST': # if there is a post form1 = RentForm(request.POST) form2 = ShopCartForm(request.POST) if form2.is_valid(): current_user=request.user data=ShopCart() data.user_id=current_user.id data.product_id=id data.total=total data.start_date=form2.cleaned_data['start_date'] data.end_date=form2.cleaned_data['end_date'] data.save() messages.success(request,"Günleriniz başarılı bir şekilde kaydedildi") shopcart = ShopCart.objects.filter(user_id=current_user.id) total = 0 for rs in shopcart: total = (rs.end_date - rs.start_date).days * rs.price return render(request, 'Rent_Form.html', {'category': category, 'form1': form1, 'form2': form2, 'profile': profile, 'product': product, 'total': total, }) if form1.is_valid(): data = Rent() data.first_name = form1.cleaned_data['first_name'] data.last_name = form1.cleaned_data['last_name'] data.address = form1.cleaned_data['address'] data.city = form1.cleaned_data['city'] data.phone = form1.cleaned_data['phone'] data.user_id = current_user.id data.total = total data.ip = request.META.get('REMOTE_ADDR') rentcode = get_random_string(5).upper() data.code = rentcode data.save() shopcart=ShopCart.objects.filter(user_id=current_user.id) for rs in shopcart: detail=RentProduct() detail.rent_id=data.id detail.product_id=rs.product_id detail.user_id=current_user.id detail.start_date=rs.start_date detail.end_date=rs.end_date product = Product.objects.get(id=rs.product_id) detail.price=rs.product.price detail.amount=rs.amount.days detail.save() ShopCart.objects.filter(user_id=current_user.id).delete() request.session['cart_items']=0 messages.success(request, "Your Order has been completed. Thank you ") return render(request, 'Order_Completed.html', {'rentcode': rentcode, 'category': category}) else: messages.warning(request, form1.errors) return HttpResponseRedirect("/rent/rentproduct/" + str(id)) form1 = RentForm() form2 = ShopCartForm() context = {'category': category, 'form1': form1, 'form2': form2, 'profile': profile, 'product': product, } return render(request, 'Rent_Form.html', context)
class PaymentModelTestCase(TestCase): #Prepara una bbdd default con los objetos que se van a testear en este TestCase ------------------- def setUp(self): self.user = User(username='******', password='******') self.user.save() self.game = Game( name='BANG', description='Juego de mesa extremadamente satisfactorio', status="Nuevo", price=22.5, picture='http://www.foto.com/foto.png', owner=self.user) self.game.save() self.rent = Rent(ticker='ABC-1234', days=4, initial_date=parse_date("2020-07-13"), game=self.game, user=self.user, rentable=True) self.rent.save() self.contend = Contend( owner=self.user, rent=self.rent, status='Buen método de pago', description='El pago se efectua de forma segura', price=55.75) self.contend.save() #Batería de test unitarios ------------------------------------------------------------------------ def test_get_owner(self): self.assertEquals(self.contend.owner, self.user) def test_get_rent(self): self.assertEquals(self.contend.rent, self.rent) def test_get_description(self): self.assertEquals(self.contend.description, 'El pago se efectua de forma segura') def test_get_status(self): self.assertEquals(self.contend.status, 'Buen método de pago') def test_get_price(self): self.assertEquals(self.contend.price, 55.75) def test_creation_contend(self): Contend(owner=self.user, rent=self.rent, status='Buen método de pago', description='El pago se efectua de forma segura', price=55.75).save() contends = Contend.objects.all() self.assertEquals(contends.count(), 2) def test_edit_contend(self): Contend.objects.filter(id=self.contend.id).update( owner=self.user, rent=self.rent, status='Transferencia', description='Sus millones están en camino', price=65.95) contend = Contend.objects.get(id=self.contend.id) self.assertEquals(contend.owner, self.user) self.assertEquals(contend.rent, self.rent) self.assertEquals(contend.status, 'Transferencia') self.assertEquals(contend.description, 'Sus millones están en camino') self.assertEquals(contend.price, 65.95) def test_delete_contend(self): self.contend2 = Contend(owner=self.user, rent=self.rent, status='Transferencia', description='Sus millones están en camino', price=65.95) self.contend2.save() self.assertEquals(2, Contend.objects.count()) self.contend2.delete() self.assertEquals(1, Contend.objects.count()) # Borra los datos para terminar con los test ------------------------------------------------------ def tearDown(self): self.rent.delete() self.game.delete() self.user.delete() self.contend.delete()
class GameModelTestCase(TestCase): #Prepara una bbdd default con los objetos que se van a testear en este TestCase ------------------- def setUp(self): self.user = User(username='******', password='******') self.user.save() self.game = Game(name='BANG', description='descripcion', status=Status.PE, price=2.5, picture='http://www.foto.com/foto.png', address='Los remedios', owner=self.user) self.game.save() self.rent = Rent(ticker='ABC-1234', game=self.game, user=self.user, rentable=True) self.rent.save() #Batería de test unitarios ------------------------------------------------------------------------ def test_get_owner(self): self.assertEquals(self.game.owner, self.user) def test_get_name(self): self.assertEquals(self.game.name, 'BANG') def test_get_description(self): self.assertEquals(self.game.description, 'descripcion') def test_get_status(self): self.assertEquals(self.game.status, Status.PE) def test_get_price(self): self.assertEquals(self.game.price, 2.5) def test_get_picture(self): self.assertEquals(self.game.picture, 'http://www.foto.com/foto.png') def test_get_address(self): self.assertEquals(self.game.address, 'Los remedios') def test_get_ticker(self): self.assertEquals(self.rent.ticker, 'ABC-1234') def test_get_game(self): self.assertEquals(self.rent.game, self.game) def test_get_user(self): self.assertEquals(self.rent.user, self.user) def test_get_rentable(self): self.assertEquals(self.rent.rentable, True) #Borra los datos para terminar con los test ------------------------------------------------------ def tearDown(self): self.rent.delete() self.game.delete() self.user.delete()