Skip to content

Commit

Permalink
fix get_account_roles service function for non-existing account
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed May 1, 2023
1 parent 0791fa3 commit 2da7d10
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion flexmeasures/data/services/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ def get_number_of_assets_in_account(account_id: int) -> int:

def get_account_roles(account_id: int) -> AccountRole:
account = Account.query.filter_by(id=account_id).one_or_none()

if account is None:
return []
return account.account_roles
3 changes: 2 additions & 1 deletion flexmeasures/data/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ def test_get_number_of_assets_in_account(db, setup_assets):
assert get_number_of_assets_in_account(3) == 0


def test_get_account_roles(db):
def test_get_account_roles(db, setup_assets):
"""Get the account roles"""
assert get_account_roles(1)[0].name == "Prosumer"
assert get_account_roles(2)[0].name == "Supplier"
assert get_account_roles(3)[0].name == "Dummy"
assert get_account_roles(4) == []
assert get_account_roles(9999999) == [] # non-existing account id
multiple_roles = get_account_roles(5)
assert [i.name for i in multiple_roles] == ["Prosumer", "Supplier", "Dummy"]

0 comments on commit 2da7d10

Please sign in to comment.