mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Feature/update account tests (#3556)
* update account tests * change second user * refactoring * clean * fix tests email receiving * fix
This commit is contained in:
@ -26,16 +26,29 @@ from platformio.commands.team import cli as cmd_team
|
||||
from platformio.downloader import FileDownloader
|
||||
from platformio.unpacker import FileUnpacker
|
||||
|
||||
pytestmark = pytest.mark.skip()
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not os.environ.get("TEST_EMAIL_LOGIN"),
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not (os.environ.get("TEST_EMAIL_LOGIN") and os.environ.get("TEST_EMAIL_PASSWORD")),
|
||||
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
||||
) # pylint:disable=too-many-arguments
|
||||
def test_account(
|
||||
clirunner, validate_cliresult, receive_email, isolated_pio_home, tmpdir_factory
|
||||
):
|
||||
)
|
||||
|
||||
username = None
|
||||
email = None
|
||||
firstname = None
|
||||
lastname = None
|
||||
password = None
|
||||
|
||||
orgname = None
|
||||
display_name = None
|
||||
second_username = None
|
||||
|
||||
teamname = None
|
||||
team_description = None
|
||||
|
||||
|
||||
def test_prepare():
|
||||
global username, splited_email, email, firstname, lastname
|
||||
global password, orgname, display_name, second_username, teamname, team_description
|
||||
|
||||
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
||||
@ -43,7 +56,17 @@ def test_account(
|
||||
lastname = "User"
|
||||
password = "Qwerty123!"
|
||||
|
||||
# pio account register
|
||||
orgname = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
||||
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(
|
||||
clirunner, validate_cliresult, receive_email, isolated_pio_home
|
||||
):
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
[
|
||||
@ -75,11 +98,17 @@ def test_account(
|
||||
link = link.replace("&", "&")
|
||||
session.get(link)
|
||||
|
||||
# pio account login
|
||||
|
||||
def test_account_login(
|
||||
clirunner, validate_cliresult, isolated_pio_home,
|
||||
):
|
||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||
validate_cliresult(result)
|
||||
try:
|
||||
# pio account summary
|
||||
|
||||
|
||||
def test_account_summary(
|
||||
clirunner, validate_cliresult, isolated_pio_home,
|
||||
):
|
||||
result = clirunner.invoke(cmd_account, ["show", "--json-output", "--offline"])
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
@ -129,7 +158,8 @@ def test_account(
|
||||
assert json_result.get("packages")[0].get("path")
|
||||
assert json_result.get("subscriptions") is not None
|
||||
|
||||
# pio account token
|
||||
|
||||
def test_account_token(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_account, ["token", "--password", password,],)
|
||||
validate_cliresult(result)
|
||||
assert "Personal Authentication Token:" in result.output
|
||||
@ -167,12 +197,11 @@ def test_account(
|
||||
|
||||
os.environ.pop("PLATFORMIO_AUTH_TOKEN")
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_account, ["login", "-u", username, "-p", password],
|
||||
)
|
||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||
validate_cliresult(result)
|
||||
|
||||
# pio account password
|
||||
|
||||
def test_account_change_password(clirunner, validate_cliresult, isolated_pio_home):
|
||||
new_password = "Testpassword123"
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
@ -194,12 +223,20 @@ def test_account(
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
# pio account update
|
||||
|
||||
def test_account_update(
|
||||
clirunner, validate_cliresult, receive_email, isolated_pio_home
|
||||
):
|
||||
global username
|
||||
global email
|
||||
global firstname
|
||||
global lastname
|
||||
|
||||
firstname = "First " + str(random.randint(0, 100000))
|
||||
lastname = "Last" + str(random.randint(0, 100000))
|
||||
|
||||
new_username = "username" + str(random.randint(0, 100000))
|
||||
new_email = "%s+new-%s@%s" % (splited_email[0], username, splited_email[1])
|
||||
username = "username" + str(random.randint(0, 100000))
|
||||
email = "%s+new-%s@%s" % (splited_email[0], username, splited_email[1])
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
[
|
||||
@ -211,9 +248,9 @@ def test_account(
|
||||
"--lastname",
|
||||
lastname,
|
||||
"--username",
|
||||
new_username,
|
||||
username,
|
||||
"--email",
|
||||
new_email,
|
||||
email,
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
@ -223,7 +260,7 @@ def test_account(
|
||||
in result.output
|
||||
)
|
||||
|
||||
result = receive_email(new_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]
|
||||
@ -242,13 +279,13 @@ def test_account(
|
||||
result.exception
|
||||
)
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_account, ["login", "-u", new_username, "-p", password],
|
||||
)
|
||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||
validate_cliresult(result)
|
||||
|
||||
# pio account destroy with linked resource
|
||||
|
||||
def test_account_destroy_with_linked_resources(
|
||||
clirunner, validate_cliresult, receive_email, isolated_pio_home, tmpdir_factory
|
||||
):
|
||||
package_url = "https://github.com/bblanchon/ArduinoJson/archive/v6.11.0.tar.gz"
|
||||
|
||||
tmp_dir = tmpdir_factory.mktemp("package")
|
||||
@ -261,7 +298,7 @@ def test_account(
|
||||
result = clirunner.invoke(cmd_package, ["publish", str(pkg_dir)],)
|
||||
validate_cliresult(result)
|
||||
try:
|
||||
result = receive_email(new_email)
|
||||
result = receive_email(email)
|
||||
assert "Congrats" in result
|
||||
assert "was published" in result
|
||||
except: # pylint:disable=bare-except
|
||||
@ -276,69 +313,16 @@ def test_account(
|
||||
|
||||
result = clirunner.invoke(cmd_package, ["unpublish", "ArduinoJson"],)
|
||||
validate_cliresult(result)
|
||||
finally:
|
||||
clirunner.invoke(cmd_account, ["destroy"], "y")
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not os.environ.get("TEST_EMAIL_LOGIN"),
|
||||
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
||||
) # pylint:disable=too-many-arguments
|
||||
def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
||||
firstname = "Test"
|
||||
lastname = "User"
|
||||
password = "Qwerty123!"
|
||||
|
||||
# pio account register
|
||||
def test_org_create(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
[
|
||||
"register",
|
||||
"-u",
|
||||
username,
|
||||
"-e",
|
||||
email,
|
||||
"-p",
|
||||
password,
|
||||
"--firstname",
|
||||
firstname,
|
||||
"--lastname",
|
||||
lastname,
|
||||
],
|
||||
cmd_org, ["create", "--email", email, "--displayname", display_name, orgname],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
# 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)
|
||||
|
||||
# pio account login
|
||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||
validate_cliresult(result)
|
||||
|
||||
orgname = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
||||
display_name = "Test Org for PIO Core"
|
||||
second_username = "ivankravets"
|
||||
try:
|
||||
# pio org create
|
||||
result = clirunner.invoke(
|
||||
cmd_org,
|
||||
["create", "--email", email, "--displayname", display_name, orgname],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
def test_org_list(clirunner, validate_cliresult, isolated_pio_home):
|
||||
# pio org list
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"])
|
||||
validate_cliresult(result)
|
||||
@ -354,7 +338,8 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
}
|
||||
]
|
||||
|
||||
# pio org add (owner)
|
||||
|
||||
def test_org_add_owner(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_org, ["add", orgname, second_username])
|
||||
validate_cliresult(result)
|
||||
|
||||
@ -362,7 +347,8 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
validate_cliresult(result)
|
||||
assert second_username in result.output
|
||||
|
||||
# pio org remove (owner)
|
||||
|
||||
def test_org_remove_owner(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_org, ["remove", orgname, second_username])
|
||||
validate_cliresult(result)
|
||||
|
||||
@ -370,7 +356,8 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
validate_cliresult(result)
|
||||
assert second_username not in result.output
|
||||
|
||||
# pio org update
|
||||
|
||||
def test_org_update(clirunner, validate_cliresult, isolated_pio_home):
|
||||
new_orgname = "neworg-piocore-%s" % str(random.randint(0, 100000))
|
||||
new_display_name = "Test Org for PIO Core"
|
||||
|
||||
@ -413,85 +400,17 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
finally:
|
||||
clirunner.invoke(cmd_org, ["destroy", orgname], "y")
|
||||
clirunner.invoke(cmd_account, ["destroy"], "y")
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not os.environ.get("TEST_EMAIL_LOGIN"),
|
||||
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
||||
) # pylint:disable=too-many-arguments
|
||||
def test_team(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
||||
firstname = "Test"
|
||||
lastname = "User"
|
||||
password = "Qwerty123!"
|
||||
|
||||
# pio account register
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
[
|
||||
"register",
|
||||
"-u",
|
||||
username,
|
||||
"-e",
|
||||
email,
|
||||
"-p",
|
||||
password,
|
||||
"--firstname",
|
||||
firstname,
|
||||
"--lastname",
|
||||
lastname,
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
# 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)
|
||||
|
||||
# pio account login
|
||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||
validate_cliresult(result)
|
||||
|
||||
orgname = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
||||
display_name = "Test Org for PIO Core"
|
||||
|
||||
# pio org create
|
||||
result = clirunner.invoke(
|
||||
cmd_org, ["create", "--email", email, "--displayname", display_name, orgname]
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
teamname = "test-" + str(random.randint(0, 100000))
|
||||
team_description = "team for CI test"
|
||||
second_username = "ivankravets"
|
||||
try:
|
||||
# pio team create
|
||||
def test_team_create(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(
|
||||
cmd_team,
|
||||
[
|
||||
"create",
|
||||
"%s:%s" % (orgname, teamname),
|
||||
"--description",
|
||||
team_description,
|
||||
],
|
||||
["create", "%s:%s" % (orgname, teamname), "--description", team_description,],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
# pio team list
|
||||
|
||||
def test_team_list(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
@ -501,7 +420,8 @@ def test_team(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
{"name": teamname, "description": team_description, "members": []}
|
||||
]
|
||||
|
||||
# pio team add (member)
|
||||
|
||||
def test_team_add_member(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(
|
||||
cmd_team, ["add", "%s:%s" % (orgname, teamname), second_username],
|
||||
)
|
||||
@ -511,7 +431,8 @@ def test_team(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
validate_cliresult(result)
|
||||
assert second_username in result.output
|
||||
|
||||
# pio team remove (member)
|
||||
|
||||
def test_team_remove(clirunner, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(
|
||||
cmd_team, ["remove", "%s:%s" % (orgname, teamname), second_username],
|
||||
)
|
||||
@ -521,7 +442,8 @@ def test_team(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
validate_cliresult(result)
|
||||
assert second_username not in result.output
|
||||
|
||||
# pio team update
|
||||
|
||||
def test_team_update(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
new_teamname = "new-" + str(random.randint(0, 100000))
|
||||
newteam_description = "Updated Description"
|
||||
result = clirunner.invoke(
|
||||
@ -558,7 +480,12 @@ def test_team(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
finally:
|
||||
clirunner.invoke(cmd_team, ["destroy", "%s:%s" % (orgname, teamname)], "y")
|
||||
clirunner.invoke(cmd_org, ["destroy", orgname], "y")
|
||||
clirunner.invoke(cmd_account, ["destroy"], "y")
|
||||
|
||||
|
||||
def test_cleanup(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_team, ["destroy", "%s:%s" % (orgname, teamname)], "y")
|
||||
validate_cliresult(result)
|
||||
result = clirunner.invoke(cmd_org, ["destroy", orgname], "y")
|
||||
validate_cliresult(result)
|
||||
result = clirunner.invoke(cmd_account, ["destroy"], "y")
|
||||
validate_cliresult(result)
|
||||
|
@ -79,7 +79,9 @@ def receive_email(): # pylint:disable=redefined-outer-name, too-many-locals
|
||||
server.select("INBOX")
|
||||
_, mails = server.search(None, "ALL")
|
||||
for index in mails[0].split():
|
||||
_, data = server.fetch(index, "(RFC822)")
|
||||
status, data = server.fetch(index, "(RFC822)")
|
||||
if status != "OK" or not data or not isinstance(data[0], tuple):
|
||||
continue
|
||||
msg = email.message_from_string(
|
||||
data[0][1].decode("ASCII", errors="surrogateescape")
|
||||
)
|
||||
|
Reference in New Issue
Block a user