refactor for independent test dirs (#7)

* make it so that the actual tests can be moved anywhere, for example in abra recipe repos
-> major refactoring with pytest test discovery magic

* create RUNNER_DICT dynamically with importlib
-> none of the tests are hardcoded, more tests can be added by placing a folder

* autoload fixtures with pytest plugins

* add URL fixture to navigate on web pages. Includes url parser based on python urllib to generate correct links

* fix nextcloud setups and tests

*  add email groundwork with imbox

Reviewed-on: local-it-infrastructure/e2e_tests#7
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
Daniel 2023-12-05 21:41:43 +01:00 committed by dan
parent 3fa10aaa69
commit f9c21c6e6b
45 changed files with 373 additions and 228 deletions

View file

@ -1,6 +1,7 @@
# %%
import email
import json
import os
from email.header import decode_header
from imaplib import IMAP4, IMAP4_SSL
from pathlib import Path
@ -11,19 +12,20 @@ cred_file = Path("../credentials.json")
with open(cred_file, "r") as f:
CREDENTIALS = json.load(f)
username = CREDENTIALS["imap_user"]
password = CREDENTIALS["imap_pass"]
for key, value in CREDENTIALS.items():
os.environ[key] = value
IMAP_HOST = os.environ["IMAP_HOST"]
IMAP_PORT = os.environ["IMAP_PORT"]
IMAP_USER = os.environ["IMAP_USER"]
IMAP_PASS = os.environ["IMAP_PASS"]
# ----------------------------------- imap ----------------------------------- #
host = "mail.local-it.org"
imap_port = 143
imap_ssl_port = 993
with IMAP4_SSL(host=host) as imap_server:
imap_server.login(username, password)
with IMAP4_SSL(host=IMAP_HOST) as imap_server:
imap_server.login(IMAP_USER, IMAP_PASS)
imap_server.select("INBOX")
# Search for all emails in the folder

View file

@ -0,0 +1,53 @@
# %%
import datetime
import json
import os
from pathlib import Path
from imbox import Imbox
cred_file = Path("../credentials.json")
with open(cred_file, "r") as f:
CREDENTIALS = json.load(f)
for key, value in CREDENTIALS.items():
os.environ[key] = value
IMAP_HOST = os.environ["IMAP_HOST"]
IMAP_PORT = os.environ["IMAP_PORT"]
IMAP_USER = os.environ["IMAP_USER"]
IMAP_PASS = os.environ["IMAP_PASS"]
with Imbox(
hostname=os.environ["IMAP_HOST"],
port=os.environ["IMAP_PORT"],
username=os.environ["IMAP_USER"],
password=os.environ["IMAP_PASS"],
ssl=True,
ssl_context=None,
starttls=False,
) as imbox:
# Get all folders
status, folders_with_additional_info = imbox.folders()
# Gets all messages from the inbox
all_inbox_messages = imbox.messages()
# Messages received after specific date
inbox_messages_received_after = imbox.messages(date__gt=datetime.date(2018, 7, 30))
# Messages whose subjects contain a string
inbox_messages_subject_christmas = imbox.messages(subject="Christmas")
for uid, message in all_inbox_messages:
print(uid, message.subject, message.date)
# # Every message is an object with the following keys
# message.sent_from
# message.sent_to
# message.subject
# message.headers
# message.message_id
# message.date
# message.body.plain

View file

@ -1,10 +0,0 @@
# %%
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse
string = "blog.dev.local-it.cloud"
parsed_url = urlparse(string, scheme="https")
print(parsed_url)
print(urlunparse(parsed_url))