Example #1
0
 def test_delete_a_item(self):
     """ Delete a Item """
     item = Item(0, "fido", "dog")
     item.save()
     self.assertEqual(len(Item.all()), 1)
     # delete the item and make sure it isn't in the database
     item.delete()
     self.assertEqual(len(Item.all()), 0)
    def test_delete_an_item(self):
        """ Delete an Item """
        item = Item(order_id=1,
                    product_id=1,
                    name="wrench",
                    quantity=1,
                    price=10.50)
        item.save()
        self.assertEqual(len(Item.all()), 1)

        item.delete()
        self.assertEqual(len(Item.all()), 0)
Example #3
0
 def test_delete_an_item(self):
     """ Delete an Item """
     item = Item(sku="ID111",
                 count=3,
                 price=2.00,
                 name="test_item",
                 link="test.com",
                 brand_name="gucci",
                 is_available=True)
     item.save()
     self.assertEqual(len(Item.all()), 1)
     # delete the item and make sure it isn't in the database
     item.delete()
     self.assertEqual(len(Item.all()), 0)
    def test_add_an_item(self):
        """ Create an Item and add it to the database """
        items = Item.all()
        self.assertEqual(items, [])
        item = Item(order_id=1,
                    product_id=1,
                    name="wrench",
                    quantity=1,
                    price=10.50)
        self.assertEqual(item.id, None)
        item.save()

        self.assertEqual(item.id, 1)
        items = Item.all()
        self.assertEqual(len(items), 1)
Example #5
0
 def test_add_a_item(self):
     """ Create a item and add it to the database """
     items = Item.all()
     self.assertEqual(items, [])
     item = Item(0, "fido", "dog", True)
     self.assertTrue(item != None)
     self.assertEqual(item.id, 0)
     item.save()
     # Asert that it was assigned an id and shows up in the database
     self.assertEqual(item.id, 1)
     items = Item.all()
     self.assertEqual(len(items), 1)
     self.assertEqual(items[0].id, 1)
     self.assertEqual(items[0].name, "fido")
     self.assertEqual(items[0].price, "dog")
     self.assertEqual(items[0].available, True)
    def test_fetch_all_items(self):
        """ Test fetching all Items """
        item = Item(order_id=1,
                    product_id=1,
                    name="wrench",
                    quantity=1,
                    price=10.50)
        item.save()
        item2 = Item(order_id=1,
                     product_id=2,
                     name="hammer",
                     quantity=2,
                     price=11)
        item2.save()
        Item.all()

        self.assertEqual(len(Item.all()), 2)
Example #7
0
 def test_add_an_item(self):
     """ Create an item and add it to the database """
     items = Item.all()
     self.assertEqual(items, [])
     item = Item(sku="ID111",
                 count=3,
                 price=2.00,
                 name="test_item",
                 link="test.com",
                 brand_name="gucci",
                 is_available=True)
     self.assertTrue(item != None)
     self.assertEqual(item.id, None)
     item.save()
     # Assert that it was assigned an id and shows up in the database
     self.assertEqual(item.id, 1)
     items = Item.all()
     self.assertEqual(len(items), 1)
Example #8
0
 def get(self):
     if request.args.get('item') is not None:
         bucketlist_id = int(request.args.get('item'))
         table = Item.db.table('bucketlists')
         result = table.get(where('id') == bucketlist_id)
         if result is None:
             return jsonify({})
         return jsonify(result)
     items = jsonify(Item.all())
     return items
Example #9
0
def list_items():
    """ Returns all of the Items """
    items = []
    price = request.args.get('price')
    name = request.args.get('name')
    if price:
        items = Item.find_by_price(price)
    elif name:
        items = Item.find_by_name(name)
    else:
        items = Item.all()

    results = [item.serialize() for item in items]
    return make_response(jsonify(results), status.HTTP_200_OK)
Example #10
0
 def test_update_a_item(self):
     """ Update a Item """
     item = Item(0, "fido", "dog", True)
     item.save()
     self.assertEqual(item.id, 1)
     # Change it an save it
     item.price = "k9"
     item.save()
     self.assertEqual(item.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     items = Item.all()
     self.assertEqual(len(items), 1)
     self.assertEqual(items[0].price, "k9")
     self.assertEqual(items[0].name, "fido")
Example #11
0
    def test_delete_all_items(self):
        """ Delete all Items """
        item = Item(sku="ID111",
                    count=3,
                    price=2.00,
                    name="test_item",
                    link="test.com",
                    brand_name="gucci",
                    is_available=True)
        item.save()
        Item(sku="ID222",
             count=5,
             price=10.00,
             name="some_item",
             link="link.com",
             brand_name="nike",
             is_available=False).save()
        self.assertEqual(len(Item.all()), 2)

        # Remove all items from the Items table
        Item.query.delete()

        # Check if the number of items in Item table is zero because they were removed
        self.assertEqual(len(Item.all()), 0)
    def test_update_an_item(self):
        """ Update an Item """
        item = Item(order_id=1,
                    product_id=1,
                    name="wrench",
                    quantity=1,
                    price=10.50)
        item.save()
        self.assertEqual(item.id, 1)

        item.price = 12.0
        item.save()

        items = Item.all()
        self.assertEqual(len(items), 1)
        self.assertEqual(items[0].price, 12.0)
Example #13
0
 def test_update_an_item(self):
     """ Update an Item """
     item = Item(sku="ID111",
                 count=3,
                 price=2.00,
                 name="test_item",
                 link="test.com",
                 brand_name="gucci",
                 is_available=True)
     item.save()
     self.assertEqual(item.id, 1)
     # Change it an save it
     item.sku = "ID222"
     item.save()
     self.assertEqual(item.id, 1)
     # Fetch it back and make sure the id hasn't changed
     # but the data did change
     items = Item.all()
     self.assertEqual(len(items), 1)
     self.assertEqual(items[0].sku, "ID222")
def list_items():
    """ Returns all of the Items
    ---
    tags:
      - Items
    description: The Items endpoint allows you to query Items
    parameters:
      - name: order_id
        in: query
        description: the order_id of the Item you are looking for
        required: false
        type: integer
      - name: product_id
        in: query
        description: the product_id of the Item you are looking for
        required: false
        type: integer
      - name: quantity
        in: query
        description: the quantity of the Item you are looking for
        required: false
        type: integer
      - name: price
        in: query
        description: the price of the Item you are looking for
        required: false
        type: number
      - name: name
        in: query
        description: the name of the Item you are looking for
        required: false
        type: string
    definitions:
      Item:
        type: object
        properties:
          id:
            type: integer
            description: unique id assigned internally by service
          name:
            type: string
            description: the item name
          order_id:
            type: integer
            description: the order_id of the item
          product_id:
            type: integer
            description: the product_id of the item
          quantity:
            type: integer
            description: the quantity of the item
          price:
            type: number
            description: the price of the item
    responses:
      200:
        description: An array of Items
        schema:
          type: array
          items:
            schema:
              $ref: '#/definitions/Item'
    """
    items = []

    order_id = request.args.get('order_id')
    product_id = request.args.get('product_id')
    quantity = request.args.get('quantity')
    price = request.args.get('price')
    name = request.args.get('name')

    if order_id:
        items = Item.find_by_order_id(order_id)
    elif product_id:
        items = Item.find_by_product_id(product_id)
    elif quantity:
        items = Item.find_by_quantity(quantity)
    elif price:
        items = Item.find_by_price(price)
    elif name:
        items = Item.find_by_name(name)
    else:
        items = Item.all()

    results = [item.serialize() for item in items]
    return make_response(jsonify(results), status.HTTP_200_OK)