Skip to content

Commit

Permalink
Merge pull request #13 from codeforberlin/fix-404
Browse files Browse the repository at this point in the history
Return proper 404 if school is not found
  • Loading branch information
k-nut authored Aug 13, 2022
2 parents ffab72f + 9592f6c commit c82b46b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/crud.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Optional

from sqlalchemy.orm import Session

Expand All @@ -7,12 +7,15 @@
from .schemas import School


def get_school(db: Session, school_id: str) -> School:
def get_school(db: Session, school_id: str) -> Optional[School]:
school = db \
.query(models.School) \
.filter(models.School.id == school_id) \
.first()
return School.from_db(school)
if school:
return School.from_db(school)
return None



def get_schools(db: Session, skip: int = 0, limit: int = 100, filter_params=None) -> List[School]:
Expand Down
11 changes: 11 additions & 0 deletions test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,14 @@ def test_schools_by_bounding_box(self, client, db):
# Assert
assert response.status_code == 200
assert len(response.json()) == 2

def test_get_single_no_result(self, client, db):
# Arrange
self.__setup_schools(db)

# Act
response = client.get("/schools/NI-12345")

# Assert
assert response.status_code == 404

0 comments on commit c82b46b

Please sign in to comment.