forked from platformio/platformio-core
* CLI to manage teams.Minor fixes. Resolve #3533 * fix teams tests * disable org and team tests * minor fixes. fix error texts * fix split compatibility
This commit is contained in:
1 parent
42df3c9c3f
commit
94cb808285
5 files changed
+453
-94
No files matched your search
+35
-71
@@ -37,7 +37,7 @@ def credentials():
|
||||
}
|
||||
|
||||
|
||||
def test_org_add(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
def test_orgs(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
try:
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
@@ -66,26 +66,11 @@ def test_org_add(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) == 3
|
||||
finally:
|
||||
clirunner.invoke(cmd_account, ["logout"])
|
||||
|
||||
|
||||
def test_org_list(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
try:
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
["login", "-u", credentials["login"], "-p", credentials["password"]],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert "Successfully logged in!" in result.output
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) == 3
|
||||
assert len(json_result) >= 3
|
||||
check = False
|
||||
for org in json_result:
|
||||
assert "orgname" in org
|
||||
orgname = org["orgname"]
|
||||
assert "displayname" in org
|
||||
assert "email" in org
|
||||
assert "owners" in org
|
||||
@@ -95,10 +80,41 @@ def test_org_list(clirunner, credentials, validate_cliresult, isolated_pio_home)
|
||||
assert "firstname" in owner
|
||||
assert "lastname" in owner
|
||||
assert check
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["add", orgname, "ivankravets"],)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) >= 3
|
||||
check = False
|
||||
for item in json_result:
|
||||
if item["orgname"] != orgname:
|
||||
continue
|
||||
for owner in item.get("owners"):
|
||||
check = owner["username"] == "ivankravets" if not check else True
|
||||
assert check
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["remove", orgname, "ivankravets"],)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) >= 3
|
||||
check = False
|
||||
for item in json_result:
|
||||
if item["orgname"] != orgname:
|
||||
continue
|
||||
for owner in item.get("owners"):
|
||||
check = owner["username"] == "ivankravets" if not check else True
|
||||
assert not check
|
||||
finally:
|
||||
clirunner.invoke(cmd_account, ["logout"])
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_org_update(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
try:
|
||||
result = clirunner.invoke(
|
||||
@@ -111,7 +127,7 @@ def test_org_update(clirunner, credentials, validate_cliresult, isolated_pio_hom
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) == 3
|
||||
assert len(json_result) >= 3
|
||||
org = json_result[0]
|
||||
assert "orgname" in org
|
||||
assert "displayname" in org
|
||||
@@ -137,55 +153,3 @@ def test_org_update(clirunner, credentials, validate_cliresult, isolated_pio_hom
|
||||
assert json.loads(result.output.strip()) == json_result
|
||||
finally:
|
||||
clirunner.invoke(cmd_account, ["logout"])
|
||||
|
||||
|
||||
def test_org_owner(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
try:
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
["login", "-u", credentials["login"], "-p", credentials["password"]],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert "Successfully logged in!" in result.output
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) == 3
|
||||
org = json_result[0]
|
||||
assert "orgname" in org
|
||||
assert "displayname" in org
|
||||
assert "email" in org
|
||||
assert "owners" in org
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["add", org["orgname"], "ivankravets"],)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) == 3
|
||||
check = False
|
||||
for item in json_result:
|
||||
if item["orgname"] != org["orgname"]:
|
||||
continue
|
||||
for owner in item.get("owners"):
|
||||
check = owner["username"] == "ivankravets" if not check else True
|
||||
assert check
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["remove", org["orgname"], "ivankravets"],)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) == 3
|
||||
check = False
|
||||
for item in json_result:
|
||||
if item["orgname"] != org["orgname"]:
|
||||
continue
|
||||
for owner in item.get("owners"):
|
||||
check = owner["username"] == "ivankravets" if not check else True
|
||||
assert not check
|
||||
|
||||
finally:
|
||||
clirunner.invoke(cmd_account, ["logout"])
|
||||
@@ -0,0 +1,158 @@
|
||||
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from platformio.commands.account import cli as cmd_account
|
||||
from platformio.commands.org import cli as cmd_org
|
||||
from platformio.commands.team import cli as cmd_team
|
||||
|
||||
pytestmark = pytest.mark.skipif(
|
||||
not (
|
||||
os.environ.get("PLATFORMIO_TEST_ACCOUNT_LOGIN")
|
||||
and os.environ.get("PLATFORMIO_TEST_ACCOUNT_PASSWORD")
|
||||
),
|
||||
reason="requires PLATFORMIO_TEST_ACCOUNT_LOGIN, PLATFORMIO_TEST_ACCOUNT_PASSWORD environ variables",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def credentials():
|
||||
return {
|
||||
"login": os.environ["PLATFORMIO_TEST_ACCOUNT_LOGIN"],
|
||||
"password": os.environ["PLATFORMIO_TEST_ACCOUNT_PASSWORD"],
|
||||
}
|
||||
|
||||
|
||||
def test_teams(clirunner, credentials, validate_cliresult, isolated_pio_home):
|
||||
orgname = ""
|
||||
teamname = "test-" + str(int(time.time() * 1000))
|
||||
try:
|
||||
result = clirunner.invoke(
|
||||
cmd_account,
|
||||
["login", "-u", credentials["login"], "-p", credentials["password"]],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
assert "Successfully logged in!" in result.output
|
||||
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
if len(json_result) < 3:
|
||||
for i in range(3 - len(json_result)):
|
||||
result = clirunner.invoke(
|
||||
cmd_org,
|
||||
[
|
||||
"create",
|
||||
"%s-%s" % (i, credentials["login"]),
|
||||
"--email",
|
||||
"test@test.com",
|
||||
"--display-name",
|
||||
"TEST ORG %s" % i,
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
result = clirunner.invoke(cmd_org, ["list", "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) >= 3
|
||||
orgname = json_result[0].get("orgname")
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_team,
|
||||
[
|
||||
"create",
|
||||
"%s:%s" % (orgname, teamname),
|
||||
"--description",
|
||||
"team for CI test",
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) >= 1
|
||||
check = False
|
||||
for team in json_result:
|
||||
assert team["id"]
|
||||
assert team["name"]
|
||||
if team["name"] == teamname:
|
||||
check = True
|
||||
assert "description" in team
|
||||
assert "members" in team
|
||||
assert check
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_team, ["add", "%s:%s" % (orgname, teamname), credentials["login"]],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
check = False
|
||||
for team in json_result:
|
||||
assert team["id"]
|
||||
assert team["name"]
|
||||
assert "description" in team
|
||||
assert "members" in team
|
||||
if (
|
||||
len(team["members"]) > 0
|
||||
and team["members"][0]["username"] == credentials["login"]
|
||||
):
|
||||
check = True
|
||||
assert check
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_team, ["remove", "%s:%s" % (orgname, teamname), credentials["login"]],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(
|
||||
cmd_team,
|
||||
[
|
||||
"update",
|
||||
"%s:%s" % (orgname, teamname),
|
||||
"--description",
|
||||
"Updated Description",
|
||||
],
|
||||
)
|
||||
validate_cliresult(result)
|
||||
|
||||
result = clirunner.invoke(cmd_team, ["list", "%s" % orgname, "--json-output"],)
|
||||
validate_cliresult(result)
|
||||
json_result = json.loads(result.output.strip())
|
||||
assert len(json_result) >= 1
|
||||
check = False
|
||||
for team in json_result:
|
||||
assert team["id"]
|
||||
assert team["name"]
|
||||
assert "description" in team
|
||||
if team.get("description") == "Updated Description":
|
||||
check = True
|
||||
assert "members" in team
|
||||
assert check
|
||||
finally:
|
||||
clirunner.invoke(
|
||||
cmd_team, ["destroy", "%s:%s" % (orgname, teamname),],
|
||||
)
|
||||
clirunner.invoke(cmd_account, ["logout"])
|
||||
Reference in new issue
Block a user