Skip to content

Commit

Permalink
fix /charts/credits_by_transaction_date/{project_id}/ (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored Oct 17, 2023
1 parent 1c00685 commit 56f2d83
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
10 changes: 2 additions & 8 deletions carbonplan_offsets_db/routers/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -616,13 +612,11 @@ 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,
credit_type=credit_type,
bin_width=bin_width,
categories=category,
)

return results
5 changes: 3 additions & 2 deletions tests/test_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 56f2d83

Please sign in to comment.