Skip to content

Commit

Permalink
GH-5: Order schemes by id
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Nov 3, 2023
1 parent c11821d commit a9280ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 6 additions & 2 deletions schemes/schemes/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ def get_by_authority(self, authority_id: int) -> list[Scheme]:
result = connection.execute(
text(
"SELECT capital_scheme_id, scheme_name, bid_submitting_authority_id FROM capital_scheme "
"WHERE bid_submitting_authority_id=:bid_submitting_authority_id"
"WHERE bid_submitting_authority_id=:bid_submitting_authority_id "
"ORDER BY capital_scheme_id"
),
{"bid_submitting_authority_id": authority_id},
)
Expand All @@ -73,7 +74,10 @@ def get_by_authority(self, authority_id: int) -> list[Scheme]:
def get_all(self) -> list[Scheme]:
with self._engine.connect() as connection:
result = connection.execute(
text("SELECT capital_scheme_id, scheme_name, bid_submitting_authority_id FROM capital_scheme")
text(
"SELECT capital_scheme_id, scheme_name, bid_submitting_authority_id FROM capital_scheme "
"ORDER BY capital_scheme_id"
)
)
return [
Scheme(id=row.capital_scheme_id, name=row.scheme_name, authority_id=row.bid_submitting_authority_id)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_by_authority(self, authority_id: int) -> list[Scheme]:
def by_authority(scheme: Scheme) -> TypeGuard[Scheme]:
return scheme.authority_id == authority_id

return list(filter(by_authority, self._schemes.values()))
return sorted(list(filter(by_authority, self._schemes.values())), key=lambda scheme: scheme.id)

def get_all(self) -> list[Scheme]:
return list(self._schemes.values())
return sorted(list(self._schemes.values()), key=lambda scheme: scheme.id)
2 changes: 1 addition & 1 deletion tests/integration/test_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def test_schemes_shows_authority(client: FlaskClient) -> None:

def test_schemes_shows_schemes(schemes: SchemeRepository, client: FlaskClient) -> None:
schemes.add(
Scheme(id=1, name="Wirral Package", authority_id=1),
Scheme(id=2, name="School Streets", authority_id=1),
Scheme(id=1, name="Wirral Package", authority_id=1),
Scheme(id=3, name="Hospital Fields Road", authority_id=2),
)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/schemes/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def test_add_schemes(schemes: DatabaseSchemeRepository) -> None:

def test_get_all_schemes_by_authority(schemes: DatabaseSchemeRepository) -> None:
schemes.add(
Scheme(id=1, name="Wirral Package", authority_id=1),
Scheme(id=2, name="School Streets", authority_id=1),
Scheme(id=1, name="Wirral Package", authority_id=1),
Scheme(id=3, name="Hospital Fields Road", authority_id=2),
)

Expand All @@ -69,8 +69,8 @@ def test_get_all_schemes_by_authority(schemes: DatabaseSchemeRepository) -> None

def test_get_all_schemes(schemes: DatabaseSchemeRepository) -> None:
schemes.add(
Scheme(id=1, name="Wirral Package", authority_id=1),
Scheme(id=2, name="School Streets", authority_id=1),
Scheme(id=1, name="Wirral Package", authority_id=1),
)

schemes_list = schemes.get_all()
Expand Down

0 comments on commit a9280ca

Please sign in to comment.