Example #1
0
 def test_query_avg_all_stations_with_date(self, prepare_test_db):
     cur_date = date.today() - timedelta(days=1)
     q = query_avg_all_stations(prepare_test_db, cur_date)
     assert q.count() == 2
     assert (abs(q[0][0] - Decimal(28.68))) < 0.01
     assert q[0][1] == cur_date
     assert q[0][2] == '92'
Example #2
0
 def get(self):
     """Returns average prices for all gas station at particular date (if date is omit at max date with info)."""
     try:
         get_date_param(request, 'date_of_price')
     except ValueError:
         return make_response_json({
             'status': 'fail',
             'reason': 'wrong date'
         })
     result = query_avg_all_stations(session, get_date_param(request, 'date_of_price'))
     result_dict = helpers.query_to_dict(result)
     return make_response_json({'status': 'ok', 'data': result_dict})
Example #3
0
def avg_price():
    if request.headers['Content-Type'] == 'application/json':
        request_data = request.get_json()
    date_of_price = request_data["date_of_price"]
    result = query_avg_all_stations(session, date_of_price)
    result_dict = helpers.query_to_dict(result)
    json_data = json.dumps(result_dict,
                           default=helpers.to_serializable,
                           ensure_ascii=False)
    resp = make_response(json_data)
    resp.mimetype = 'application/json'
    return resp
Example #4
0
 def test_query_avg_all_stations_no_info(self, prepare_test_db):
     q = query_avg_all_stations(prepare_test_db, date.today() + timedelta(days=2))
     assert q.count() == 0
Example #5
0
 def test_query_avg_all_stations_max_date(self, prepare_test_db):
     q = query_avg_all_stations(prepare_test_db)
     assert q.count() == 2
     assert (abs(q[0][0] - Decimal(28.38))) < 0.01
     assert q[0][1] == date.today()
     assert q[0][2] == '92'