forked from platformio/platformio-core
tests fix (#3555)
* replace timestamp with randint in tests * replace pop3 with imap
This commit is contained in:
2
.github/workflows/core.yml
vendored
2
.github/workflows/core.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
TEST_EMAIL_LOGIN: ${{ secrets.TEST_EMAIL_LOGIN }}
|
TEST_EMAIL_LOGIN: ${{ secrets.TEST_EMAIL_LOGIN }}
|
||||||
TEST_EMAIL_PASSWORD: ${{ secrets.TEST_EMAIL_PASSWORD }}
|
TEST_EMAIL_PASSWORD: ${{ secrets.TEST_EMAIL_PASSWORD }}
|
||||||
TEST_EMAIL_POP3_SERVER: ${{ secrets.TEST_EMAIL_POP3_SERVER }}
|
TEST_EMAIL_IMAP_SERVER: ${{ secrets.TEST_EMAIL_IMAP_SERVER }}
|
||||||
run: |
|
run: |
|
||||||
tox -e testcore
|
tox -e testcore
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import random
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
@ -32,7 +32,7 @@ from platformio.unpacker import FileUnpacker
|
|||||||
def test_account(
|
def test_account(
|
||||||
clirunner, validate_cliresult, receive_email, isolated_pio_home, tmpdir_factory
|
clirunner, validate_cliresult, receive_email, isolated_pio_home, tmpdir_factory
|
||||||
):
|
):
|
||||||
username = "test-piocore-%s" % str(int(time.time() * 1000))
|
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
||||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
||||||
firstname = "Test"
|
firstname = "Test"
|
||||||
@ -191,10 +191,10 @@ def test_account(
|
|||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
# pio account update
|
# pio account update
|
||||||
firstname = "First " + str(int(time.time() * 1000))
|
firstname = "First " + str(random.randint(0, 100000))
|
||||||
lastname = "Last" + str(int(time.time() * 1000))
|
lastname = "Last" + str(random.randint(0, 100000))
|
||||||
|
|
||||||
new_username = "username" + str(int(time.time() * 1000))[-5:]
|
new_username = "username" + str(random.randint(0, 100000))
|
||||||
new_email = "%s+new-%s@%s" % (splited_email[0], username, splited_email[1])
|
new_email = "%s+new-%s@%s" % (splited_email[0], username, splited_email[1])
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
cmd_account,
|
cmd_account,
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import random
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
@ -28,7 +28,7 @@ from platformio.commands.org import cli as cmd_org
|
|||||||
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
||||||
) # pylint:disable=too-many-arguments
|
) # pylint:disable=too-many-arguments
|
||||||
def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||||
username = "test-piocore-%s" % str(int(time.time() * 1000))
|
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
||||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
||||||
firstname = "Test"
|
firstname = "Test"
|
||||||
@ -71,7 +71,7 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
|||||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
orgname = "testorg-piocore-%s" % str(int(time.time() * 1000))
|
orgname = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
||||||
display_name = "Test Org for PIO Core"
|
display_name = "Test Org for PIO Core"
|
||||||
second_username = "ivankravets"
|
second_username = "ivankravets"
|
||||||
try:
|
try:
|
||||||
@ -114,7 +114,7 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
|||||||
assert second_username not in result.output
|
assert second_username not in result.output
|
||||||
|
|
||||||
# pio org update
|
# pio org update
|
||||||
new_orgname = "neworg-piocore-%s" % str(int(time.time() * 1000))
|
new_orgname = "neworg-piocore-%s" % str(random.randint(0, 100000))
|
||||||
new_display_name = "Test Org for PIO Core"
|
new_display_name = "Test Org for PIO Core"
|
||||||
|
|
||||||
result = clirunner.invoke(
|
result = clirunner.invoke(
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import random
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
@ -29,7 +29,7 @@ from platformio.commands.team import cli as cmd_team
|
|||||||
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
reason="requires TEST_EMAIL_LOGIN, TEST_EMAIL_PASSWORD environ variables",
|
||||||
) # pylint:disable=too-many-arguments
|
) # pylint:disable=too-many-arguments
|
||||||
def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
||||||
username = "test-piocore-%s" % str(int(time.time() * 1000))
|
username = "test-piocore-%s" % str(random.randint(0, 100000))
|
||||||
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
splited_email = os.environ.get("TEST_EMAIL_LOGIN").split("@")
|
||||||
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
|
||||||
firstname = "Test"
|
firstname = "Test"
|
||||||
@ -72,7 +72,7 @@ def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
|||||||
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
result = clirunner.invoke(cmd_account, ["login", "-u", username, "-p", password],)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
orgname = "testorg-piocore-%s" % str(int(time.time() * 1000))
|
orgname = "testorg-piocore-%s" % str(random.randint(0, 100000))
|
||||||
display_name = "Test Org for PIO Core"
|
display_name = "Test Org for PIO Core"
|
||||||
|
|
||||||
# pio org create
|
# pio org create
|
||||||
@ -81,7 +81,7 @@ def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
|||||||
)
|
)
|
||||||
validate_cliresult(result)
|
validate_cliresult(result)
|
||||||
|
|
||||||
teamname = "test-" + str(int(time.time() * 1000))
|
teamname = "test-" + str(random.randint(0, 100000))
|
||||||
team_description = "team for CI test"
|
team_description = "team for CI test"
|
||||||
second_username = "ivankravets"
|
second_username = "ivankravets"
|
||||||
try:
|
try:
|
||||||
@ -128,7 +128,7 @@ def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
|
|||||||
assert second_username not in result.output
|
assert second_username not in result.output
|
||||||
|
|
||||||
# pio team update
|
# pio team update
|
||||||
new_teamname = "new-" + str(int(time.time() * 1000))
|
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,
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import email
|
import email
|
||||||
|
import imaplib
|
||||||
import os
|
import os
|
||||||
import poplib
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -63,9 +63,7 @@ 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.get("TEST_EMAIL_LOGIN")
|
||||||
test_password = os.environ.get("TEST_EMAIL_PASSWORD")
|
test_password = os.environ.get("TEST_EMAIL_PASSWORD")
|
||||||
pop_server = os.environ.get("TEST_EMAIL_POP3_SERVER") or "pop.gmail.com"
|
imap_server = os.environ.get("TEST_EMAIL_IMAP_SERVER") or "imap.gmail.com"
|
||||||
if "gmail" in pop_server:
|
|
||||||
test_email = "recent:" + test_email
|
|
||||||
|
|
||||||
def get_body(msg):
|
def get_body(msg):
|
||||||
if msg.is_multipart():
|
if msg.is_multipart():
|
||||||
@ -76,23 +74,26 @@ def receive_email(): # pylint:disable=redefined-outer-name, too-many-locals
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
while not result:
|
while not result:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
server = poplib.POP3_SSL(pop_server)
|
server = imaplib.IMAP4_SSL(imap_server)
|
||||||
server.user(test_email)
|
server.login(test_email, test_password)
|
||||||
server.pass_(test_password)
|
server.select("INBOX")
|
||||||
_, mails, _ = server.list()
|
_, mails = server.search(None, "ALL")
|
||||||
for index, _ in enumerate(mails):
|
for index in mails[0].split():
|
||||||
_, lines, _ = server.retr(index + 1)
|
_, data = server.fetch(index, "(RFC822)")
|
||||||
msg_content = b"\n".join(lines)
|
|
||||||
msg = email.message_from_string(
|
msg = email.message_from_string(
|
||||||
msg_content.decode("ASCII", errors="surrogateescape")
|
data[0][1].decode("ASCII", errors="surrogateescape")
|
||||||
)
|
)
|
||||||
if from_who not in msg.get("To"):
|
if from_who not in msg.get("To"):
|
||||||
continue
|
continue
|
||||||
server.dele(index + 1)
|
if "gmail" in imap_server:
|
||||||
|
server.store(index, "+X-GM-LABELS", "\\Trash")
|
||||||
|
server.store(index, "+FLAGS", "\\Deleted")
|
||||||
|
server.expunge()
|
||||||
result = get_body(msg).decode()
|
result = get_body(msg).decode()
|
||||||
if time.time() - start_time > 120:
|
if time.time() - start_time > 120:
|
||||||
break
|
break
|
||||||
server.quit()
|
server.close()
|
||||||
|
server.logout()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return _receive_email
|
return _receive_email
|
||||||
|
Reference in New Issue
Block a user