def interval_average(): """POSTs timestamp from which average HR calculation should begin. :param patient_id: patient id as string :param heart_rate_average_since: timestamp as string :returns: average HR over interval as JSON """ global patientRecord query_interval_average = request.get_json() from outsource import get_interval_average try: interval_average = get_interval_average(query_interval_average, patientRecord) return jsonify(interval_average), 200 except TypeError: return jsonify("Please check that all fields were input."), 400 except ValueError: return jsonify("Please check input and that patient has data."), 400 except: return jsonify("Something went wrong."), 501
def test_get_interval_average_noData(): from outsource import get_interval_average with pytest.raises(ValueError): get_interval_average(deadRequest, checkUpdatedPatientRecord)
def test_get_interval_average_no_set(): from outsource import get_interval_average wantedAverage = get_interval_average(noDataAverageRequest, patientRecord) assert wantedAverage == "No heart rate measurements since this date."
def test_get_interval_average_bad(): from outsource import get_interval_average with pytest.raises(ValueError): get_interval_average(badIntervalAverageRequest, patientRecord)
def test_get_interval_average_good(): from outsource import get_interval_average pAverage = get_interval_average(goodIntervalAverageRequest, patientRecord) assert pAverage == round((75 + 110) / 2)