-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
from rctab.crud.accounting_models import subscription, subscription_details | ||
from rctab.crud.schema import RoleAssignment, SubscriptionState, UserRBAC | ||
from rctab.routers.frontend import check_user_on_subscription, home | ||
from rctab.routers.frontend import subscription_details as subscription_details_page | ||
from tests.test_routes import constants | ||
from tests.test_routes.test_routes import test_db # pylint: disable=unused-import | ||
|
||
|
@@ -181,3 +182,65 @@ async def test_render_home_page(mocker: MockerFixture, test_db: Database) -> Non | |
mocker.patch("rctab.routers.frontend.check_user_access", mock_check_access) | ||
|
||
await home(mock_request, mock_user) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_render_details_page(mocker: MockerFixture, test_db: Database) -> None: | ||
"""Check that we can pick up on undefined variable template issues.""" | ||
# Use StrictUndefined while testing | ||
mocker.patch( | ||
"rctab.routers.frontend.templates", | ||
Jinja2Templates( | ||
( | ||
Path(rctab.routers.frontend.__file__).parent.parent / "templates" | ||
).absolute(), | ||
undefined=StrictUndefined, | ||
), | ||
) | ||
subscription_id = UUID(int=random.randint(0, (2**32) - 1)) | ||
|
||
await test_db.execute( | ||
subscription.insert().values(), | ||
dict( | ||
admin=str(constants.ADMIN_UUID), | ||
subscription_id=str(subscription_id), | ||
), | ||
) | ||
|
||
await test_db.execute( | ||
subscription_details.insert().values(), | ||
dict( | ||
subscription_id=str(subscription_id), | ||
state=SubscriptionState("Enabled"), | ||
display_name="a subscription", | ||
role_assignments=[ | ||
RoleAssignment( | ||
role_definition_id="123", | ||
role_name="Sous chef", | ||
principal_id="456", | ||
display_name="Max Mustermann", | ||
# Note the missing email address, which does sometimes happen | ||
mail=None, | ||
scope="some/scope/string", | ||
).dict() | ||
], | ||
), | ||
) | ||
|
||
mock_request = mocker.Mock() | ||
|
||
mock_user = mocker.Mock() | ||
mock_user.token = { | ||
"access_token": jwt.encode( | ||
{"unique_name": "[email protected]", "name": "My Name"}, "my key" | ||
) | ||
} | ||
mock_user.oid = str(UUID(int=434)) | ||
|
||
mock_check_access = AsyncMock() | ||
mock_check_access.return_value = UserRBAC( | ||
oid=UUID(int=111), has_access=True, is_admin=True | ||
) | ||
mocker.patch("rctab.routers.frontend.check_user_access", mock_check_access) | ||
|
||
await subscription_details_page(subscription_id, mock_request, mock_user) |