mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Fix account related tests
This commit is contained in:
@ -83,7 +83,7 @@ def validate_password(value):
|
|||||||
def account_register(username, email, password, firstname, lastname):
|
def account_register(username, email, password, firstname, lastname):
|
||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
client.registration(username, email, password, firstname, lastname)
|
client.registration(username, email, password, firstname, lastname)
|
||||||
return click.secho(
|
click.secho(
|
||||||
"An account has been successfully created. "
|
"An account has been successfully created. "
|
||||||
"Please check your mail to activate your account and verify your email address.",
|
"Please check your mail to activate your account and verify your email address.",
|
||||||
fg="green",
|
fg="green",
|
||||||
@ -96,14 +96,14 @@ def account_register(username, email, password, firstname, lastname):
|
|||||||
def account_login(username, password):
|
def account_login(username, password):
|
||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
client.login(username, password)
|
client.login(username, password)
|
||||||
return click.secho("Successfully logged in!", fg="green")
|
click.secho("Successfully logged in!", fg="green")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("logout", short_help="Log out of PlatformIO Account")
|
@cli.command("logout", short_help="Log out of PlatformIO Account")
|
||||||
def account_logout():
|
def account_logout():
|
||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
client.logout()
|
client.logout()
|
||||||
return click.secho("Successfully logged out!", fg="green")
|
click.secho("Successfully logged out!", fg="green")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("password", short_help="Change password")
|
@cli.command("password", short_help="Change password")
|
||||||
@ -112,7 +112,7 @@ def account_logout():
|
|||||||
def account_password(old_password, new_password):
|
def account_password(old_password, new_password):
|
||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
client.change_password(old_password, new_password)
|
client.change_password(old_password, new_password)
|
||||||
return click.secho("Password successfully changed!", fg="green")
|
click.secho("Password successfully changed!", fg="green")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("token", short_help="Get or regenerate Authentication Token")
|
@cli.command("token", short_help="Get or regenerate Authentication Token")
|
||||||
@ -123,8 +123,9 @@ def account_token(password, regenerate, json_output):
|
|||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
auth_token = client.auth_token(password, regenerate)
|
auth_token = client.auth_token(password, regenerate)
|
||||||
if json_output:
|
if json_output:
|
||||||
return click.echo(json.dumps({"status": "success", "result": auth_token}))
|
click.echo(json.dumps({"status": "success", "result": auth_token}))
|
||||||
return click.secho("Personal Authentication Token: %s" % auth_token, fg="green")
|
return
|
||||||
|
click.secho("Personal Authentication Token: %s" % auth_token, fg="green")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("forgot", short_help="Forgot password")
|
@cli.command("forgot", short_help="Forgot password")
|
||||||
@ -132,7 +133,7 @@ def account_token(password, regenerate, json_output):
|
|||||||
def account_forgot(username):
|
def account_forgot(username):
|
||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
client.forgot_password(username)
|
client.forgot_password(username)
|
||||||
return click.secho(
|
click.secho(
|
||||||
"If this account is registered, we will send the "
|
"If this account is registered, we will send the "
|
||||||
"further instructions to your email.",
|
"further instructions to your email.",
|
||||||
fg="green",
|
fg="green",
|
||||||
@ -171,11 +172,13 @@ def account_update(current_password, **kwargs):
|
|||||||
except AccountNotAuthorized:
|
except AccountNotAuthorized:
|
||||||
pass
|
pass
|
||||||
if email_changed:
|
if email_changed:
|
||||||
return click.secho(
|
click.secho(
|
||||||
"Please check your mail to verify your new email address and re-login. ",
|
"Please check your mail to verify your new email address and re-login. ",
|
||||||
fg="yellow",
|
fg="yellow",
|
||||||
)
|
)
|
||||||
return click.secho("Please re-login.", fg="yellow")
|
return None
|
||||||
|
click.secho("Please re-login.", fg="yellow")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@cli.command("destroy", short_help="Destroy account")
|
@cli.command("destroy", short_help="Destroy account")
|
||||||
@ -192,7 +195,7 @@ def account_destroy():
|
|||||||
client.logout()
|
client.logout()
|
||||||
except AccountNotAuthorized:
|
except AccountNotAuthorized:
|
||||||
pass
|
pass
|
||||||
return click.secho(
|
click.secho(
|
||||||
"User account has been destroyed.",
|
"User account has been destroyed.",
|
||||||
fg="green",
|
fg="green",
|
||||||
)
|
)
|
||||||
@ -205,7 +208,8 @@ def account_show(offline, json_output):
|
|||||||
client = AccountClient()
|
client = AccountClient()
|
||||||
info = client.get_account_info(offline)
|
info = client.get_account_info(offline)
|
||||||
if json_output:
|
if json_output:
|
||||||
return click.echo(json.dumps(info))
|
click.echo(json.dumps(info))
|
||||||
|
return
|
||||||
click.echo()
|
click.echo()
|
||||||
if info.get("profile"):
|
if info.get("profile"):
|
||||||
print_profile(info["profile"])
|
print_profile(info["profile"])
|
||||||
@ -213,7 +217,7 @@ def account_show(offline, json_output):
|
|||||||
print_packages(info["packages"])
|
print_packages(info["packages"])
|
||||||
if info.get("subscriptions"):
|
if info.get("subscriptions"):
|
||||||
print_subscriptions(info["subscriptions"])
|
print_subscriptions(info["subscriptions"])
|
||||||
return click.echo()
|
click.echo()
|
||||||
|
|
||||||
|
|
||||||
def print_profile(profile):
|
def print_profile(profile):
|
||||||
|
@ -26,42 +26,46 @@ from platformio.commands.org import cli as cmd_org
|
|||||||
from platformio.commands.team import cli as cmd_team
|
from platformio.commands.team import cli as cmd_team
|
||||||
|
|
||||||
pytestmark = pytest.mark.skipif(
|
pytestmark = pytest.mark.skipif(
|
||||||
not (os.environ.get("TEST_EMAIL_LOGIN") and os.environ.get("TEST_EMAIL_PASSWORD")),
|
not all(
|
||||||
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
os.environ.get(name)
|
||||||
|
for name in (
|
||||||
|
"TEST_EMAIL_LOGIN",
|
||||||
|
"TEST_EMAIL_PASSWORD",
|
||||||
|
"TEST_EMAIL_IMAP_SERVER",
|
||||||
|
)
|
||||||
|
),
|
||||||
|
reason=(
|
||||||
|
"requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD, "
|
||||||
|
"and TEST_EMAIL_IMAP_SERVER environment variables"
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
username = None
|
USER_NAME = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||||
email = None
|
USER_EMAIL = os.environ.get("TEST_EMAIL_LOGIN", "").replace("@", f"+{USER_NAME}@")
|
||||||
splited_email = None
|
USER_PASSWORD = f"Qwerty-{random.randint(0, 100000)}"
|
||||||
firstname = None
|
USER_FIRST_NAME = "FirstName"
|
||||||
lastname = None
|
USER_LAST_NAME = "LastName"
|
||||||
password = None
|
|
||||||
|
|
||||||
orgname = None
|
ORG_NAME = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
||||||
display_name = None
|
ORG_DISPLAY_NAME = "Test Org for PIO Core"
|
||||||
second_username = None
|
EXISTING_OWNER = "piolabs"
|
||||||
|
|
||||||
teamname = None
|
TEAM_NAME = "test-" + str(random.randint(0, 100000))
|
||||||
team_description = None
|
TEAM_DESCRIPTION = "team for CI test"
|
||||||
|
|
||||||
|
|
||||||
def test_prepare():
|
def verify_account(email_contents):
|
||||||
global username, email, splited_email, firstname, lastname
|
link = (
|
||||||
global password, orgname, display_name, second_username, teamname, team_description
|
email_contents.split("Click on the link below to start this process.")[1]
|
||||||
|
.split("This link will expire within 12 hours.")[0]
|
||||||
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
.strip()
|
||||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
)
|
||||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
with requests.Session() as session:
|
||||||
firstname = "Test"
|
result = session.get(link).text
|
||||||
lastname = "User"
|
link = result.split('<a href="')[1].split('"', 1)[0]
|
||||||
password = "Qwerty123!"
|
link = link.replace("&", "&")
|
||||||
|
session.get(link)
|
||||||
orgname = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
session.close()
|
||||||
display_name = "Test Org for PIO Core"
|
|
||||||
second_username = "ivankravets"
|
|
||||||
|
|
||||||
teamname = "test-" + str(random.randint(0, 100000))
|
|
||||||
team_description = "team for CI test"
|
|
||||||
|
|
||||||
|
|
||||||
def test_account_register(
|
def test_account_register(
|
||||||
@ -72,31 +76,19 @@ def test_account_register(
|
|||||||
[
|
[
|
||||||
"register",
|
"register",
|
||||||
"-u",
|
"-u",
|
||||||
username,
|
USER_NAME,
|
||||||
"-e",
|
"-e",
|
||||||
email,
|
USER_EMAIL,
|
||||||
"-p",
|
"-p",
|
||||||
password,
|
USER_PASSWORD,
|
||||||
"--firstname",
|
"--firstname",
|
||||||
firstname,
|
USER_FIRST_NAME,
|
||||||
"--lastname",
|
"--lastname",
|
||||||
lastname,
|
USER_LAST_NAME,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
verify_account(receive_email(USER_EMAIL))
|
||||||
# email verification
|
|
||||||
result = receive_email(email)
|
|
||||||
link = (
|
|
||||||
result.split("Click on the link below to start this process.")[1]
|
|
||||||
.split("This link will expire within 12 hours.")[0]
|
|
||||||
.strip()
|
|
||||||
)
|
|
||||||
session = requests.Session()
|
|
||||||
result = session.get(link).text
|
|
||||||
link = result.split('<a href="')[1].split('"', 1)[0]
|
|
||||||
link = link.replace("&", "&")
|
|
||||||
session.get(link)
|
|
||||||
|
|
||||||
|
|
||||||
def test_account_login(
|
def test_account_login(
|
||||||
@ -106,7 +98,7 @@ def test_account_login(
|
|||||||
):
|
):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
["login", "-u", username, "-p", password],
|
["login", "-u", USER_NAME, "-p", USER_PASSWORD],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
@ -121,14 +113,14 @@ def test_account_summary(
|
|||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
assert not json_result.get("user_id")
|
assert not json_result.get("user_id")
|
||||||
assert json_result.get("profile")
|
assert json_result.get("profile")
|
||||||
assert json_result.get("profile").get("username")
|
assert json_result.get("profile").get("username") == USER_NAME
|
||||||
assert json_result.get("profile").get("email")
|
assert json_result.get("profile").get("email") == USER_EMAIL
|
||||||
assert not json_result.get("packages")
|
assert not json_result.get("packages")
|
||||||
assert not json_result.get("subscriptions")
|
assert not json_result.get("subscriptions")
|
||||||
|
|
||||||
result = clirunner.invoke(cmd_account, ["show"])
|
result = clirunner.invoke(cmd_account, ["show"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert username in result.output
|
assert USER_NAME in result.output
|
||||||
# assert "100 Concurrent Remote Agents" in result.output
|
# assert "100 Concurrent Remote Agents" in result.output
|
||||||
|
|
||||||
result = clirunner.invoke(cmd_account, ["show", "--json-output"])
|
result = clirunner.invoke(cmd_account, ["show", "--json-output"])
|
||||||
@ -136,30 +128,10 @@ def test_account_summary(
|
|||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
assert json_result.get("user_id")
|
assert json_result.get("user_id")
|
||||||
assert json_result.get("profile")
|
assert json_result.get("profile")
|
||||||
assert json_result.get("profile").get("username")
|
assert json_result.get("profile").get("username") == USER_NAME
|
||||||
assert json_result.get("profile").get("email")
|
assert json_result.get("profile").get("email") == USER_EMAIL
|
||||||
assert username == json_result.get("profile").get(
|
assert json_result.get("profile").get("firstname") == USER_FIRST_NAME
|
||||||
"username"
|
assert json_result.get("profile").get("lastname") == USER_LAST_NAME
|
||||||
) or username == json_result.get("profile").get("email")
|
|
||||||
assert json_result.get("profile").get("firstname")
|
|
||||||
assert json_result.get("profile").get("lastname")
|
|
||||||
assert json_result.get("packages")
|
|
||||||
assert json_result.get("packages")[0].get("name")
|
|
||||||
assert json_result.get("packages")[0].get("path")
|
|
||||||
assert json_result.get("subscriptions") is not None
|
|
||||||
|
|
||||||
result = clirunner.invoke(cmd_account, ["show", "--json-output", "--offline"])
|
|
||||||
validate_cliresult(result)
|
|
||||||
json_result = json.loads(result.output.strip())
|
|
||||||
assert json_result.get("user_id")
|
|
||||||
assert json_result.get("profile")
|
|
||||||
assert json_result.get("profile").get("username")
|
|
||||||
assert json_result.get("profile").get("email")
|
|
||||||
assert username == json_result.get("profile").get(
|
|
||||||
"username"
|
|
||||||
) or username == json_result.get("profile").get("email")
|
|
||||||
assert json_result.get("profile").get("firstname")
|
|
||||||
assert json_result.get("profile").get("lastname")
|
|
||||||
assert json_result.get("packages")
|
assert json_result.get("packages")
|
||||||
assert json_result.get("packages")[0].get("name")
|
assert json_result.get("packages")[0].get("name")
|
||||||
assert json_result.get("packages")[0].get("path")
|
assert json_result.get("packages")[0].get("path")
|
||||||
@ -172,7 +144,7 @@ def test_account_token(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
[
|
[
|
||||||
"token",
|
"token",
|
||||||
"--password",
|
"--password",
|
||||||
password,
|
USER_PASSWORD,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
@ -181,48 +153,48 @@ def test_account_token(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
["token", "--password", password, "--json-output"],
|
["token", "--password", USER_PASSWORD, "--json-output"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
assert json_result
|
assert json_result
|
||||||
assert json_result.get("status") == "success"
|
assert json_result.get("status") == "success"
|
||||||
assert json_result.get("result") == token
|
assert json_result.get("result") == token
|
||||||
token = json_result.get("result")
|
|
||||||
|
|
||||||
clirunner.invoke(cmd_account, ["logout"])
|
# logout
|
||||||
|
result = clirunner.invoke(cmd_account, ["logout"])
|
||||||
|
validate_cliresult(result)
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
[
|
[
|
||||||
"token",
|
"token",
|
||||||
"--password",
|
"--password",
|
||||||
password,
|
USER_PASSWORD,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
assert result.exit_code > 0
|
assert result.exit_code != 0
|
||||||
assert result.exception
|
assert result.exception
|
||||||
assert "You are not authorized! Please log in to PIO Account" in str(
|
assert "You are not authorized!" in str(result.exception)
|
||||||
result.exception
|
|
||||||
)
|
|
||||||
|
|
||||||
|
# use env tokem
|
||||||
os.environ["PLATFORMIO_AUTH_TOKEN"] = token
|
os.environ["PLATFORMIO_AUTH_TOKEN"] = token
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
["token", "--password", password, "--json-output"],
|
["show", "--json-output"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
assert json_result
|
assert json_result.get("user_id")
|
||||||
assert json_result.get("status") == "success"
|
assert json_result.get("profile").get("username") == USER_NAME
|
||||||
assert json_result.get("result") == token
|
assert json_result.get("profile").get("email") == USER_EMAIL
|
||||||
|
|
||||||
os.environ.pop("PLATFORMIO_AUTH_TOKEN")
|
os.environ.pop("PLATFORMIO_AUTH_TOKEN")
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
["login", "-u", username, "-p", password],
|
["login", "-u", USER_NAME, "-p", USER_PASSWORD],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
@ -234,7 +206,7 @@ def test_account_change_password(clirunner, validate_cliresult, isolated_pio_cor
|
|||||||
[
|
[
|
||||||
"password",
|
"password",
|
||||||
"--old-password",
|
"--old-password",
|
||||||
password,
|
USER_PASSWORD,
|
||||||
"--new-password",
|
"--new-password",
|
||||||
new_password,
|
new_password,
|
||||||
],
|
],
|
||||||
@ -242,11 +214,12 @@ def test_account_change_password(clirunner, validate_cliresult, isolated_pio_cor
|
|||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert "Password successfully changed!" in result.output
|
assert "Password successfully changed!" in result.output
|
||||||
|
|
||||||
clirunner.invoke(cmd_account, ["logout"])
|
result = clirunner.invoke(cmd_account, ["logout"])
|
||||||
|
validate_cliresult(result)
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
["login", "-u", username, "-p", new_password],
|
["login", "-u", USER_NAME, "-p", new_password],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
@ -257,7 +230,7 @@ def test_account_change_password(clirunner, validate_cliresult, isolated_pio_cor
|
|||||||
"--old-password",
|
"--old-password",
|
||||||
new_password,
|
new_password,
|
||||||
"--new-password",
|
"--new-password",
|
||||||
password,
|
USER_PASSWORD,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
@ -266,30 +239,29 @@ def test_account_change_password(clirunner, validate_cliresult, isolated_pio_cor
|
|||||||
def test_account_update(
|
def test_account_update(
|
||||||
clirunner, validate_cliresult, receive_email, isolated_pio_core
|
clirunner, validate_cliresult, receive_email, isolated_pio_core
|
||||||
):
|
):
|
||||||
global username
|
global USER_NAME, USER_EMAIL, USER_FIRST_NAME, USER_LAST_NAME
|
||||||
global email
|
|
||||||
global firstname
|
|
||||||
global lastname
|
|
||||||
|
|
||||||
firstname = "First " + str(random.randint(0, 100000))
|
USER_NAME = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||||
lastname = "Last" + str(random.randint(0, 100000))
|
USER_EMAIL = os.environ.get("TEST_EMAIL_LOGIN", "").replace(
|
||||||
|
"@", f"+new-{USER_NAME}@"
|
||||||
|
)
|
||||||
|
USER_FIRST_NAME = "First " + str(random.randint(0, 100000))
|
||||||
|
USER_LAST_NAME = "Last" + str(random.randint(0, 100000))
|
||||||
|
|
||||||
username = "username" + str(random.randint(0, 100000))
|
|
||||||
email = "%s+new-%s@%s" % (splited_email[0], username, splited_email[1])
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
[
|
[
|
||||||
"update",
|
"update",
|
||||||
"--current-password",
|
"--current-password",
|
||||||
password,
|
USER_PASSWORD,
|
||||||
"--firstname",
|
"--firstname",
|
||||||
firstname,
|
USER_FIRST_NAME,
|
||||||
"--lastname",
|
"--lastname",
|
||||||
lastname,
|
USER_LAST_NAME,
|
||||||
"--username",
|
"--username",
|
||||||
username,
|
USER_NAME,
|
||||||
"--email",
|
"--email",
|
||||||
email,
|
USER_EMAIL,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
@ -298,18 +270,7 @@ def test_account_update(
|
|||||||
"Please check your mail to verify your new email address and re-login. "
|
"Please check your mail to verify your new email address and re-login. "
|
||||||
in result.output
|
in result.output
|
||||||
)
|
)
|
||||||
|
verify_account(receive_email(USER_EMAIL))
|
||||||
result = receive_email(email)
|
|
||||||
link = (
|
|
||||||
result.split("Click on the link below to start this process.")[1]
|
|
||||||
.split("This link will expire within 12 hours.")[0]
|
|
||||||
.strip()
|
|
||||||
)
|
|
||||||
session = requests.Session()
|
|
||||||
result = session.get(link).text
|
|
||||||
link = result.split('<a href="')[1].split('"', 1)[0]
|
|
||||||
link = link.replace("&", "&")
|
|
||||||
session.get(link)
|
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
@ -317,18 +278,16 @@ def test_account_update(
|
|||||||
)
|
)
|
||||||
assert result.exit_code > 0
|
assert result.exit_code > 0
|
||||||
assert result.exception
|
assert result.exception
|
||||||
assert "You are not authorized! Please log in to PIO Account" in str(
|
assert "You are not authorized!" in str(result.exception)
|
||||||
result.exception
|
|
||||||
)
|
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
["login", "-u", username, "-p", password],
|
["login", "-u", USER_NAME, "-p", USER_PASSWORD],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
|
|
||||||
# def test_account_destroy_with_linked_resources(
|
# def _test_account_destroy_with_linked_resources(
|
||||||
# clirunner, validate_cliresult, receive_email, isolated_pio_core, tmpdir_factory
|
# clirunner, validate_cliresult, receive_email, isolated_pio_core, tmpdir_factory
|
||||||
# ):
|
# ):
|
||||||
# package_url = "https://github.com/bblanchon/ArduinoJson/archive/v6.11.0.tar.gz"
|
# package_url = "https://github.com/bblanchon/ArduinoJson/archive/v6.11.0.tar.gz"
|
||||||
@ -363,44 +322,47 @@ def test_account_update(
|
|||||||
def test_org_create(clirunner, validate_cliresult, isolated_pio_core):
|
def test_org_create(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_org,
|
cmd_org,
|
||||||
["create", "--email", email, "--displayname", display_name, orgname],
|
["create", "--email", USER_EMAIL, "--displayname", ORG_DISPLAY_NAME, ORG_NAME],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
|
|
||||||
def test_org_list(clirunner, validate_cliresult, isolated_pio_core):
|
def test_org_list(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
# pio org list
|
|
||||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
assert json_result == [
|
assert json_result == [
|
||||||
{
|
{
|
||||||
"orgname": orgname,
|
"orgname": ORG_NAME,
|
||||||
"displayname": display_name,
|
"displayname": ORG_DISPLAY_NAME,
|
||||||
"email": email,
|
"email": USER_EMAIL,
|
||||||
"owners": [
|
"owners": [
|
||||||
{"username": username, "firstname": firstname, "lastname": lastname}
|
{
|
||||||
|
"username": USER_NAME,
|
||||||
|
"firstname": USER_FIRST_NAME,
|
||||||
|
"lastname": USER_LAST_NAME,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_org_add_owner(clirunner, validate_cliresult, isolated_pio_core):
|
def test_org_add_owner(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(cmd_org, ["add", orgname, second_username])
|
result = clirunner.invoke(cmd_org, ["add", ORG_NAME, EXISTING_OWNER])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert second_username in result.output
|
assert EXISTING_OWNER in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_org_remove_owner(clirunner, validate_cliresult, isolated_pio_core):
|
def test_org_remove_owner(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(cmd_org, ["remove", orgname, second_username])
|
result = clirunner.invoke(cmd_org, ["remove", ORG_NAME, EXISTING_OWNER])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert second_username not in result.output
|
assert EXISTING_OWNER not in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_org_update(clirunner, validate_cliresult, isolated_pio_core):
|
def test_org_update(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
@ -411,8 +373,8 @@ def test_org_update(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
cmd_org,
|
cmd_org,
|
||||||
[
|
[
|
||||||
"update",
|
"update",
|
||||||
orgname,
|
ORG_NAME,
|
||||||
"--new-orgname",
|
"--orgname",
|
||||||
new_orgname,
|
new_orgname,
|
||||||
"--displayname",
|
"--displayname",
|
||||||
new_display_name,
|
new_display_name,
|
||||||
@ -427,9 +389,13 @@ def test_org_update(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
{
|
{
|
||||||
"orgname": new_orgname,
|
"orgname": new_orgname,
|
||||||
"displayname": new_display_name,
|
"displayname": new_display_name,
|
||||||
"email": email,
|
"email": USER_EMAIL,
|
||||||
"owners": [
|
"owners": [
|
||||||
{"username": username, "firstname": firstname, "lastname": lastname}
|
{
|
||||||
|
"username": USER_NAME,
|
||||||
|
"firstname": USER_FIRST_NAME,
|
||||||
|
"lastname": USER_LAST_NAME,
|
||||||
|
}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -439,10 +405,10 @@ def test_org_update(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
[
|
[
|
||||||
"update",
|
"update",
|
||||||
new_orgname,
|
new_orgname,
|
||||||
"--new-orgname",
|
"--orgname",
|
||||||
orgname,
|
ORG_NAME,
|
||||||
"--displayname",
|
"--displayname",
|
||||||
display_name,
|
ORG_DISPLAY_NAME,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
@ -453,9 +419,9 @@ def test_team_create(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
cmd_team,
|
cmd_team,
|
||||||
[
|
[
|
||||||
"create",
|
"create",
|
||||||
"%s:%s" % (orgname, teamname),
|
"%s:%s" % (ORG_NAME, TEAM_NAME),
|
||||||
"--description",
|
"--description",
|
||||||
team_description,
|
TEAM_DESCRIPTION,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
@ -464,55 +430,55 @@ def test_team_create(clirunner, validate_cliresult, isolated_pio_core):
|
|||||||
def test_team_list(clirunner, validate_cliresult, isolated_pio_core):
|
def test_team_list(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
["list", "%s" % orgname, "--json-output"],
|
["list", "%s" % ORG_NAME, "--json-output"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
for item in json_result:
|
for item in json_result:
|
||||||
del item["id"]
|
del item["id"]
|
||||||
assert json_result == [
|
assert json_result == [
|
||||||
{"name": teamname, "description": team_description, "members": []}
|
{"name": TEAM_NAME, "description": TEAM_DESCRIPTION, "members": []}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_team_add_member(clirunner, validate_cliresult, isolated_pio_core):
|
def _test_team_add_member(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
["add", "%s:%s" % (orgname, teamname), second_username],
|
["add", "%s:%s" % (ORG_NAME, TEAM_NAME), EXISTING_OWNER],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
["list", "%s" % orgname, "--json-output"],
|
["list", "%s" % ORG_NAME, "--json-output"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert second_username in result.output
|
assert EXISTING_OWNER in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_team_remove(clirunner, validate_cliresult, isolated_pio_core):
|
def _test_team_remove(clirunner, validate_cliresult, isolated_pio_core):
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
["remove", "%s:%s" % (orgname, teamname), second_username],
|
["remove", "%s:%s" % (ORG_NAME, TEAM_NAME), EXISTING_OWNER],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
["list", "%s" % orgname, "--json-output"],
|
["list", "%s" % ORG_NAME, "--json-output"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
assert second_username not in result.output
|
assert EXISTING_OWNER not in result.output
|
||||||
|
|
||||||
|
|
||||||
def test_team_update(clirunner, validate_cliresult, receive_email, isolated_pio_core):
|
def _test_team_update(clirunner, validate_cliresult, receive_email, isolated_pio_core):
|
||||||
new_teamname = "new-" + str(random.randint(0, 100000))
|
new_teamname = "new-" + str(random.randint(0, 100000))
|
||||||
newteam_description = "Updated Description"
|
newteam_description = "Updated Description"
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
[
|
[
|
||||||
"update",
|
"update",
|
||||||
"%s:%s" % (orgname, teamname),
|
"%s:%s" % (ORG_NAME, TEAM_NAME),
|
||||||
"--name",
|
"--name",
|
||||||
new_teamname,
|
new_teamname,
|
||||||
"--description",
|
"--description",
|
||||||
@ -523,7 +489,7 @@ def test_team_update(clirunner, validate_cliresult, receive_email, isolated_pio_
|
|||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_team,
|
cmd_team,
|
||||||
["list", "%s" % orgname, "--json-output"],
|
["list", "%s" % ORG_NAME, "--json-output"],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
json_result = json.loads(result.output.strip())
|
json_result = json.loads(result.output.strip())
|
||||||
@ -537,20 +503,22 @@ def test_team_update(clirunner, validate_cliresult, receive_email, isolated_pio_
|
|||||||
cmd_team,
|
cmd_team,
|
||||||
[
|
[
|
||||||
"update",
|
"update",
|
||||||
"%s:%s" % (orgname, new_teamname),
|
"%s:%s" % (ORG_NAME, new_teamname),
|
||||||
"--name",
|
"--name",
|
||||||
teamname,
|
TEAM_NAME,
|
||||||
"--description",
|
"--description",
|
||||||
team_description,
|
TEAM_DESCRIPTION,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
|
|
||||||
def test_cleanup(clirunner, validate_cliresult, receive_email, isolated_pio_core):
|
def test_cleanup(clirunner, validate_cliresult, receive_email, isolated_pio_core):
|
||||||
result = clirunner.invoke(cmd_team, ["destroy", "%s:%s" % (orgname, teamname)], "y")
|
result = clirunner.invoke(
|
||||||
|
cmd_team, ["destroy", "%s:%s" % (ORG_NAME, TEAM_NAME)], "y"
|
||||||
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
result = clirunner.invoke(cmd_org, ["destroy", orgname], "y")
|
result = clirunner.invoke(cmd_org, ["destroy", ORG_NAME], "y")
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
result = clirunner.invoke(cmd_account, ["destroy"], "y")
|
result = clirunner.invoke(cmd_account, ["destroy"], "y")
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
@ -93,9 +93,9 @@ def without_internet(monkeypatch):
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def receive_email(): # pylint:disable=redefined-outer-name, too-many-locals
|
def receive_email(): # pylint:disable=redefined-outer-name, too-many-locals
|
||||||
def _receive_email(from_who):
|
def _receive_email(from_who):
|
||||||
test_email = os.environ.get("TEST_EMAIL_LOGIN")
|
test_email = os.environ["TEST_EMAIL_LOGIN"]
|
||||||
test_password = os.environ.get("TEST_EMAIL_PASSWORD")
|
test_password = os.environ["TEST_EMAIL_PASSWORD"]
|
||||||
imap_server = os.environ.get("TEST_EMAIL_IMAP_SERVER") or "imap.gmail.com"
|
imap_server = os.environ["TEST_EMAIL_IMAP_SERVER"]
|
||||||
|
|
||||||
def get_body(msg):
|
def get_body(msg):
|
||||||
if msg.is_multipart():
|
if msg.is_multipart():
|
||||||
|
Reference in New Issue
Block a user