-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from jacebrowning/refactor-prompts
Refactor prompts
- Loading branch information
Showing
12 changed files
with
185 additions
and
190 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import os | ||
from typing import Tuple | ||
|
||
from . import browser, enums, shared | ||
from .config import settings | ||
|
||
|
||
def browser_if_unset(): | ||
if settings.browser.name: | ||
return | ||
|
||
if "CI" in os.environ or not shared.cli: | ||
settings.browser.name = os.getenv("BROWSER", "firefox") | ||
return | ||
|
||
command = shared.cli.Bullet( | ||
prompt="\nSelect a browser for automation: ", | ||
bullet=" ● ", | ||
choices=browser.NAMES, | ||
) | ||
value = command.launch() | ||
print() | ||
settings.browser.name = value.lower() | ||
|
||
|
||
def url_if_unset(domains=None): | ||
if settings.url: | ||
return | ||
|
||
if "CI" in os.environ or not shared.cli: | ||
settings.url = "http://example.com" | ||
return | ||
|
||
if domains: | ||
command = shared.cli.Bullet( | ||
prompt="\nStarting domain: ", bullet=" ● ", choices=domains | ||
) | ||
else: | ||
command = shared.cli.Input(prompt="\nStarting domain: ", strip=True) | ||
value = command.launch() | ||
print() | ||
settings.url = f"https://{value}" | ||
|
||
|
||
def secret_if_unset(name: str): | ||
if settings.get_secret(name, _log=False): | ||
return | ||
|
||
if "CI" in os.environ or not shared.cli: | ||
settings.set_secret(name, "<unset>") | ||
return | ||
|
||
command = shared.cli.Input(prompt=f"{name}: ") | ||
value = command.launch() | ||
print() | ||
settings.set_secret(name, value) | ||
|
||
|
||
def mode_and_value() -> Tuple[str, str]: | ||
if not shared.cli: | ||
return "", "" | ||
|
||
choices = ["<cancel>"] + [mode.value for mode in enums.Mode] | ||
command = shared.cli.Bullet( | ||
prompt="\nSelect element locator: ", | ||
bullet=" ● ", | ||
choices=choices, | ||
) | ||
mode = command.launch() | ||
if mode == "<cancel>": | ||
print() | ||
return "", "" | ||
|
||
command = shared.cli.Input("\nValue to match: ") | ||
value = command.launch() | ||
print() | ||
return mode, value |
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,33 @@ | ||
# pylint: disable=expression-not-assigned,unused-variable,redefined-outer-name,unused-argument | ||
|
||
from .. import config, prompts | ||
|
||
|
||
def describe_browser_if_unset(): | ||
def when_ci(expect, monkeypatch): | ||
monkeypatch.setenv("CI", "true") | ||
config.settings.browser.name = "" | ||
prompts.browser_if_unset() | ||
expect(config.settings.browser.name) == "firefox" | ||
|
||
def when_ci_and_override(expect, monkeypatch): | ||
monkeypatch.setenv("CI", "true") | ||
monkeypatch.setenv("BROWSER", "chrome") | ||
config.settings.browser.name = "" | ||
prompts.browser_if_unset() | ||
expect(config.settings.browser.name) == "chrome" | ||
|
||
|
||
def describe_url_if_unset(): | ||
def when_ci(expect, monkeypatch, mockbrowser): | ||
monkeypatch.setenv("CI", "true") | ||
config.settings.url = "" | ||
prompts.url_if_unset() | ||
expect(config.settings.url) == "http://example.com" | ||
|
||
|
||
def describe_secret_if_unset(): | ||
def when_ci(expect, monkeypatch, mockbrowser): | ||
monkeypatch.setenv("CI", "true") | ||
prompts.secret_if_unset("foobar") | ||
expect(config.settings.get_secret("foobar")) == "<unset>" |
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 was deleted.
Oops, something went wrong.
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.