Beispiel #1
0
    def test_update_prod_info(self):
        """ Update a product information. """
        test_prod_id = 111
        test_prod_name = "ab"
        prod_info = ProductInformation(prod_id=test_prod_id,
                                       prod_name=test_prod_name)
        prod_info.save()

        # update
        test_new_qty = 10
        test_used_qty = 30
        test_open_boxed_qty = 40
        test_restock_level = 20
        test_restock_amt = 66
        prod_info.new_qty = test_new_qty
        prod_info.used_qty = test_used_qty
        prod_info.open_boxed_qty = test_open_boxed_qty
        prod_info.restock_level = test_restock_level
        prod_info.restock_amt = test_restock_amt

        prod_infos = ProductInformation.list_all()
        self.assertEqual(1, len(prod_infos))
        self.assertIsNotNone(prod_infos[0])
        self.assert_fields_equal(prod_infos[0], test_prod_id, test_prod_name,
                                 test_new_qty, test_used_qty,
                                 test_open_boxed_qty, test_restock_level,
                                 test_restock_amt)
Beispiel #2
0
 def test_delete_prod_info(self):
     """ Delete a product information """
     prod_info = ProductInformation(prod_id=110, prod_name="qwe")
     prod_info.save()
     self.assertEqual(1, len(ProductInformation.list_all()))
     prod_info.delete()
     self.assertEqual(0, len(ProductInformation.list_all()))
Beispiel #3
0
    def test_automatic_restock(self):
        """ Test automatic restocking functionality """
        prod_info = ProductInformation(prod_id=1, prod_name='Storm Trooper', \
                                       new_qty=20, used_qty=30, open_boxed_qty=40, \
                                       restock_level=1000, restock_amt=100)
        prod_info.save()

        retrived_prod_info = ProductInformation.find(prod_id=1)
        self.assertIsNotNone(retrived_prod_info)
        total_qty = retrived_prod_info.new_qty + retrived_prod_info.used_qty \
                + retrived_prod_info.open_boxed_qty
        self.assertEqual(total_qty, 1090)
Beispiel #4
0
    def test_create_prod_info(self):
        """ Create a new prodct information and add it to the data table """
        prod_infos = ProductInformation.list_all()
        self.assertEqual(prod_infos, [])

        test_prod_id = 11
        test_prod_name = "a"
        prod_info = ProductInformation(prod_id=test_prod_id,
                                       prod_name=test_prod_name)
        prod_info.save()
        prod_infos = ProductInformation.list_all()

        self.assertEqual(1, len(prod_infos))
        self.assertIsNotNone(prod_infos[0])
        self.assert_fields_equal(prod_infos[0], test_prod_id, test_prod_name,
                                 None, None, None, None, None)
Beispiel #5
0
def create_prod_info():
    """
    Creates a ProductInformation
    This endpoint will create a ProductInformation based the data in the body that is posted
    ---
    tags:
        -   Inventory
    consumes:
        -   application/json
    produces:
        -   application/json
    definitions:
        Product:
            type: object
            properties:
                prod_id:
                    type: integer
                    description: Unique ID of the product.
                prod_name:
                    type: string
                    description: Name for the product.
                new_qty:
                    type: integer
                    description: Quantity of condition "new".
                used_qty:
                    type: integer
                    description: Quantity of condition "used".
                open_boxed_qty:
                    type: integer
                    description: Quantity of condition "open boxed".
                restock_level:
                    type: integer
                    minimum: -1
                    description: Bottom line of a product's quantity with condition "new".
                restock_amt:
                    type: integer
                    description: Quantity to be added to a product's quantity with condition "new".
    parameters:
        -   in: body
            name: body
            required: true
            schema:
                id: data
                required:
                    - prod_id
                    - prod_name
                $ref: '#/definitions/Product'

    responses:
        201:
            description: Product information created
            schema:
                $ref: '#/definitions/Product'
        400:
            description: Bad Request (invalid posted data)
    """
    check_content_type(JSON)
    app.logger.info("POST received, create with payload {}.".format(
        request.get_json()))
    prod_info = ProductInformation()
    prod_info.deserialize(request.get_json())

    if ProductInformation.find(prod_info.prod_id):
        raise BadRequest(CANNOT_CREATE_MSG.format(prod_info.prod_id))

    prod_info.save()
    message = prod_info.serialize()
    location_url = url_for(GET_PROD_INFO,
                           prod_id=prod_info.prod_id,
                           _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {LOCATION: location_url})