Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions newsfragments/1491.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Raise an error from ``create_cloud_database``, rather than silently using
the first match, when more than one license in the drop-down has the
requested name.
36 changes: 25 additions & 11 deletions src/vws_web_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
Expand Down Expand Up @@ -490,17 +491,30 @@ def create_cloud_database(
)
database_type_radio_element.click()

wait.until(
method=lambda d: any(
opt.text == license_name
for opt in Select(
webelement=d.find_element(
by=By.ID,
value="cloud-license-dropdown",
),
).options
),
)
@beartype
def _matching_license_options(driver: WebDriver) -> list[WebElement]:
"""Return the drop-down options for the wanted license."""
license_select = Select(
webelement=driver.find_element(
by=By.ID,
value="cloud-license-dropdown",
),
)
return [
option
for option in license_select.options
if option.text == license_name
]

matching_options = wait.until(method=_matching_license_options)
if len(matching_options) > 1: # pragma: no cover
message = (
f"{len(matching_options)} licenses in the drop-down are named "
f"'{license_name}'. Which one to attach the new database to "
"is ambiguous."
)
raise ValueError(message)

Select(
webelement=driver.find_element(
by=By.ID,
Expand Down