-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the Selenium tests and exercise the create token UI. Add some id and class attributes to the frontend so that Selenium can find the necessary elements. Change the GitHub Actions workflow to install the JavaScript dependencies and build the UI before running tests.
- Loading branch information
Showing
11 changed files
with
199 additions
and
86 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Selenium tests for ``/auth/tokens``.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
from urllib.parse import urljoin | ||
|
||
import pytest | ||
|
||
from gafaelfawr.constants import COOKIE_NAME | ||
from gafaelfawr.models.state import State | ||
from gafaelfawr.models.token import TokenType | ||
from tests.pages.tokens import TokensPage | ||
from tests.support.selenium import run | ||
|
||
if TYPE_CHECKING: | ||
from seleniumwire import webdriver | ||
|
||
from tests.support.selenium import SeleniumConfig | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_token( | ||
driver: webdriver.Chrome, selenium_config: SeleniumConfig | ||
) -> None: | ||
cookie = State(token=selenium_config.token).as_cookie() | ||
driver.header_overrides = {"Cookie": f"{COOKIE_NAME}={cookie}"} | ||
|
||
tokens_url = urljoin(selenium_config.url, "/auth/tokens") | ||
await run(lambda: driver.get(tokens_url)) | ||
|
||
tokens_page = TokensPage(driver) | ||
assert tokens_page.get_tokens(TokenType.user) == [] | ||
session_tokens = tokens_page.get_tokens(TokenType.session) | ||
assert len(session_tokens) == 1 | ||
assert session_tokens[0].token == selenium_config.token.key | ||
|
||
# Drop our cookie in favor of the one the browser is now sending, since | ||
# the browser one contains a CSRF token that will be required for token | ||
# creation. | ||
del driver.header_overrides | ||
|
||
create_modal = await tokens_page.click_create_token() | ||
create_modal.set_token_name("test token") | ||
await create_modal.submit() | ||
|
||
new_token_modal = tokens_page.get_new_token_modal() | ||
assert new_token_modal.token.startswith("gt-") | ||
new_token_modal.dismiss() | ||
|
||
user_tokens = tokens_page.get_tokens(TokenType.user) | ||
assert len(user_tokens) == 1 | ||
assert user_tokens[0].name == "test token" |
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
Oops, something went wrong.