From 56f2d832d5715bc7d5d0100b124795adcbbe0df1 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe <13301940+andersy005@users.noreply.github.com> Date: Tue, 17 Oct 2023 09:03:56 -0700 Subject: [PATCH] fix `/charts/credits_by_transaction_date/{project_id}/` (#42) --- carbonplan_offsets_db/routers/charts.py | 10 ++-------- tests/test_charts.py | 5 +++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/carbonplan_offsets_db/routers/charts.py b/carbonplan_offsets_db/routers/charts.py index 31dbdd1..10106bb 100644 --- a/carbonplan_offsets_db/routers/charts.py +++ b/carbonplan_offsets_db/routers/charts.py @@ -3,7 +3,7 @@ import numpy as np import pandas as pd -from fastapi import APIRouter, Depends, HTTPException, Query, Request +from fastapi import APIRouter, Depends, Query, Request from sqlmodel import Session, and_, case, func, or_ from ..database import get_session @@ -501,10 +501,6 @@ def get_credits_by_project_id( .filter(Project.project_id == project_id) ) - # check if project exists - if not query.first(): - raise HTTPException(status_code=404, detail=f'Project {project_id} not found') - filters = [ ('transaction_type', transaction_type, 'ilike', Credit), ('transaction_date', transaction_date_from, '>=', Credit), @@ -616,7 +612,7 @@ def get_projects_by_credit_totals( minimum = query.with_entities(func.min(getattr(Project, credit_type))).scalar() maximum = query.with_entities(func.max(getattr(Project, credit_type))).scalar() - results = projects_by_credit_totals( + return projects_by_credit_totals( query=query, min_value=minimum, max_value=maximum, @@ -624,5 +620,3 @@ def get_projects_by_credit_totals( bin_width=bin_width, categories=category, ) - - return results diff --git a/tests/test_charts.py b/tests/test_charts.py index 91336bb..b615c7b 100644 --- a/tests/test_charts.py +++ b/tests/test_charts.py @@ -101,8 +101,9 @@ def test_get_credits_by_transaction_date_by_project( def test_get_credits_by_transaction_date_by_nonexistent_project(test_app): project_id = 'ACR999' response = test_app.get(f'/charts/credits_by_transaction_date/{project_id}/') - assert response.status_code == 404 - assert response.json() == {'detail': 'Project ACR999 not found'} + assert response.status_code == 200 + # check that the response is empty + assert response.json() == [] @pytest.mark.parametrize('credit_type', ['issued', 'retired'])