Example #1
0
 def test_delete_a_cart(self):
     """ Delete a Cart """
     shopcart = ShoppingCart(state="activated", userId=5)
     shopcart.save()
     self.assertEqual(len(ShoppingCart.all()), 1)
     # delete the cart and make sure it isn't in the database
     shopcart.delete()
     self.assertEqual(len(ShoppingCart.all()), 0)
Example #2
0
 def test_find_cart(self):
     """ Find a Cart by ID """
     ShoppingCart(state="activated", userId=7).save()
     deactivated = ShoppingCart(state="deactivated", userId=8)
     deactivated.save()
     shopcart = ShoppingCart.find(deactivated.id)
     self.assertIsNot(shopcart, None)
     self.assertEqual(shopcart.id, deactivated.id)
     self.assertEqual(shopcart.state, "deactivated")
     self.assertEqual(shopcart.userId, 8)
Example #3
0
def create_carts():
    """ Create a new Cart """
    app.logger.info('Create Cart requested')
    check_content_type('application/json')
    cart = ShoppingCart(None)
    cart.deserialize(request.get_json())
    cart.save()
    app.logger.info('Created Cart with id: {}'.format(cart.id))
    return make_response(
        jsonify(cart.serialize()), status.HTTP_201_CREATED,
        {'Location': url_for('get_carts', cart_id=cart.id, _external=True)})
Example #4
0
 def test_add_a_cart(self):
     """ Create a cart and add it to the database """
     shopcarts = ShoppingCart.all()
     self.assertEqual(shopcarts, [])
     shopcart = ShoppingCart(state="activated", userId=5)
     self.assertTrue(shopcart != None)
     self.assertEqual(shopcart.id, None)
     shopcart.save()
     # Asert that it was assigned an id and shows up in the database
     self.assertEqual(shopcart.id, 1)
     shopcarts = ShoppingCart.all()
     self.assertEqual(len(shopcarts), 1)
Example #5
0
 def test_update_a_cart(self):
     """ Update a ShopCart """
     shopcart = ShoppingCart(state="activated", userId=5)
     shopcart.save()
     self.assertEqual(shopcart.id, 1)
     # Change it an save it
     shopcart.state = "deactivated"
     shopcart.save()
     self.assertEqual(shopcart.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     shopcarts = ShoppingCart.all()
     self.assertEqual(len(shopcarts), 1)
     self.assertEqual(shopcarts[0].state, "deactivated")
Example #6
0
def buy(request):
    userid = request.GET.get('userid')
    movieid = request.GET.get('movieid')
    price = request.GET.get('price')
    quantity = request.GET.get('quantity')
    seats = request.GET.get('seats')
    userfor = User.objects.filter(id=userid).first()
    moviesfor = Movies.objects.filter(id=movieid).first()
    shopping = ShoppingCart()
    shopping.userid = userfor
    shopping.movieid = moviesfor
    shopping.price = price
    shopping.quantity = quantity
    shopping.seats = seats
    shopping.save()
    return render(request, 'user/userInfo.html')