refactoring (#13)
* general project refactoring * various small improvements * improve imap fixture with helper functions and typing * add wordpress send email setup * add wordpress receive email test * add various documentation Reviewed-on: local-it-infrastructure/e2e_tests#13 Co-authored-by: Daniel <d.brummerloh@gmail.com> Co-committed-by: Daniel <d.brummerloh@gmail.com>
This commit is contained in:
parent
41a042f07d
commit
d1ff1183a5
29 changed files with 323 additions and 175 deletions
19
prototyping/dependency_injection.py
Normal file
19
prototyping/dependency_injection.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import inspect
|
||||
|
||||
a = 2
|
||||
b = 3
|
||||
c = 4
|
||||
|
||||
|
||||
def func(a: int, c: int) -> int:
|
||||
return a + c
|
||||
|
||||
|
||||
arg_names = inspect.getfullargspec(func).args
|
||||
print(arg_names) # ['a', 'c']
|
||||
|
||||
arguments = {arg: globals()[arg] for arg in arg_names if arg in globals()}
|
||||
print(arguments) # {'a': 2, 'c': 4}
|
||||
|
||||
result = func(**arguments)
|
||||
print(result) # 6
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
# %%
|
||||
import email
|
||||
import json
|
||||
import os
|
||||
from email.header import decode_header
|
||||
from imaplib import IMAP4, IMAP4_SSL
|
||||
from pathlib import Path
|
||||
|
||||
# -------------------------------- credentials ------------------------------- #
|
||||
|
||||
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"]
|
||||
|
||||
|
||||
# ----------------------------------- imap ----------------------------------- #
|
||||
|
||||
|
||||
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
|
||||
status, email_ids = imap_server.search(None, "ALL")
|
||||
email_ids = email_ids[0].split()
|
||||
|
||||
# Fetch email details using the retrieved IDs
|
||||
for email_id in email_ids:
|
||||
result, data = imap_server.fetch(email_id, "(RFC822)")
|
||||
raw_email = data[0][1] # Raw content of the email
|
||||
email_message = email.message_from_bytes(raw_email)
|
||||
|
||||
# Extract the subject
|
||||
subject_encoded = email_message.get("Subject")
|
||||
decoded_subject = decode_header(subject_encoded)[0][0]
|
||||
|
||||
if isinstance(decoded_subject, bytes):
|
||||
decoded_subject = decoded_subject.decode()
|
||||
|
||||
# Print or use the subject as needed
|
||||
print("Subject:", decoded_subject)
|
||||
80
prototyping/structure.md
Normal file
80
prototyping/structure.md
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
|
||||
|
||||
Abratest has 3 required inputs, but most importantly the test configuration is done through the .env files given with the --env_paths argument. So let's say we want to run abratest with these 3 .env files:
|
||||
|
||||
- config1.env [of TYPE authentik]
|
||||
|
||||
- config2.env [of TYPE wordpress]
|
||||
|
||||
- config3.env [of TYPE wordpress]
|
||||
|
||||
Now we run
|
||||
|
||||
```bash
|
||||
abratest --env_paths path/config1.env;path/config2.env;path/config3.env [...other args]
|
||||
```
|
||||
|
||||
|
||||
```
|
||||
abratest -> create Coordinator() instance
|
||||
└── Coordinator() -> create Runner() subclass instances
|
||||
├── RunnerAuthentik() [based on config1.env, loaded
|
||||
│ │ from abra/recipes/authentik]
|
||||
│ │ # RunnerAuthentik with 3 test files:
|
||||
│ ├── RUN pytest path/setup_authentik.py
|
||||
│ ├── RUN pytest path/test_authentik_1.py
|
||||
│ └── RUN pytest path/test_authentik_2.py
|
||||
├── RunnerWordpress() [based on config2.env, loaded
|
||||
│ │ from abra/recipes/wordpress]
|
||||
│ │ # RunnerWordpress with 1 test file
|
||||
│ ├── RUN pytest path/setup_authentik.py
|
||||
│ ├── RUN pytest path/test_authentik_1.py
|
||||
│ └── RUN pytest path/test_authentik_2.py
|
||||
└── RunnerWordpress() [based on config3.env, loaded
|
||||
│ from abra/recipes/wordpress]
|
||||
│ # RunnerWordpress with 1 test file
|
||||
├── RUN pytest path/setup_authentik.py
|
||||
├── RUN pytest path/test_authentik_1.py
|
||||
└── RUN pytest path/test_authentik_2.py
|
||||
|
||||
|
||||
```
|
||||
|
||||
Coordinator will take care of the correct order of the tests. In general, tests are placed in one of 3 categories: `setups`, `tests` and `cleanups`. To associate a test with one of these categories, place the Test in the corresponding list of the Runner class, i.e. Runner.setups = [test] or Runner.tests = [test]. The execution order will be.
|
||||
|
||||
> [setups] ➔ [tests] ➔ [cleanups]
|
||||
|
||||
|
||||
Furthermore, some `Runner` classes can depend on others. For example, `RunnerWordpress` depends on `RunnerAuthentik`. Therefore, `Coordinator` will make sure that `RunnerAuthentik` runs before `RunnerWordpress`. We will end up with with this order:
|
||||
|
||||
| # | Runner | Type |
|
||||
| --- | -------------- | -------- |
|
||||
| 1. | Authentik | setups |
|
||||
| 2. | Wordpress-1 | setups |
|
||||
| 3. | Wordpress-2 | setups |
|
||||
| 4. | Authentik | tests |
|
||||
| 5. | Wordpress-1 | tests |
|
||||
| 6. | Wordpress-2 | tests |
|
||||
| 7. | Authentik | cleanups |
|
||||
| 8. | Wordpress-1 | cleanups |
|
||||
| 9. | Wordpress-2 | cleanups |
|
||||
|
||||
|
||||
|
||||
To comprehend this process, let's examine a simplified rendition of the `RunnerWordpress` class. Within it, there exist two setup scripts and two test scripts, one of which operates conditionally.
|
||||
|
||||
|
||||
```python
|
||||
class RunnerWordpress(Runner):
|
||||
env_type = "wordpress"
|
||||
dependencies = ["authentik"]
|
||||
setups = [
|
||||
Test(test_file="setup_wordpress_1.py"),
|
||||
Test(test_file="setup_wordpress_2.py"),
|
||||
]
|
||||
tests = [
|
||||
Test(test_file="test_wordpress.py"),
|
||||
Test(condition=condition_function, test_file="test_wordpress_conditional.py"),
|
||||
]
|
||||
cleanups = []
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue