* replace timestamp with randint in tests

* replace pop3 with imap
This commit is contained in:
ShahRustam
2020-06-10 11:07:19 +03:00
committed by GitHub
parent e6fbd6acf1
commit a182cca5e9
5 changed files with 30 additions and 29 deletions

View File

@ -30,7 +30,7 @@ jobs:
env:
TEST_EMAIL_LOGIN: ${{ secrets.TEST_EMAIL_LOGIN }}
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: |
tox -e testcore

View File

@ -14,7 +14,7 @@
import json
import os
import time
import random
import pytest
import requests
@ -32,7 +32,7 @@ from platformio.unpacker import FileUnpacker
def test_account(
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("@")
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
firstname = "Test"
@ -191,10 +191,10 @@ def test_account(
validate_cliresult(result)
# pio account update
firstname = "First " + str(int(time.time() * 1000))
lastname = "Last" + str(int(time.time() * 1000))
firstname = "First " + str(random.randint(0, 100000))
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])
result = clirunner.invoke(
cmd_account,

View File

@ -14,7 +14,7 @@
import json
import os
import time
import random
import pytest
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",
) # pylint:disable=too-many-arguments
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("@")
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
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],)
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"
second_username = "ivankravets"
try:
@ -114,7 +114,7 @@ def test_org(clirunner, validate_cliresult, receive_email, isolated_pio_home):
assert second_username not in result.output
# 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"
result = clirunner.invoke(

View File

@ -14,7 +14,7 @@
import json
import os
import time
import random
import pytest
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",
) # pylint:disable=too-many-arguments
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("@")
email = "%s+%s@%s" % (splited_email[0], username, splited_email[1])
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],)
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"
# pio org create
@ -81,7 +81,7 @@ def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
)
validate_cliresult(result)
teamname = "test-" + str(int(time.time() * 1000))
teamname = "test-" + str(random.randint(0, 100000))
team_description = "team for CI test"
second_username = "ivankravets"
try:
@ -128,7 +128,7 @@ def test_teams(clirunner, validate_cliresult, receive_email, isolated_pio_home):
assert second_username not in result.output
# pio team update
new_teamname = "new-" + str(int(time.time() * 1000))
new_teamname = "new-" + str(random.randint(0, 100000))
newteam_description = "Updated Description"
result = clirunner.invoke(
cmd_team,

View File

@ -13,8 +13,8 @@
# limitations under the License.
import email
import imaplib
import os
import poplib
import time
import pytest
@ -63,9 +63,7 @@ def receive_email(): # pylint:disable=redefined-outer-name, too-many-locals
def _receive_email(from_who):
test_email = os.environ.get("TEST_EMAIL_LOGIN")
test_password = os.environ.get("TEST_EMAIL_PASSWORD")
pop_server = os.environ.get("TEST_EMAIL_POP3_SERVER") or "pop.gmail.com"
if "gmail" in pop_server:
test_email = "recent:" + test_email
imap_server = os.environ.get("TEST_EMAIL_IMAP_SERVER") or "imap.gmail.com"
def get_body(msg):
if msg.is_multipart():
@ -76,23 +74,26 @@ def receive_email(): # pylint:disable=redefined-outer-name, too-many-locals
start_time = time.time()
while not result:
time.sleep(5)
server = poplib.POP3_SSL(pop_server)
server.user(test_email)
server.pass_(test_password)
_, mails, _ = server.list()
for index, _ in enumerate(mails):
_, lines, _ = server.retr(index + 1)
msg_content = b"\n".join(lines)
server = imaplib.IMAP4_SSL(imap_server)
server.login(test_email, test_password)
server.select("INBOX")
_, mails = server.search(None, "ALL")
for index in mails[0].split():
_, data = server.fetch(index, "(RFC822)")
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"):
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()
if time.time() - start_time > 120:
break
server.quit()
server.close()
server.logout()
return result
return _receive_email