Skip to content

Commit

Permalink
Fixed timestamp bug with casting
Browse files Browse the repository at this point in the history
  • Loading branch information
caparker committed Oct 8, 2024
1 parent 57a6477 commit ecc6859
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openaq_api/openaq_api/v3/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async def get_register(
user_token = await db.get_user_token(body.users_id)
if not user_token:
return HTTPException(401)
redis_client = getattr(request.app.state, "redis_client")
redis_client = getattr(request.app, "redis")
if redis_client:
await redis_client.sadd("keys", user_token)
return {"message": "success"}
Expand Down
1 change: 0 additions & 1 deletion openaq_api/openaq_api/v3/routers/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ async def location_get(
request: Request,
db: DB = Depends(),
):
print("FOO", request.app.state.redis_client)
response = await fetch_locations(locations, db)
return response

Expand Down
5 changes: 3 additions & 2 deletions openaq_api/openaq_api/v3/routers/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,8 @@ async def fetch_hours_trends(aggregate_to, query, db):
, m.measurands_id
, m.measurand
, m.units
, as_timestamptz(:{datetime_field_name}_from, tz.tzid) as datetime_from
, as_timestamptz(:{datetime_field_name}_to, tz.tzid) as datetime_to
, as_timestamptz(:{datetime_field_name}_from::timestamp, tz.tzid) as datetime_from
, as_timestamptz(:{datetime_field_name}_to::timestamp, tz.tzid) as datetime_to
FROM sensors s
, sensor_systems sy
, sensor_nodes sn
Expand Down Expand Up @@ -906,6 +906,7 @@ async def fetch_hours_trends(aggregate_to, query, db):
ORDER BY e.factor
"""


return await db.fetchPage(sql, params)


Expand Down
1 change: 1 addition & 0 deletions openaq_api/tests/test_sensor_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_aggregated_moy_good(self, client):
data = json.loads(response.content).get('results', [])
assert len(data) == 12


row = data[0]
# hours are time ending
assert row['coverage']['datetimeFrom']['local'] == '2022-01-02T00:00:00-10:00'
Expand Down
2 changes: 1 addition & 1 deletion openaq_api/tests/test_sensors_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_date_filter(self, client):
response = client.get(f"/v3/parameters/{measurands_id}/latest?datetime_min=2024-08-27")
assert response.status_code == 200
data = json.loads(response.content).get('results', [])
assert len(data) == 10
assert len(data) == 1

def test_timestamp_filter(self, client):
response = client.get(f"/v3/parameters/{measurands_id}/latest?datetime_min=2024-08-27 19:00:00")
Expand Down

0 comments on commit ecc6859

Please sign in to comment.