Example #1
0
def bmi_console():
    db.printAllBMI()

    feet = raw_input(" Height (ft): ")
    inches = raw_input(" Height (in): ")
    weight = raw_input(" Weight (lb): ")

    try:
        category, bmiNum = bmi.calculate(feet, inches, weight)
        print("\n Your BMI of : " + str(bmiNum) + " is considered " +
              category + "\n")

        db.saveBMI(feet, inches, weight, category, bmiNum)
    except Exception as e:
        print("\n Try again: " + type(e).__name__ + "\n")
Example #2
0
def api_bmi():
    if 'feet' in request.args and 'inches' in request.args and 'weight' in request.args:
        try:
            category, bmiNum = bmi.calculate(request.args['feet'],
                                             request.args['inches'],
                                             request.args['weight'])

            return jsonify(
                db.saveBMI(request.args['feet'], request.args['inches'],
                           request.args['weight'], category, bmiNum))
        except:
            pass
    elif not request.args:
        return jsonify(db.getBMI())
    return flask.jsonify(
        error=400,
        text=str(
            "Bad Request: The requested URL requires either no parameters (to view all bmi requests in the databse) or the arguments 'feet', 'inches' and 'weight' as integers."
        )), 400
Example #3
0
def test_bmi_returns_tuple():
    assert isinstance(bmi.calculate(5, 10, 150), tuple)
Example #4
0
def test_bmi_returns_obese():
    # BMI is 40.0 - Obese BMI of 30 or greater
    assert bmi.calculate(5, 0, 200)[0] == "Obese"
Example #5
0
def test_bmi_returns_category_string():
    assert isinstance(bmi.calculate(5, 10, 150)[0], str)
Example #6
0
def test_bmi_returns_overweight():
    # BMI is 27.9 - Overweight BMI 25-29.9
    assert bmi.calculate(5, 10, 190)[0] == "Overweight"
Example #7
0
def test_bmi_returns_obese_edge():
    # BMI is 30 - Obese BMI of 30 or greater
    assert bmi.calculate(5, 0, 150)[0] == "Obese"
Example #8
0
def test_bmi_returns_normalweight():
    # BMI is 22.7 - Normal weight BMI 18.5-24.9
    assert bmi.calculate(5, 3, 125)[0] == "Normal weight"
Example #9
0
def test_bmi_returns_overweight_edge():
    # BMI is 25 - Overweight BMI 25-29.9
    assert bmi.calculate(5, 0, 125)[0] == "Overweight"
Example #10
0
def test_bmi_returns_bmi_float():
    assert isinstance(bmi.calculate(5, 10, 150)[1], float)
Example #11
0
def test_bmi_returns_normalweight_edge():
    # BMI is 18.5 - Normal weight BMI 18.5-24.9
    assert bmi.calculate(5, 2, 99)[0] == "Normal weight"
Example #12
0
def test_bmi_formula():
    assert bmi.calculate(5, 5, 90)[1] == 15.3
Example #13
0
def test_bmi_returns_underweight():
    # BMI is 15.3 - Underweight BMI < 18.5
    assert bmi.calculate(5, 5, 90)[0] == "Underweight"
Example #14
0
def test_bmi_empty_weight():
    with pytest.raises(bmi.ZeroWeightError):
        bmi.calculate(5, 1, 0)
Example #15
0
def test_bmi_empty_height():
    with pytest.raises(bmi.ZeroHeightError):
        bmi.calculate(0, 0, 150)
Example #16
0
def test_bmi_invalid_input_weight():
    with pytest.raises(bmi.InvalidInputError):
        bmi.calculate(5, 5, "weight")
Example #17
0
def test_bmi_invalid_input_inches():
    with pytest.raises(bmi.InvalidInputError):
        bmi.calculate(5, "inches", 100)
Example #18
0
def test_bmi_invalid_input_feet():
    with pytest.raises(bmi.InvalidInputError):
        bmi.calculate("feet", 0, 150)